3 ��Xs � @ s� d Z ddlZddlmZmZmZmZmZ ddlm Z m Z mZmZm Z mZmZmZmZmZmZ ddlmZmZ ddlmZ ddlmZmZmZmZ ddlmZ d d ddd dddgZej d�Z!ej dej"�Z#ej dej"�Z$dd� Z%G dd� de&�Z'G dd � d e'e�Z(G dd � d e'e�Z)G dd� de'e�Z*ej d�Z+ej d�Z,ej d�Z-ej d�Z,ej d �Z.ej d!�Z/G d"d#� d#e&�Z0G d$d� de�Z1G d%d� de�Z2G d&d � d e�Z3G d'd� de�Z4G d(d� de�Z5G d)d� de�Z6dS )*a� pygments.lexers.sql ~~~~~~~~~~~~~~~~~~~ Lexers for various SQL dialects and related interactive sessions. Postgres specific lexers: `PostgresLexer` A SQL lexer for the PostgreSQL dialect. Differences w.r.t. the SQL lexer are: - keywords and data types list parsed from the PG docs (run the `_postgres_builtins` module to update them); - Content of $-strings parsed using a specific lexer, e.g. the content of a PL/Python function is parsed using the Python lexer; - parse PG specific constructs: E-strings, $-strings, U&-strings, different operators and punctuation. `PlPgsqlLexer` A lexer for the PL/pgSQL language. Adds a few specific construct on top of the PG SQL lexer (such as <<label>>). `PostgresConsoleLexer` A lexer to highlight an interactive psql session: - identifies the prompt and does its best to detect the end of command in multiline statement where not all the lines are prefixed by a prompt, telling them apart from the output; - highlights errors in the output and notification levels; - handles psql backslash commands. The ``tests/examplefiles`` contains a few test files with data to be parsed by these lexers. :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. � N)�Lexer� RegexLexer� do_insertions�bygroups�words)�Punctuation� Whitespace�Error�Text�Comment�Operator�Keyword�Name�String�Number�Generic)�get_lexer_by_name� ClassNotFound)� iteritems)�KEYWORDS� DATATYPES�PSEUDO_TYPES�PLPGSQL_KEYWORDS)�_tsql_builtins� PostgresLexer�PlPgsqlLexer�PostgresConsoleLexer�SqlLexer�TransactSqlLexer� MySqlLexer�SqliteConsoleLexer�RqlLexerz.*? z\s+LANGUAGE\s+'?(\w+)'?z\bDO\bc c s� d}t j| j|j� |j� d � �}|dk r>| j|jd��}n|tt j| jtd|j � d �|j � � ��}|r�| j|d jd��}n8tt j| jtd|j � d �|j � � ��}|r�| jd�}|j d�t|jd�fV |j d�tj|jd�fV |j d�t|jd�fV |�r.x:|j |jd ��D ]}|V �qW n|j d �t|jd �fV |j d �t|jd �fV |j d�tj|jd�fV |j d�t|jd�fV dS )z�Parse the content of a $-string using a lexer The lexer is chosen looking for a nearby LANGUAGE or assumed as plpgsql if inside a DO statement and no LANGUAGE has been found. N�d � r � �plpgsql� � � � � � ���)�language_re�match�text�end� _get_lexer�group�list�finditer�max�start�do_rer Z Delimiter�get_tokens_unprocessed)�lexerr. �l�m�x� r= �/usr/lib/python3.6/sql.py�language_callbackA s, $$ r? c s( e Zd ZdZ� fdd�Zdd� Z� ZS )�PostgresBasea� Base class for Postgres-related lexers. This is implemented as a mixin to avoid the Lexer metaclass kicking in. this way the different lexer don't have a common Lexer ancestor. If they had, _tokens could be created on this ancestor and not updated for the other classes, resulting e.g. in PL/pgSQL parsed as SQL. This shortcoming seem to suggest that regexp lexers are not really subclassable. c '