�
|�e{� � �@ � d Z ddlZddlmZmZmZmZmZ ddlm Z m
Z
mZmZm
Z
mZmZmZmZmZmZ ddlmZmZ ddlmZmZmZmZmZ ddlmZmZm Z m!Z!m"Z" ddlm#Z# g d �Z$ ejJ d
� Z& ejJ d� Z' ejJ dejP � Z) ejJ d
ejP � Z* ejJ d� Z+ ejJ d� Z, ejJ dejP � Z- ejJ dejP � Z. ejJ d� Z/d� Z0 G d� d� Z1 G d� de1e� Z2 G d� de1e� Z3 G d� de1e� Z4 ejJ d� Z5 ejJ d� Z6 ejJ d� Z7 ejJ d� Z6 ejJ d � Z8 ejJ d!� Z9 G d"� d#� Z: G d$� d%e� Z; G d&� d'e� Z< G d(� d)e� Z= G d*� d+e� Z> G d,� d-e� Z? G d.� d/e� Z@ G d0� d1e� ZAy)2a�
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.
`PostgresExplainLexer`
A lexer to highlight Postgres execution plan.
The ``tests/examplefiles`` contains a few test files with data to be
parsed by these lexers.
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
� N)�Lexer�
RegexLexer�
do_insertions�bygroups�words)�Punctuation�
Whitespace�Text�Comment�Operator�Keyword�Name�String�Number�Generic�Literal)�get_lexer_by_name�
ClassNotFound)�KEYWORDS� DATATYPES�PSEUDO_TYPES�PLPGSQL_KEYWORDS�EXPLAIN_KEYWORDS)�MYSQL_CONSTANTS�MYSQL_DATATYPES�MYSQL_FUNCTIONS�MYSQL_KEYWORDS�MYSQL_OPTIMIZER_HINTS)�_tsql_builtins) �
PostgresLexer�PlPgsqlLexer�PostgresConsoleLexer�PostgresExplainLexer�SqlLexer�TransactSqlLexer�
MySqlLexer�SqliteConsoleLexer�RqlLexerz.*?
z^(?:sqlite| ...)>(?= )z\s+LANGUAGE\s+'?(\w+)'?z\bDO\bz\[[a-zA-Z_]\w*\]z`[a-zA-Z_]\w*`z\bgo\bz
\bdeclare\s+@z@[a-zA-Z_]\w*\bc
# �Z K � d}t j | j |j � |j � dz � }|�!| j |j d� � }n�t
t j | j t d|j � dz
� |j � � � }|r$| j |d j d� � }ngt
t j | j t d|j � dz
� |j � � � }|r| j d� }|j d� t |j d� f�� |j d� t j |j d� f�� |j d � t |j d � f�� |r)|j |j d
� � E d{ ��� n)|j d
� t |j d
� f�� |j d� t |j d� f�� |j d� t j |j d� f�� |j d
� t |j d
� f�� y7 ���w)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 � Delimiter�get_tokens_unprocessed)�lexerr6 �lx�ms �5/usr/lib/python3/dist-packages/pygments/lexers/sql.py�language_callbackrF Q s � �� �
�B����%�*�*�U�Y�Y�[�����S��A�B�A��}�
�
�
�a�g�g�a�j�
)����%�%��J�J�s�1�e�k�k�m�C�/�0�����?�A�
B����!�!�!�B�%�+�+�a�.�1�B��U�^�^��
�
�3�q�%�+�+�-��"2�3�E�K�K�M�B�D� E�A���%�%�i�0�� �;�;�q�>�6�5�;�;�q�>�
2�2��;�;�q�>�6�+�+�U�[�[��^�
<�<��;�;�q�>�6�5�;�;�q�>�
2�2� ��,�,�U�[�[��^�<�<�<��{�{�1�~�v�u�{�{�1�~�6�6��;�;�q�>�6�5�;�;�q�>�
2�2��;�;�q�>�6�+�+�U�[�[��^�
<�<��;�;�q�>�6�5�;�;�q�>�
2�2�
=�s �G2J+�4J)�5B5J+c �( � � e Zd ZdZ� fd�Zd� Z� xZS )�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 ' |