
    dafC                         d dl Z d dlZd dlZd dlmZmZ d dlmZmZm	Z	m
Z
 d dl mZ d dlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%  G d de
      Z&e'dk(  rd d	lm(Z(  e(e&       yy)
    N)AnyOptional)memoizememoize_left_recloggerParser)literal_eval)AltCutForcedGatherGroupItem	LookaheadLookaheadOrCut	MetaTupleMetaListNameLeaf	NamedItemNamedItemListNegativeLookaheadOptPlainPositiveLookaheadRepeat0Repeat1RhsRuleRuleListRuleNameGrammar
StringLeafc                   `   e Zd Zedee   fd       Zedee   fd       Zedee   fd       Z	edee
   fd       Zedee   fd       Zedee   fd       Zedee   fd       Zedee   fd	       Zedee   fd
       Zedee   fd       Zedee   fd       Zedee   fd       Zedee   fd       Zedee   fd       Zedee   fd       Z edee!   fd       Z"edee#   fd       Z$edee   fd       Z%edee   fd       Z&edee   fd       Z'edee   fd       Z(dZ)dZ*y)GeneratedParserreturnc                     | j                         }| j                         x}r| j                  d      x}r|S | j                  |       y )N	ENDMARKER)_markgrammarexpect_reset)selfmarkr)   
_endmarkers       ?/root/Python-3.12.4/Tools/peg_generator/pegen/grammar_parser.pystartzGeneratedParser.start,   sH     zz|&W&;;{33Z3ND    c                    | j                         }| j                         x}r| j                         x}rt        ||      S | j	                  |       | j                         x}rt        |g       S | j	                  |       y N)r(   metasrulesr!   r+   )r,   r-   r4   r5   s       r/   r)   zGeneratedParser.grammar9   sw     zz|jjl"U"jjl"U"UU,,Djjl"U"UR))Dr1   c                     | j                         }| j                         x}r| j                         x}r|g|z   S | j                  |       | j                         x}r|gS | j                  |       y r3   )r(   metar4   r+   )r,   r-   r7   r4   s       r/   r4   zGeneratedParser.metasK   p     zz|YY[ T jjl"U"6E>!DYY[ T 6MDr1   c                    | j                         }| j                  d      x}r3| j                         x}r!| j                  d      x}r|j                  d fS | j	                  |       | j                  d      x}rO| j                         x}r=| j                         x}r+| j                  d      x}r|j                  |j                  fS | j	                  |       | j                  d      x}rX| j                         x}rF| j                         x}r4| j                  d      x}r!|j                  t        |j                        fS | j	                  |       y )N@NEWLINE)r(   r*   namestringr+   r	   )r,   r-   literalr<   _newlineabr=   s           r/   r7   zGeneratedParser.meta]   s=    zz|C((W(YY[ T Y//X/]]T++DC((W())+Q))+QY//X/ZZ!**..DC((W(YY[ T {{}$V$Y//X/]]\FOO%EGGDr1   c                     | j                         }| j                         x}r| j                         x}r|g|z   S | j                  |       | j                         x}r|gS | j                  |       y r3   )r(   ruler5   r+   )r,   r-   rC   r5   s       r/   r5   zGeneratedParser.rules   r8   r1   c                 2   | j                         }| j                         x}r| j                         x}fr| j                  d      x}r| j	                         x}r| j                  d      x}rm| j                  d      x}rZ| j                         x}rH| j                  d      x}	r5t        |d   |d   t        |j                  |j                  z         |      S | j                  |       | j                         x}r| j                         x}frs| j                  d      x}r`| j                  d      x}rM| j                  d      x}r:| j                         x}r(| j                  d      x}	rt        |d   |d   ||      S | j                  |       | j                         x}r`| j                         x}frM| j                  d      x}r:| j	                         x}r(| j                  d      x}rt        |d   |d   ||      S | j                  |       y )N:r;   INDENTDEDENTr      memo)	r(   rulenamememoflagr*   alts	more_altsr   r   r+   )
r,   r-   rK   optr>   rM   r?   _indentrN   _dedents
             r/   rC   zGeneratedParser.rule   s
    zz|(X(MMO#S%C((W(YY[ T Y//X/H--W-..**Y*H--W-(A,1dkkIL\L\>\8^hkmmD(X(MMO#S%C((W(Y//X/H--W-..**Y*H--W-(A,1	3PPD(X(MMO#S%C((W(YY[ T Y//X/(A,1cKKDr1   c                    | j                         }| j                         x}r | j                         x}r|j                  |fS | j	                  |       | j                         x}r|j                  d fS | j	                  |       y r3   )r(   r<   
annotationr=   r+   )r,   r-   r<   rS   s       r/   rK   zGeneratedParser.rulename   s|     zz|YY[ T ??,,Z,]]Z11DYY[ T ]]T++Dr1   c                     | j                         }| j                  d      x}r'| j                  d      x}r| j                  d      x}ry| j                  |       y )N(rJ   ))r(   r*   r+   )r,   r-   r>   	literal_1	literal_2s        r/   rL   zGeneratedParser.memoflag   s]     zz|C((W(++f--Y-++c**Y*Dr1   c                 D   | j                         }| j                         x}r>| j                  d      x}r+| j                         x}rt	        |g|j                  z         S | j                  |       | j                         x}rt	        |g      S | j                  |       y )N|)r(   altr*   rM   r   r+   )r,   r-   r[   r>   rM   s        r/   rM   zGeneratedParser.alts   s     zz|HHJSC((W(YY[ T #,..DHHJS#= Dr1   c                    | j                         }| j                  d      x}rY| j                         x}rG| j                  d      x}r4| j                         x}r"t	        |j                  |j                  z         S | j                  |       | j                  d      x}r:| j                         x}r(| j                  d      x}rt	        |j                        S | j                  |       y )NrZ   r;   )r(   r*   rM   rN   r   r+   )r,   r-   r>   rM   r?   rN   s         r/   rN   zGeneratedParser.more_alts   s     zz|C((W(YY[ T Y//X/..**Y*y'7'7799DC((W(YY[ T Y//X/&&Dr1   c           	         | j                         }| j                         x}rI| j                  d      x}r6| j                         x}r$t	        |t        d t        d            gz   |      S | j                  |       | j                         x}r7| j                  d      x}r$t	        |t        d t        d            gz   d       S | j                  |       | j                         x}r| j                         x}rt	        ||      S | j                  |       | j                         x}rt	        |d       S | j                  |       y )N$r'   )action)r(   itemsr*   r_   r
   r   r   r+   )r,   r-   r`   r>   r_   s        r/   r[   zGeneratedParser.alt  s.    zz|jjl"U"C((W({{}$V$)dX5M"O!PP\bddDjjl"U"C((W()dX5M"O!PP\`bbDjjl"U"{{}$V$&22Djjl"U"$00Dr1   c                     | j                         }| j                         x}r| j                         x}r|g|z   S | j                  |       | j                         x}r|gS | j                  |       y r3   )r(   
named_itemr`   r+   )r,   r-   rb   r`   s       r/   r`   zGeneratedParser.items<  st     zz|??,,Z,jjl"U"<%''D??,,Z,<Dr1   c                     | j                         }d}| j                         x}rR| j                         x}r@| j                  d      x}r-dx}r)| j	                         x}rt        |j                  ||      S | j                  |       |ry d}| j                         x}r?| j                  d      x}r,dx}r(| j	                         x}rt        |j                  |      S | j                  |       |ry | j	                         x}rt        d |      S | j                  |       | j                         x}rt        d |      S | j                  |       | j                         x}rt        d |      S | j                  |       y )NF=T)
r(   r<   rS   r*   itemr   r=   r+   forced_atom	lookahead)	r,   r-   cutr<   rS   r>   re   forcedits	            r/   rb   zGeneratedParser.named_itemN  st    zz|YY[ T ??,,Z,C((W([S[YY[ T t}}tjBBDtYY[ T C((W([S[YY[ T t}}t55DtYY[ T td,,D''))V)tf..D>>##R#tb**Dr1   c                     | j                         }d}| j                  d      x}r4| j                  d      x}r!dx}r| j                         x}rt        |      S | j	                  |       |ry y )NF&T)r(   r*   atomr   r+   )r,   r-   rh   r>   rW   rm   s         r/   rf   zGeneratedParser.forced_atom  st     zz|C((W(++c**Y*[S[YY[ T D?"Dtr1   c                    | j                         }d}| j                  d      x}r!dx}r| j                         x}rt        |      S | j	                  |       |ry d}| j                  d      x}r!dx}r| j                         x}rt        |      S | j	                  |       |ry | j                  d      x}r
t               S | j	                  |       y )NFrl   T!~)r(   r*   rm   r   r+   r   r   )r,   r-   rh   r>   rm   s        r/   rg   zGeneratedParser.lookahead  s     zz|C((W([S[YY[ T $t--DtC((W([S[YY[ T $t--DtC((W(7NDr1   c                 |   | j                         }d}| j                  d      x}r4dx}r0| j                         x}r| j                  d      x}rt        |      S | j	                  |       |ry | j                         x}r| j                  d      x}rt        |      S | j	                  |       | j                         x}r| j                  d      x}rt        |      S | j	                  |       | j                         x}r| j                  d      x}rt        |      S | j	                  |       | j                         x}rD| j                  d      x}r1| j                         x}r| j                  d      x}rt        ||      S | j	                  |       | j                         x}r|S | j	                  |       y )	NF[T]?*+.)	r(   r*   rM   r   r+   rm   r   r   r   )	r,   r-   rh   r>   rM   rW   rm   sepnodes	            r/   re   zGeneratedParser.item  s    zz|C((W([S[YY[ T ++c**Y*<DtYY[ T C((W(<DYY[ T C((W(T##DYY[ T C((W(T##DIIKSC((W(YY[ T ++c**Y*C$((DYY[ T KDr1   c                    | j                         }d}| j                  d      x}r4dx}r0| j                         x}r| j                  d      x}rt        |      S | j	                  |       |ry | j                         x}rt        |j                        S | j	                  |       | j                         x}rt        |j                        S | j	                  |       y )NFrU   TrV   )	r(   r*   rM   r   r+   r<   r   r=   r"   )r,   r-   rh   r>   rM   rW   r<   r=   s           r/   rm   zGeneratedParser.atom  s     zz|C((W([S[YY[ T ++c**Y*4>!DtYY[ T dmm--D{{}$V$11Dr1   c                     | j                         }d}| j                  d      x}r+dx}r'| j                         x}r| j                  d      x}r|S | j                  |       |ry y )NF{T}r(   r*   target_atomsr+   r,   r-   rh   r>   r   rW   s         r/   r_   zGeneratedParser.action  s     zz|C((W([S[!..00\0++c**Y*Dtr1   c                     | j                         }d}| j                  d      x}r+dx}r'| j                         x}r| j                  d      x}r|S | j                  |       |ry y )NFrr   Trs   r~   r   s         r/   rS   zGeneratedParser.annotation  r   r1   c                     | j                         }| j                         x}r| j                         x}r|dz   |z   S | j                  |       | j                         x}r|S | j                  |       y )N )r(   target_atomr   r+   )r,   r-   r   r   s       r/   r   zGeneratedParser.target_atoms.  s|     zz| ,,..[.!..00\0$|33D ,,..[.Dr1   c                    | j                         }d}| j                  d      x}r6dx}r2| j                         x}fr| j                  d      x}rd|xs dz   dz   S | j                  |       |ry d}| j                  d      x}r6dx}r2| j                         x}fr| j                  d      x}rd|xs dz   dz   S | j                  |       |ry | j	                         x}r"| j                  d      x}r|j
                  dz   S | j                  |       | j	                         x}r|j
                  S | j                  |       | j                         x}r|j
                  S | j                  |       | j                         x}r|j
                  S | j                  |       | j                  d	      x}ry	| j                  |       | j                  d
      x}ry
| j                  |       | j                  | j                  d      r:| j                  | j                  d      r| j                         x}	r|	j
                  S | j                  |       y )NFr|   Tr}    rr   rs   ru   rt   rE   )	r(   r*   r   r+   r<   r=   numbernegative_lookaheadop)
r,   r-   rh   r>   atomsrW   r<   r   r=   r   s
             r/   r   zGeneratedParser.target_atom@  s8    zz|C((W([S[''))U+++c**Y*5;B(3..DtC((W([S[''))U+++c**Y*5;B(3..DtYY[ T C((W(==3&&DYY[ T == D{{}$V$??"D{{}$V$??"DC((W(DC((W(D##DKK5##DKK5779_R_;;Dr1    rI   N)+__name__
__module____qualname__r   r   r!   r0   r)   r   r4   r   r7   r   r5   r   rC   r    rK   strrL   r   rM   rN   r
   r[   r   r`   r   rb   r   rf   r   rg   r   re   r   rm   r_   rS   r   r   KEYWORDSSOFT_KEYWORDSr   r1   r/   r$   r$   *   s   
x( 
 
 '*  " x)  " "hy) " "H x)  " 4htn 4 4l (8,  " (3-   hsm  & 8C=  2 Xc]  B x.  " .HY/ . .` Xf-  $ 8N3  @ 5htn 5 5n huo  8   $ HSM  $ hsm  " FXc] F FP HMr1   r$   __main__)simple_parser_main))astsystokenizetypingr   r   pegen.parserr   r   r   r   r	   pegen.grammarr
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r$   r   r   r   r1   r/   <module>r      sh     
    B B       :`	f `	F z/' r1   