
    +h                     T    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
y)
z	SQL Lexer    N)
TextIOBase)tokenskeywords)consumec                   J    e Zd ZdZdZed        Zd Zd Zd Z	d Z
d Zd
d	Zy)LexerzrThe Lexer supports configurable syntax.
    To add support for additional keywords, use the `add_keywords` method.Nc                 ~    | j                   & |        | _         | j                   j                          | j                   S )zRReturns the lexer instance used internally
        by the sqlparse core functions.)_default_intancedefault_initialization)clss    A/var/www/html/venv/lib/python3.12/site-packages/sqlparse/lexer.pyget_default_instancezLexer.get_default_instance.   s8     '#&5C   779###    c                    | j                          | j                  t        j                         | j	                  t        j
                         | j	                  t        j                         | j	                  t        j                         | j	                  t        j                         | j	                  t        j                         | j	                  t        j                         y)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23(223(334(//0(445(++,r   c                      g | _         g | _        y)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  }|D cg c]'  \  }}t        j                  ||      j                  |f) c}}| _        yc c}}w )z.Set the list of regex that will parse the SQL.N)re
IGNORECASEUNICODEcompilematchr   )r   r   FLAGSrxtts        r   r   zLexer.set_SQL_REGEXK   sO    

* $
B ZZE"(("-
 
s   ,Ac                 :    | j                   j                  |       y)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                     |j                         }| j                  D ]  }||v s||   |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   sI     kkmnn 	&Ff}c{E))	& ;;%%r   c              #     K   t        |t              r|j                         }t        |t              rnZt        |t              r'|r|j                  |      }n6	 |j                  d      }n#t        dj                  t        |                  t        |      }|D ]  \  }}| j                  D ]  \  }} |||      }|st        |t        j                        r||j                         f n3|t        j                   u r!| j#                  |j                                t%        ||j'                         |z
  dz
           t        j(                  |f  y# t        $ r |j                  d      }Y w xY ww)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_KEYWORDr1   r   endError)	r   textencodingiterableposcharrexmatchactionms	            r   
get_tokenszLexer.get_tokense   sP     dJ'99;DdC e${{8,9;;w/D I"F4:.0 0 T?! 	)IC$(OO ) &T3'(9(9: !'')++x::://!'')44!%%'C-!"34) llD((	) * 9;;'78D9s+   AE;E *C1E;E85E;7E88E;N)__name__
__module____qualname____doc__r
   classmethodr   r   r   r   r   r1   rK    r   r   r   r      sB    N ( $ $
-
(
&-)r   r   c                 J    t         j                         j                  | |      S )zTokenize sql.

    Tokenize *sql* using the :class:`Lexer` and return a 2-tuple stream
    of ``(token type, value)`` items.
    )r   r   rK   )sqlrD   s     r   tokenizerU      s      %%'223AAr   rL   )rP   r!   ior   sqlparser   r   sqlparse.utilsr   r   rU   rR   r   r   <module>rY      s+     	  % "|) |)~Br   