
    j                     b    S r SSKrSSKJr  SSKJr  SSKJrJr  SSK	J
r
   " S S5      rS
S	 jrg)z	SQL Lexer    N)
TextIOBase)Lock)keywordstokens)consumec                   b    \ rS rSrSrSr\" 5       r\S 5       r	S r
S rS rS rS	 rSS
 jrSrg)Lexer   znThe Lexer supports configurable syntax.
To add support for additional keywords, use the `add_keywords` method.Nc                     U R                      U R                  c&  U " 5       U l        U R                  R                  5         SSS5        U R                  $ ! , (       d  f       U R                  $ = f)zJReturns the lexer instance used internally
by the sqlparse core functions.N)_lock_default_instancedefault_initialization)clss    F/var/www/html/KUNJ/venv/lib/python3.13/site-packages/sqlparse/lexer.pyget_default_instanceLexer.get_default_instance/   s\     YY$$,(+%%%<<>  $$$	 Y $$$s   4A
A.c                    U R                  5         U R                  [        R                  5        U R	                  [        R
                  5        U R	                  [        R                  5        U R	                  [        R                  5        U R	                  [        R                  5        U R	                  [        R                  5        U R	                  [        R                  5        U R	                  [        R                  5        U R	                  [        R                  5        U R	                  [        R                  5        g)zdInitialize 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   Lexer.default_initialization9   s     	

8--.(223(223(112(334(//0(445(556(445(++,    c                      / U l         / U l        g)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   Lexer.clearH   s    
 r$   c                     [         R                  [         R                  -  nU VVs/ s H'  u  p4[         R                  " X25      R                  U4PM)     snnU l        gs  snnf )z.Set the list of regex that will parse the SQL.N)re
IGNORECASEUNICODEcompilematchr'   )r"   r   FLAGSrxtts        r   r   Lexer.set_SQL_REGEXP   sP    

* $
# ZZ"(("-#
 
s   .Ac                 :    U R                   R                  U5        g)z`Add keyword dictionaries. Keywords are looked up in the same order
that dictionaries were added.N)r(   append)r"   r   s     r   r   Lexer.add_keywordsX   s     	h'r$   c                     UR                  5       nU R                   H  nX#;   d  M
  X2   U4s  $    [        R                  U4$ )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_keywordLexer.is_keyword]   s@     kkmnnF}{E)) % ;;%%r$   c              #     #    [        U[        5      (       a  UR                  5       n[        U[        5      (       a  OY[        U[        5      (       a,  U(       a  UR                  U5      nO+ UR                  S5      nO[        S[        U5      < 35      e[        R                  " U5      nUR                  n[        U5      nU H  u  pgXd;   a2  UR                  U5      nUb  Uu  pXXi 4v   [        XYU-
  S-
  5        M<  U R                   H  u  pU" X5      nU(       d  M  [        U[         R"                  5      (       a  XR%                  5       4v   O4U[        R&                  L a!  U R)                  UR%                  5       5      v   [        X]R+                  5       U-
  S-
  5          M     [         R,                  U4v   M     g! [         a    UR                  S5      n GNOf = f7f)as  
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 N   )
isinstancer   readstrbytesdecodeUnicodeDecodeError	TypeErrortyper   find_delimited_spansopeners	enumerateresolver   r'   r   
_TokenTypegroupPROCESS_AS_KEYWORDr=   endError)r"   textencodingdelimited_spansspan_openersiterableposcharresolvedrP   ttyperexmatchactionms                 r   
get_tokensLexer.get_tokensj   s     dJ''99;DdC  e$${{8,9;;w/D Ed4j^TUU"77=&..T?!IC
 "*2237'!)JCc..HCi!m4$(OO T'(9(9:: '')++x::://!'')44%%'C-!"34 %4 llD((5 " * 9;;'78D9s+   A*G*-G >E
G*G'#G*&G''G*r&   N)__name__
__module____qualname____firstlineno____doc__r   r   r   classmethodr   r   r   r   r   r=   r^   __static_attributes__ r$   r   r	   r	      sI    N FE( % %-
(
&;)r$   r	   c                 H    [         R                  5       R                  X5      $ )zuTokenize sql.

Tokenize *sql* using the :class:`Lexer` and return a 2-tuple stream
of ``(token type, value)`` items.
)r	   r   r^   )sqlrS   s     r   tokenizerk      s     %%'223AAr$   r`   )re   r+   ior   	threadingr   sqlparser   r   sqlparse.utilsr   r	   rk   rh   r$   r   <module>rp      s.     	   % "O) O)dBr$   