
    Dvgg                     h    d Z ddlZddlmZ ddlmZ ddlmZmZ ddl	m
Z
  G d d          Zd
d	ZdS )z	SQL Lexer    N)Lock)
TextIOBase)tokenskeywords)consumec                   f    e Zd ZdZdZ e            Zed             Zd Z	d Z
d Zd Zd Zd
d	ZdS )LexerzrThe Lexer supports configurable syntax.
    To add support for additional keywords, use the `add_keywords` method.Nc                     | j         5  | j        ( |             | _        | j                                         ddd           n# 1 swxY w Y   | j        S )zRReturns the lexer instance used internally
        by the sqlparse core functions.N)_lock_default_instancedefault_initialization)clss    K/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/sqlparse/lexer.pyget_default_instancezLexer.get_default_instance0   s     Y 	? 	?$,(+%%<<>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? $$s   0AAAc                    |                                   |                     t          j                   |                     t          j                   |                     t          j                   |                     t          j                   |                     t          j                   |                     t          j	                   |                     t          j
                   |                     t          j                   |                     t          j                   |                     t          j                   dS )zlInitialize the lexer with default dictionaries.
        Useful if you need to revert custom syntax settings.N)clearset_SQL_REGEXr   	SQL_REGEXadd_keywordsKEYWORDS_COMMONKEYWORDS_ORACLEKEYWORDS_MYSQLKEYWORDS_PLPGSQLKEYWORDS_HQLKEYWORDS_MSACCESSKEYWORDS_SNOWFLAKEKEYWORDS_BIGQUERYKEYWORDSselfs    r   r   zLexer.default_initialization:   s     	

8-...(2333(2333(1222(3444(/000(4555(5666(4555(+,,,,,    c                 "    g | _         g | _        dS )zClear all syntax configurations.
        Useful if you want to load a reduced set of syntax configurations.
        After this call, regexps and keyword dictionaries need to be loaded
        to make the lexer functional again.N)
_SQL_REGEX	_keywordsr   s    r   r   zLexer.clearI   s    
 r!   c                 `    t           j        t           j        z  fd|D             | _        dS )z.Set the list of regex that will parse the SQL.c                 N    g | ]!\  }}t          j        |          j        |f"S  )recompilematch).0rxttFLAGSs      r   
<listcomp>z'Lexer.set_SQL_REGEX.<locals>.<listcomp>T   sA     
 
 
B ZE""("-
 
 
r!   N)r(   
IGNORECASEUNICODEr#   )r    r   r.   s     @r   r   zLexer.set_SQL_REGEXQ   s?    
*
 
 
 
#
 
 
r!   c                 :    | j                             |           dS )zhAdd keyword dictionaries. Keywords are looked up in the same order
        that dictionaries were added.N)r$   append)r    r   s     r   r   zLexer.add_keywordsY   s      	h'''''r!   c                 z    |                                 }| j        D ]}||v r||         |fc S t          j        |fS )zChecks for a keyword.

        If the given value is in one of the KEYWORDS_* dictionary
        it's considered a keyword. Otherwise, tokens.Name is returned.
        )upperr$   r   Name)r    valuevalkwdicts       r   
is_keywordzLexer.is_keyword^   sT     kkmmn 	& 	&Ff}}c{E))))  ;%%r!   c              #   d  K   t          |t                    r|                                }t          |t                    rnt          |t                    rT|r|                    |          }nk	 |                    d          }nT# t          $ r |                    d          }Y n3w xY wt          d                    t          |                              t          |          }|D ]\  }}| j        D ]\  }} |||          }|st          |t          j                  r||                                fV  n7|t          j        u r)|                     |                                          V  t%          ||                                |z
  dz
              nt          j        |fV  dS )a  
        Return an iterable of (tokentype, value) pairs generated from
        `text`. If `unfiltered` is set to `True`, the filtering mechanism
        is bypassed even if filters are defined.

        Also preprocess the text, i.e. expand tabs and strip it if
        wanted and applies registered filters.

        Split ``text`` into (tokentype, text) pairs.

        ``stack`` is the initial stack (default: ``['root']``)
        zutf-8zunicode-escapez+Expected text or file-like object, got {!r}   N)
isinstancer   readstrbytesdecodeUnicodeDecodeError	TypeErrorformattype	enumerater#   r   
_TokenTypegroupr   PROCESS_AS_KEYWORDr:   r   endError)	r    textencodingiterableposcharrexmatchactionms	            r   
get_tokenszLexer.get_tokensk   s      dJ'' 	99;;DdC   	0e$$ 
	0 9{{8,,9;;w//DD) 9 9 9;;'788DDD9 I"F4::..0 0 0 T??! 	) 	)IC$(O ) ) &HT3'' 5(9:: 5 !''))+++++x::://!''))44444!%%''C-!"3444lD((((	) 	)s   0B B('B(N)__name__
__module____qualname____doc__r   r   r   classmethodr   r   r   r   r   r:   rT   r'   r!   r   r	   r	      s        N N DFFE( % % [%- - -  
 
 
( ( (
& & &-) -) -) -) -) -)r!   r	   c                 \    t                                                               | |          S )zTokenize sql.

    Tokenize *sql* using the :class:`Lexer` and return a 2-tuple stream
    of ``(token type, value)`` items.
    )r	   r   rT   )sqlrM   s     r   tokenizer]      s&     %%''223AAAr!   rU   )rY   r(   	threadingr   ior   sqlparser   r   sqlparse.utilsr   r	   r]   r'   r!   r   <module>rb      s     				             % % % % % % % % " " " " " "A) A) A) A) A) A) A) A)HB B B B B Br!   