
                         V    S r SSK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)tokenskeywords)consumec                   T    \ rS rSrSrS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                 n    U R                   c  U " 5       nUR                  5         Xl         U R                   $ )zJReturns the lexer instance used internally
by the sqlparse core functions.)_default_intancedefault_initialization)clsdefault_instances     !lib/third_party/sqlparse/lexer.pyget_default_instanceLexer.get_default_instance.   s6     '"u335#3 ###    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        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_PLPGSQLKEYWORDS_HQLKEYWORDS_MSACCESSKEYWORDSselfs    r   r   Lexer.default_initialization8   s     	

8--.(223(223(334(//0(445(++,r   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.clearD   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_REGEXL   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_keywordsT   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_keywordY   s@     kkmnnF}{E)) % ;;%%r   c              #   :  #    [        U[        5      (       a  UR                  5       n[        U[        5      (       a  Od[        U[        5      (       a,  U(       a  UR                  U5      nO6 UR                  S5      nO#[        SR                  [        U5      5      5      e[        U5      nU H  u  pEU R                   H  u  pgU" X5      nU(       d  M  [        U[        R                  5      (       a  XxR                  5       4v   O4U[        R                   L a!  U R#                  UR                  5       5      v   [%        X8R'                  5       U-
  S-
  5          M     [        R(                  U4v   M     g! [         a    UR                  S5      n Nf = 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 {!r}   N)
isinstancer   readstrbytesdecodeUnicodeDecodeError	TypeErrorformattype	enumerater#   r   
_TokenTypegroupr   PROCESS_AS_KEYWORDr9   r   endError)	r   textencodingiterableposcharrexmatchactionms	            r   
get_tokensLexer.get_tokensf   sG     dJ''99;DdC  e$${{8,9;;w/D I"F4:.0 0 T?!IC$(OO T'(9(9:: '')++x::://!'')44%%'C-!"34 %4 llD(( " * 9;;'78D9s+   A*F-E: >C<F:FFFFr"   N)__name__
__module____qualname____firstlineno____doc__r   classmethodr   r   r   r   r   r9   rT   __static_attributes__ r   r   r   r      sB    N ( $ $
-
(
&-)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   rT   )sqlrM   s     r   tokenizera      s     %%'223AAr   rV   )r[   r'   ior   sqlparser   r   sqlparse.utilsr   r   ra   r^   r   r   <module>re      s+     	  % "}) })@Br   