
    %D[e                     \    d Z ddl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)
TextIOBase)tokenskeywords)consumec                   R    e Zd ZdZd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                 n    | j         ( |             | _         | j                                          | j         S )zRReturns the lexer instance used internally
        by the sqlparse core functions.)_default_intancedefault_initialization)clss    H/var/www/html/Alfredo/env/lib/python3.11/site-packages/sqlparse/lexer.pyget_default_instancezLexer.get_default_instance.   s9     '#&355C  77999##    c                    |                                   |                     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_PLPGSQLKEYWORDS_HQLKEYWORDS_MSACCESSKEYWORDSselfs    r   r   zLexer.default_initialization7   s     	

8-...(2333(2333(3444(/000(4555(+,,,,,r   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.clearC   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>N   sA     
 
 
B ZE""("-
 
 
r   N)r#   
IGNORECASEUNICODEr   )r   r   r)   s     @r   r   zLexer.set_SQL_REGEXK   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_keywordsS   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_keywordX   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_KEYWORDr5   r   endError)	r   textencodingiterableposcharrexmatchactionms	            r   
get_tokenszLexer.get_tokense   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
   classmethodr   r   r   r   r   r5   rO   r"   r   r   r   r      s        N N ( $ $ [$
- 
- 
-  
 
 
( ( (
& & &-) -) -) -) -) -)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   rO   )sqlrH   s     r   tokenizerX      s&     %%''223AAAr   rP   )rT   r#   ior   sqlparser   r   sqlparse.utilsr   r   rX   r"   r   r   <module>r\      s     				       % % % % % % % % " " " " " "|) |) |) |) |) |) |) |)~B B B B B Br   