
    AeH              	       h   d dl mZ d dlZ ej                  eeeeeee       d dlZd dlZddlmZ ddl	m
Z
 ddlmZ dd	lmZmZ dd
lmZmZmZ ddlmZ d Zd Zd ZdZdad Zg dZeg dz   Z G d de      Z G d de      Zd Z  G d de      Z! G d de!      Z" G d de!      Z# G d de
      Z$y)    )absolute_importN)make_lexiconlexiconprint_functionerrorwarningosplatform   )Utils)Scanner)UnrecognizedInput   )r   r   )any_string_prefixr   IDENT)r   c                  .    t         s
t               a t         S N)r   r        8lib/python3.12/site-packages/Cython/Compiler/Scanning.pyget_lexiconr      s    .Nr   )globalnonlocaldefclassprintdelpassbreakcontinuereturnraiseimportexectryexceptfinallywhileifelifelseforinassertandornotislambdafromyieldwith)	includectypedefcdefcpdefcimportDEFIFELIFELSEc                   $    e Zd Zd Zd Zd Zd Zy)Methodc                 6    || _         |xs d | _        || _        y r   )namekwargs__name__)selfrC   rD   s      r   __init__zMethod.__init__8   s    	nr   c                 |    t        || j                        }| j                   ||fi | j                  S  ||      S r   )getattrrC   rD   )rF   streamtextmethods       r   __call__zMethod.__call__=   s9    +.2kk.Evd*dkk*W6RV<Wr   c                     | S r   r   rF   s    r   __copy__zMethod.__copy__B       r   c                     | S r   r   rF   memos     r   __deepcopy__zMethod.__deepcopy__E   rQ   r   N)rE   
__module____qualname__rG   rM   rP   rU   r   r   r   rA   rA   6   s    
X
r   rA   c                   2    e Zd ZddZd Zd Zd Zd Zd Zy)	CompileTimeScopeNc                      i | _         || _        y r   )entriesouter)rF   r\   s     r   rG   zCompileTimeScope.__init__M   s    
r   c                 "    || j                   |<   y r   r[   )rF   rC   values      r   declarezCompileTimeScope.declareQ   s    "Tr   c                 :    | j                   j                  |       y r   )r[   updaterF   others     r   rb   zCompileTimeScope.updateT   s    E"r   c                      | j                   |   S r   r^   rF   rC   s     r   lookup_herezCompileTimeScope.lookup_hereW   s    ||D!!r   c                     || j                   v S r   r^   rf   s     r   __contains__zCompileTimeScope.__contains__Z   s    t||##r   c                     	 | j                  |      S # t        $ r# | j                  }|r|j                  |      cY S  w xY wr   )rg   KeyErrorr\   lookup)rF   rC   r\   s      r   rl   zCompileTimeScope.lookup]   sE    	##D)) 	JJE||D))	s    (??r   )	rE   rV   rW   rG   r`   rb   rg   ri   rl   r   r   r   rY   rY   K   s     ##"$r   rY   c                  X   t               } d}t        |t        j                               D ]  \  }}| j	                  ||        	 dd l}d}|D ]  }	 | j	                  |t        ||             ! ddl
m} | j	                  d|       | j	                  dt        |dt        |d                   | j	                  dt        |dt        |d	                   | j	                  d
t        |d
t        |d                   t        |       }|S # t        $ r dd l}Y w xY w# t        $ r Y w xY w)N)UNAME_SYSNAMEUNAME_NODENAMEUNAME_RELEASEUNAME_VERSIONUNAME_MACHINEr   )*FalseTrueabsallanyasciibinbool	bytearraybyteschrcmpcomplexdictdivmod	enumeratefilterfloatformat	frozensethashhexintlenlistmapmaxminoctordpowrangereprreversedroundsetslicesortedstrsumtuplezip)reducer   unicoder   longr   xranger   )rY   r   r
   unamer`   __builtin__ImportErrorbuiltinsrI   AttributeError	functoolsr   )benvnamesrC   r_   r   r   denvs          r   initial_compile_time_envr   h   s   DbE5(.."23 "eT5!"&
E  	LLwx67 !LL6"LLGHi59QRSLL678U3KLMLL78Xwx7QRSD!DK=  $  		s$   D
 D
DD	D)(D)c                   \    e Zd ZdZdZdZdZdZd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zy)SourceDescriptorz<
    A SourceDescriptor should be considered immutable.
    Npyx c                     J r   r   rO   s    r   __str__zSourceDescriptor.__str__   s    r   c                 p    t         j                  j                  |      \  }}|dv xr |dd  xs d| _        y )N)z.pyxz.pxdz.pyr   r   )r	   pathsplitext
_file_type)rF   filenamerC   exts       r   set_file_type_from_namez(SourceDescriptor.set_file_type_from_name   s7    GG$$X.	c!88DSWMr   c                     | j                   dv S )N)r   pxdr   rO   s    r   is_cython_filezSourceDescriptor.is_cython_file   s    .00r   c                      | j                   dk(  S )Npyr   rO   s    r   is_python_filezSourceDescriptor.is_python_file   s    $&&r   c                     | j                   F| j                         j                  dd      j                  d      }|j	                  dd      | _         | j                   S )NASCIIreplace\/)_escaped_descriptionget_descriptionencodedecoder   )rF   esc_descs     r   get_escaped_descriptionz(SourceDescriptor.get_escaped_description   sZ    $$,$$&--gyAHHQ  )1(8(8s(CD%(((r   c                 T    	 | j                   |j                   kD  S # t        $ r Y yw xY wNF	_cmp_namer   rc   s     r   __gt__zSourceDescriptor.__gt__   ,    	>>EOO33 		    	''c                 T    	 | j                   |j                   k  S # t        $ r Y yw xY wr   r   rc   s     r   __lt__zSourceDescriptor.__lt__   r   r   c                 T    	 | j                   |j                   k  S # t        $ r Y yw xY wr   r   rc   s     r   __le__zSourceDescriptor.__le__   s,    	>>U__44 		r   c                     | S r   r   rO   s    r   rP   zSourceDescriptor.__copy__   rQ   r   c                     | S r   r   rS   s     r   rU   zSourceDescriptor.__deepcopy__   rQ   r   )rE   rV   rW   __doc__r   r   r   r   r   r   r   r   r   r   r   r   rP   rU   r   r   r   r   r      sQ     HJIN1')r   r   c                   D    e Zd ZdZddZddZd Zd Zd Zd Z	d	 Z
d
 Zy)FileSourceDescriptora7  
    Represents a code source. A code source is a more generic abstraction
    for a "filename" (as sometimes the code doesn't come from a file).
    Instances of code sources are passed to Scanner.__init__ as the
    optional name argument and will be passed back when asking for
    the position()-tuple.
    Nc                 <   t        j                  |      }|xs || _        || _        t        j
                  j                  d      t        j                  z   }|j                  |      r|t        |      d  n|| _
        | j                  |       || _        i | _        y )N.)r   decode_filenamepath_descriptionr   r	   r   abspathsep
startswithr   	file_pathr   r   _lines)rF   r   r   workdirs       r   rG   zFileSourceDescriptor.__init__   s    ((2 0 <H ''//#&/4<4G4G4P#g,-0V^$$X.!r   c                 6   ||f}	 | j                   |   }||S 	 t        j                  | j                  ||      5 }t        |      }d d d        || j                   v r| j                   |<   |S d | j                   |<   S # t        $ r Y qw xY w# 1 sw Y   HxY w)N)encodingerror_handling)r   rk   r   open_source_filer   r   )rF   r   r   keylinesfs         r   	get_lineszFileSourceDescriptor.get_lines   s     (	KK$E  !
 ##DMMHUcd 	hiGE	 $++$DKK
   $DKK  			 	s   B  B 	BBBc                     	 t         j                  j                  | j                        S # t        $ r | j                  cY S w xY wr   )r	   r   relpathr   
ValueErrorrO   s    r   r   z$FileSourceDescriptor.get_description   s;    	)77??4#8#899 	)(((	)s   (+ AAc                     | j                   }t        j                  t        j                         t        j
                  j                  z         }|j                  |      r|t        |      d  S |S r   )	r   r   r   r	   getcwdr   r   r   r   )rF   r   cwds      r   get_error_descriptionz*FileSourceDescriptor.get_error_description   sO    }}##BIIK"''++$=>??3C	?"r   c                     | j                   S r   )r   rO   s    r   get_filenametable_entryz,FileSourceDescriptor.get_filenametable_entry  s    ~~r   c                 X    t        |t              xr | j                  |j                  k(  S r   )
isinstancer   r   rc   s     r   __eq__zFileSourceDescriptor.__eq__  s"    %!56Z4==ENN;ZZr   c                 ,    t        | j                        S r   )r   r   rO   s    r   __hash__zFileSourceDescriptor.__hash__  s    DMM""r   c                      d| j                   z  S )Nz<FileSourceDescriptor:%s>)r   rO   s    r   __repr__zFileSourceDescriptor.__repr__  s    *T]]::r   r   NN)rE   rV   rW   r   rG   r   r   r   r   r   r   r   r   r   r   r   r      s0    	,)[#;r   r   c                   @    e Zd ZdZd Zd
dZd ZeZd Zd Z	d Z
d	 Zy)StringSourceDescriptorzu
    Instances of this class can be used instead of a filenames if the
    code originates from a string object.
    c                 x    || _         |j                  d      D cg c]  }|dz   	 c}| _        || _        y c c}w )N
)rC   split	codelinesr   )rF   rC   codexs       r   rG   zStringSourceDescriptor.__init__  s4    	,0JJt,<=q!d(= >s   7Nc                     |s| j                   S | j                   D cg c]#  }|j                  ||      j                  |      % c}S c c}w r   )r  r   r   )rF   r   r   lines       r   r   z StringSourceDescriptor.get_lines  sK    >>! !%0 KK.9@@J 0 0 0s   (Ac                     | j                   S r   rC   rO   s    r   r   z&StringSourceDescriptor.get_description$  s    yyr   c                      y)Nstringsourcer   rO   s    r   r   z.StringSourceDescriptor.get_filenametable_entry)  s    r   c                     t        |       S r   )idrO   s    r   r   zStringSourceDescriptor.__hash__,  s    $xr   c                 X    t        |t              xr | j                  |j                  k(  S r   )r   r   rC   rc   s     r   r   zStringSourceDescriptor.__eq__2  s"    %!78TTYY%**=TTr   c                      d| j                   z  S )Nz<StringSourceDescriptor:%s>r  rO   s    r   r   zStringSourceDescriptor.__repr__5  s    ,tyy88r   r   )rE   rV   rW   r   rG   r   r   r   r   r   r   r   r   r   r   r   r     s3    0 ,U9r   r   c                       e Zd Z	 	 d dZd Zd Zd Zd Zd Zd Z	d	d
dddZ
d Zd Zd Zd Zd Zd Zd Zd Zd Zd!dZd"dZd"dZd"dZd Zd Zd#dZd Zd Zy)$PyrexScannerNc	                 n   t        j                  | t               |||       |j                         rd| _        t        t              | _        nd| _        t        t              | _        d| _	        |rr|j                  | _
        |j                  | _        |j                  | _        |j                  | _        |j                  | _        |j                  r| j                          n{|| _
        |j                  | _        t!               | _        d| _        d| _        t#        |j$                  dd       r/| j                  j'                  |j$                  j                         || _        || _        t,        | _        dg| _        d | _        d| _        | j7                  d       d| _        | j;                          y )NTFr   r   compile_time_envINDENTr   )r   rG   r   r   in_python_filer   py_reserved_wordskeywordspyx_reserved_wordsasync_enabledcontextincluded_filesr  compile_time_evalcompile_time_exprenter_asyncr   rI   optionsrb   parse_commentssource_encodingtrace_scannertraceindentation_stackindentation_charbracket_nesting_levelbeginsynext)	rF   filer   parent_scannerscoper  r   r  initial_poss	            r   rG   zPyrexScanner.__init__B  sa   {}dHkJ""$"&D 12DM"'D 23DM)11DL"0"?"?D$2$C$CD!%3%E%ED"%3%E%ED"++  ""DL"'"6"6D$<$>D!%&D"%&D"w(:DA%%,,W__-M-MN,."
"# $%&"

8		r   c                 B    | j                   r| j                  d|       y y )Ncommentline)r  producerF   rK   s     r   r.  zPyrexScanner.commentlinek  s    LL- r   c                 H    | j                  ||j                  dd             y )N_r   )r/  r   )rF   rK   symbols      r   strip_underscoreszPyrexScanner.strip_underscoreso  s    VT\\#r23r   c                      | j                   d   S )N)r#  rO   s    r   current_levelzPyrexScanner.current_levelr  s    %%b))r   c                 0    | xj                   dz  c_         |S Nr   r%  r0  s     r   open_bracket_actionz PyrexScanner.open_bracket_actionu      ""a'"r   c                 0    | xj                   dz  c_         |S r9  r:  r0  s     r   close_bracket_actionz!PyrexScanner.close_bracket_actiony  r<  r   c                 j    | j                   dk(  r$| j                  d       | j                  dd       y y )Nr   r  NEWLINEr   )r%  r&  r/  r0  s     r   newline_actionzPyrexScanner.newline_action}  s/    %%*JJx LLB' +r   	SQ_STRING	DQ_STRING
TSQ_STRING
TDQ_STRING)'"z'''z"""c                     |d d t         v r|dd  }|d d t         v r| j                  | j                  |          | j                  d       y )Nr   BEGIN_STRING)r   r&  string_statesr/  r0  s     r   begin_string_actionz PyrexScanner.begin_string_action  sP    2Ah++8D 2Ah++

4%%d+,^$r   c                 H    | j                  d       | j                  d       y )Nr   
END_STRING)r&  r/  r0  s     r   end_string_actionzPyrexScanner.end_string_action  s    

2\"r   c                 H    | j                  |       | j                  d       y )NzUnclosed string literal)rN  r   r0  s     r   unclosed_string_actionz#PyrexScanner.unclosed_string_action  s    t$

,-r   c                    | j                  d       |r_|d   }| j                  || _        n | j                  |k7  r| j                  d       |j                  |d      dk7  r| j                  d       | j	                         }t        |      }||k(  ry ||kD  r.| j                  j                  |       | j                  dd       y || j	                         k  r@| j                  j                          | j                  dd       || j	                         k  r@|| j	                         k7  r| j                  d       y y )Nr   r   zMixed use of tabs and spacesr  DEDENTzInconsistent indentation)
r&  r$  r   r   r7  r   r#  appendr/  pop)rF   rK   cr7  	new_levels        r   indentation_actionzPyrexScanner.indentation_action  s!   

2
 QA$$,()% ((A-JJ=>||Ar"b(

9:**,I	%&"")))4LL2&d0022&&**,Xr* d0022
 D..00

56 1r   c                     t        | j                        dkD  rE| j                  dd       | j                  j                          t        | j                        dkD  rE| j                  dd       y )Nr   rR  r   EOF)r   r#  r/  rT  r0  s     r   
eof_actionzPyrexScanner.eof_action  sZ    $(()A-LL2&""&&( $(()A- 	UBr   c                    	 | j                         \  }}|t        k(  r|| j                  v ry|dk(  r8t
        | j                  j                  v r| j                  j                  d       n<|dk(  r5| j                  j                  dk\  r| j                  j                  d       n|}| j                  j                  |      }|| _        || _        y # t        $ r | j                  d       Y y w xY w)NzUnrecognized characterr   r$      )readr   r   r   r  r   r  future_directivesdiscardlanguage_levelintern_ustringr'  systringpositionr   )rF   r'  rb  r2  r  colts          r   r(  zPyrexScanner.next  s    	99;LB ;4==(x'Ndll>\>\,\MM))'2(T\\-H-HA-MMM))&1!B||228<H  ! 	JJ/0	s   C C,+C,c                     | j                   | j                  f}| j                          | j                   | j                  f} | j                  |  |\  | _         | _        |S r   )r'  rb  r(  unread)rF   savedr(  s      r   peekzPyrexScanner.peek  sP    &		ww%T!&r   c                 l    | j                  | j                  | j                         || _        || _        y r   )rg  r'  rb  )rF   r'  rb  s      r   put_backzPyrexScanner.put_back  s&    DGGT]]+ r   c                 @    | j                   j                  d||f       y )Nr   )queueinsert)rF   tokenr_   s      r   rg  zPyrexScanner.unread  s    

!eU^,r   c                 ~    || j                         }| j                  dk(  rt        |d       t        ||      }|r|y )Nr  z!Possible inconsistent indentation)rc  r'  r   )rF   messageposfatalerrs        r   r   zPyrexScanner.error  s>    ;--/C77h#:;C!)5r   c                 h    | j                   |k(  r| j                          y | j                  ||       y r   )r'  r(  expectedrF   whatrq  s      r   expectzPyrexScanner.expect  s$    77d?IIKMM$(r   c                     | j                   t        k(  r | j                  |k(  r| j                          y | j	                  ||       y r   )r'  r   rb  r(  rv  rw  s      r   expect_keywordzPyrexScanner.expect_keyword  s0    77e 5IIKMM$(r   c                     |r| j                  |       y | j                  t        k(  r| j                  }n| j                  }| j                  d|d|d       y )Nz
Expected 'z
', found 'rF  )r   r'  r   rb  )rF   rx  rq  founds       r   rv  zPyrexScanner.expected  s@    JJwww%JJdEBCr   c                 (    | j                  dd       y )Nr  z)Expected an increase in indentation levelry  rO   s    r   expect_indentzPyrexScanner.expect_indent	  s    HIJr   c                 (    | j                  dd       y )NrR  z(Expected a decrease in indentation levelr  rO   s    r   expect_dedentzPyrexScanner.expect_dedent  s    HHIr   c                     d }|r/| j                   dk(  r | j                         }| j                          | j                   dk7  r| j                  d|       |t	        |d       y y )N;rY  r@  zuseless trailing semicolon)r'  rc  r(  ry  r   )rF   rq  ignore_semicolonuseless_trailing_semicolons       r   expect_newlinezPyrexScanner.expect_newline  s[    %)"3)-&IIK77eKK	7+%1.0LM 2r   c                     | xj                   dz  c_         | j                   dk(  r7| j                  j                  d       | j                  j                  d       y y )Nr   asyncawait)r  r  addrO   s    r   r  zPyrexScanner.enter_async  sJ    a"MMg&MMg& #r   c                 `   | j                   dkD  sJ | xj                   dz  c_         | j                   s|| j                  j                  d       | j                  j                  d       | j                  dv r7t        | j
                  j                  | j                        c| _        | _        y y y )Nr   r   r  r  )r  r  )r  r  r_  r'  r   r  ra  rb  rO   s    r   
exit_asynczPyrexScanner.exit_async   s    !!A%%a!!MM!!'*MM!!'*ww,,).0K0KDGG0T& - "r   )NNNNTN)NTr   )zExpected a newlineF)rE   rV   rW   rG   r.  r4  r7  r;  r>  rA  rJ  rK  rN  rP  rW  rZ  r(  ri  rk  rg  r   ry  r{  rv  r  r  r  r  r  r   r   r   r  r  ;  s     7;bf'R.4*( 	M%#."7H 52!
-))DKJ	N'Ur   r  )%
__future__r   cythonr`   objectr	   r
   r   r   Plex.Scannersr   Plex.Errorsr   Errorsr   r   Lexiconr   r   r   Futurer   debug_scannerr!  scanner_debug_flagsscanner_dump_filer   r   r  r  rA   rY   r   r   r   r   r  r   r   r   <module>r     s    '  FF$FF6+ 
   # + " ; ; "  
  ' *  V *v :%T9v 9xA;+ A;H$9- $9RlU7 lUr   