
    ^h                        S SK r S SKrS SKrS SKJrJr  S SKJr  S SKJ	r	  S SK
JrJrJrJrJrJrJrJr  \(       a  S SKJr  \\\\   4   r " S S\5      r " S	 S
\5      rS\\\\\\4      4   S\\S4   S\\\\\\4      4   4S jrS\\\\R6                     4   S\S\\\\\\4      4   4S jrS\\   S\\\R6                        4S jrSSS\SS4S jrg)    N)Counterdefaultdict)Enum)StringIO)TYPE_CHECKINGCallableDictList
NamedTupleSetTupleUnion)AstRewriterc                   $    \ rS rSrSrSrSrSrSrg)AugmentationType   prefixsuffixdotbinop N)	__name__
__module____qualname____firstlineno__r   r   r   r   __static_attributes__r       U/home/james-whalen/.local/lib/python3.13/site-packages/pyccolo/syntax_augmentation.pyr   r      s    FF
CEr   r   c                   4    \ rS rSr% \\S'   \\S'   \\S'   Srg)AugmentationSpec   aug_typetokenreplacementr   N)r   r   r   r   r   __annotations__strr   r   r   r   r    r       s    Jr   r    pos_by_spec
spec_order.returnc                 &   [        [        5      n0 nU R                  5        H0  u  pE[        5       X4'   U H  u  pgX&   R	                  Xt45        M     M2     UR                  5        H  u  ph[        5       n	[        5       n
UR                  5         U Hx  u  pt[        UR                  5      [        UR                  5      -
  nU H  nX==   U-  ss'   X:X  d  M    O   X==   U-  ss'   XyU   X   -
  -
  nX4   R                  Xm45        Mz     M     U$ )N)r   listitemssetappendr   sortlenr#   r$   add)r'   r(   grouped_by_linefixed_pos_by_specspec	positionslinecolcols_with_spectotal_offset_by_specoffset_by_specoffsetprev_appliednew_cols                 r   fix_positionsr>      s    FQQUEVOFH&,,."%%"ID!((#5 # /
 !0 5 5 7<CI6=i'IC_s4+;+;'<<F * %2f<2' !+  F* $7.:NNOG#''8 (	 !8  r   tokenizabler4   c                   ^^
^^ [        U [        5      (       a  [        [        U /5      5      S   nOU n[	        5       m[	        5       mSm
SS[
        SS 4UUU4S jjjnS[        R                  SS 4U
U4S jjnSnSn/ nS nU[        U5      :  GaU  X%   n	UbY  UR                  S   U	R                  S   :X  a9  TR                  SU	R                  S	   UR                  S	   -
  -  5        U" 5         O)SnU" S
S9  TR                  SU	R                  S	   -  5        U" U	5        U" 5         TR                  TR                  5       :X  a  UR                  T
S   T
S	   U-   45        U[        TR                  5      [        TR                  5      -
  -  nTR                  TR                  5        TR!                  S5        TR#                  5         U	nUS	-  nU[        U5      :  a  GMU  U" S
S9  TR                  5       U4$ )Nr   )rA   forcer)   c                    > U (       d.  TR                   R                  TR                  5       5      (       dA  TR                  TR                  5       5        TR	                  S5        TR                  5         g g )Nr   )r#   
startswithgetvaluewriteseektruncate)rB   matchr4   transformeds    r   _flush_match@replace_tokens_and_get_augmented_positions.<locals>._flush_matchF   sQ    

--enn.>??enn./JJqMNN @r   tokc                 |   > TR                  5       S:X  a  U R                  mTR                  U R                  5        g )N )rE   startrF   string)rM   cur_match_startrI   s    r   _write_match@replace_tokens_and_get_augmented_positions.<locals>._write_matchL   s+    >>r!!iiOCJJr       T)rB   )F)
isinstancer&   r+   make_tokens_by_liner   booltokenize	TokenInfor0   endrP   rF   r#   rE   r.   r$   rG   rH   )r?   r4   tokensrK   rS   idx
col_offsetr5   prevcurrR   rI   rJ   s    `        @@@r   *replace_tokens_and_get_augmented_positionsrb   ;   s    +s##);-89!<*KJEOD T   (,,       CJID
F
ksyy| ;KKsyy|dhhqk9:;NJt$KKciil*+S::))oa0/!2Dz2QRS#d../#djj/AAJd../JJqMNNq% F
( t!9,,r   linesc                    [         R                  [         R                  p!/ /n[        U 5      S:  a/  U S   R	                  S5      (       d  [
        R                  " S5        Sn [         R                  " [        U 5      R                  5       H  nUS   R                  U5        UR                  U:X  d  UR                  U:X  a  US::  a  UR                  / 5        MP  UR                  S;   a  US-  nMg  UR                  S;   d  My  US:  d  M  US-  nM     US   (       d  UR                  5         U$ ! [         R                   a     N2f = f)aO  Tokenize a series of lines and group tokens by line.

The tokens for a multiline Python string or expression are grouped as one
line. All lines except the last lines should keep their line ending ('\n',
'\r\n') for this to properly work. Use `.splitlines(keeplineending=True)`
for example when passing block of text to this function.

rV   r   )
z
z`make_tokens_by_line` received a list of lines which do not have lineending markers ('\n', '\r', '\r\n', '\x0b', '\x0c'), behavior will be unspecifiedrA   >   ([{>   )]})rZ   NEWLINENLr0   endswithwarningswarngenerate_tokensiter__next__r.   typerQ   
TokenErrorpop)rc   ro   rp   tokens_by_lineparenlevr#   s         r   rX   rX   p   s    ""HKKR68TN
5zA~eAh//0TUU-	

 H--d5k.B.BCE2%%e,

g%EJJ",<8q=%%b)0A0a<MH D "  s   $BD3 D3 	D3 3E
	E
rewriterr   aug_speczCallable[[CodeType], CodeType]c                    ^ ^ SUU 4S jjnU$ )Nc                 <  > [        U [        5      (       a  U nOU R                  SS9n[        [        R                  " [        U5      6 5      n[        UT5      u  p4U H  nTR                  " T/UQ76   M     [        U [        5      (       a  UR                  SS9$ U$ )NT)keepends)rW   r+   
splitlines	itertoolschainrX   rb   register_augmented_position)rc   
code_linesr]   rJ   r5   posr}   r|   s         r   _input_transformer1make_syntax_augmenter.<locals>._input_transformer   s    eT""$)J))4)8Jioo'::'FGH!KH"
 C00@C@ eT""))4)88r   )rc   CodeTyper)   r   r   )r|   r}   r   s   `` r   make_syntax_augmenterr      s       r   )r   rZ   rr   collectionsr   r   enumr   ior   typingr   r   r	   r
   r   r   r   r   pyccolo.ast_rewriterr   r&   r   r   r    intr>   r[   rb   rX   r   r   r   r   <module>r      s9      ,   U U U0S$s)^$Ht z &E#s(O(<<=&+, 

Cc3h0
01<0-sD!3!34450-=M0-
3U38_%%&0-j'tCy 'T$x7I7I2J-K 'T'7%r   