+
    Bi                        ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIHtH	t	 ^ RI
HtHtHtHtHt ]P                   ! R4       ]P"                  ! R4      ;_uu_ 4        ^ RIHt ^ RIHtHtHt ^ RIHtHtHt ^ R	IHt ^ R
IH t  ^ RI!H"t"H#t# ^ RI$H%t% RRR4        ! R R]PL                  4      t' ! R R4      t( ! R R]PL                  4      t)R#   + '       g   i     LF; i)    N)
test_tools)DictAny)	TokenInfoNAMENEWLINENUMBEROPpeg_generator)GeneratedParser)parse_stringgenerate_parsermake_parser)GrammarVisitorGrammarErrorGrammar)ASTGrammarPrinter)Parser)compute_nullablescompute_left_recursives)PythonParserGeneratorc                     a  ] tR t^t o V 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R	 lR
 ltV 3R lR lt	V 3R lR lt
V 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR  ltV 3R! lR" ltV 3R# lR$ ltV 3R% lR& ltV 3R' lR( ltV 3R) lR* ltV 3R+ lR, ltV 3R- lR. ltV 3R/ lR0 ltV 3R1 lR2 ltV 3R3 lR4 ltV 3R5 lR6 ltV 3R7 lR8 ltV 3R9 lR: lt V 3R; lR< lt!V 3R= lR> lt"V 3R? lR@ lt#V 3RA lRB lt$V 3RC lRD lt%V 3RE lRF lt&V 3RG lRH lt'V 3RI lRJ lt(V 3RK lRL lt)V 3RM lRN lt*V 3RO lRP lt+V 3RQ lRR lt,RSt-V t.RT# )U	TestPegenc                   < V ^8  d   QhRR/#    returnN )format__classdict__s   "9/usr/lib/python3.14/test/test_peg_generator/test_pegen.py__annotate__TestPegen.__annotate__   s     = =D =    c                   R pRp\        V\        4      pVP                  pV P                  \	        V4      \
        P                  ! V4      P                  4       4       V P                  \	        VR,          4      R4       V P                  \	        VR,          4      R4       RpV P                  \        VR,          4      V4       R# )	zl
        start: sum NEWLINE
        sum: t1=term '+' t2=term { action } | term
        term: NUMBER
        [
        start: sum NEWLINE
        sum: term '+' term | term
        term: NUMBER
        startstart: sum NEWLINEsumsum: term '+' term | termzERule('term', None, Rhs([Alt([NamedItem(None, NameLeaf('NUMBER'))])]))termN)	r   GrammarParserrulesassertEqualstrtextwrapdedentstriprepr)selfgrammar_sourceexpectedgrammarr-   expected_reprs   &     r!   test_parse_grammarTestPegen.test_parse_grammar   s    

 (FWxx'@'F'F'HIU7^,.BCU5\*,GHS 	 	eFm,m<r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#   -   s     8 8T 8r$   c                    R pV P                  \        R4      ;_uu_ 4        \        V\        4       RRR4       R#   + '       g   i     R# ; i)ze
        start: the_rule NEWLINE
        the_rule: 'b' NEWLINE
        the_rule: 'a' NEWLINE
        zRepeated rule 'the_rule'N)assertRaisesRegexr   r   r,   )r4   r5   s   & r!   test_repeated_rulesTestPegen.test_repeated_rules-   s9    
 ##L2LMM7 NMMMs	   <A	c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#   6   s     Y YD Yr$   c                    R pRp\        V\        4      pV P                  \        VP                  R,          4      \
        P                  ! V4      P                  4       4       R# )zt
        start: zero | one | one zero | one one | one zero zero | one zero one | one one zero | one one one
        z
        start:
            | zero
            | one
            | one zero
            | one one
            | one zero zero
            | one zero one
            | one one zero
            | one one one
        r'   N)r   r,   r.   r/   r-   r0   r1   r2   )r4   r5   r6   r7   s   &   r!   test_long_rule_strTestPegen.test_long_rule_str6   sN    
 (FW]]734hooh6O6U6U6WXr$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#   H   s     
 
$ 
r$   c                
   R p\        V\        4      P                  pV P                  \	        VR,          4      R4       V P                  \	        VR,          4      R4       V P                  \        VR,          4      R4       R# )z{
        start[int]: sum NEWLINE
        sum[int]: t1=term '+' t2=term { action } | term
        term[int]: NUMBER
        r'   r(   r)   r*   r+   zFRule('term', 'int', Rhs([Alt([NamedItem(None, NameLeaf('NUMBER'))])]))N)r   r,   r-   r.   r/   r3   )r4   r7   r-   s   &  r!   test_typed_rulesTestPegen.test_typed_rulesH   sn    
 Wm4::U7^,.BCU5\*,GHvT	
r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#   W   s     
 
T 
r$   c                   R p\        V\        4      P                  pV P                  \	        VR,          4      R4       V P                  \        VR,          4      R4       V P                  \	        VR,          4      R4       \        V4      p\        RV4      p\        RV4      pV P                  V\        \        RRRRR	7      \        \        R
RRRR	7      .\        \        RRRRR	7      .4       R# )A
        start: ','.thing+ NEWLINE
        thing: NUMBER
        r'   zstart: ','.thing+ NEWLINEzXRule('start', None, Rhs([Alt([NamedItem(None, Gather(StringLeaf("','"), NameLeaf('thing'thingzthing: NUMBER42
z1, 2
1stringr'   endline2
N   r   rU   rU   rU      rU      rU      )r   r,   r-   r.   r/   assertStartsWithr3   r   r   r	   r   )r4   r7   r-   parser_classnodes   &    r!   test_gatherTestPegen.test_gatherW   s     Wm4::U7^,.IJd5>2h	
 	U7^,o>"7+FL1Hl3 s&f8 s&f8	 DF	
r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#   v   s     
 
4 
r$   c                    R p\        V4      p\        RV4      pV P                  V\        \        RRRRR7      \        \
        RRRRR7      .4       R# )	r&   rL   42rN   rS   NrT   rU   r   rW   r   r   r.   r   r	   r   r4   r7   r^   r_   s   &   r!   test_expr_grammarTestPegen.test_expr_grammarv   sW    
 #7+FL1&VfU'$f&vV	
r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#      s     '
 '
 '
r$   c                   R p\        V4      p\        RV4      pV P                  V\        \        RR	R
RR7      \        \
        RRRRR7      \        \        RRRRR7      ..\        \        RRRRR7      .4       \        RV4      pV P                  V\        \        RR	R
RR7      R.\        \        RR
RRR7      .4       R# )zW
        start: sum NEWLINE
        sum: term ('+' term)?
        term: NUMBER
        1 + 2
rM   rN   +rR   rS   1
NrT   rV   re   rW   rY   r[   rU      r   r   r.   r   r	   r
   r   rg   s   &   r!   test_optional_operator TestPegen.test_optional_operator       
 #7+I|4 s&f9 "s&f9 ""3f&y		 DF	
* E<0 fSFQVW '$f&uU		
r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#      s     
 
t 
r$   c                \   R p\        V4      p\        RV4      pV P                  V\        \        RRR	RR7      \        \
        RR	R
RR7      .\        \        RR
RRR7      .4       \        RV4      pV P                  V\        \        RRR	RR7      R.\        \        RR	R
RR7      .4       R# )zQ
        start: sum NEWLINE
        sum: term '+' ?
        term: NUMBER
        z1+
rM   rN   rm   rS   rn   NrT   rV   re   rW   rq   rg   s   &   r!   test_optional_literalTestPegen.test_optional_literal   s    
 #7+FL1 s&f6 bFVT	 '$f&vV	
 E<0 fSFQVW '$f&uU		
r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#      s     '
 '
D '
r$   c                   R p\        V4      p\        RV4      pV P                  V\        \        RR	R
RR7      \        \
        RRRRR7      \        \        RRRRR7      ..\        \        RRRRR7      .4       \        RV4      pV P                  V\        \        RR	R
RR7      R.\        \        RR
RRR7      .4       R# )zV
        start: sum NEWLINE
        sum: term ['+' term]
        term: NUMBER
        rl   rM   rN   rm   rR   rS   rn   NrT   rV   re   rW   rY   r[   ro   rq   rg   s   &   r!   test_alt_optional_operator$TestPegen.test_alt_optional_operator   rt   r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#      s      
  
d  
r$   c                   R p\        V4      p\        RV4      pV P                  V\        \        RR	R
RR7      \        \        RRRRR7      \        \        RRRRR7      .\        \
        RRRRR7      .4       \        RV4      pV P                  V\        \        RR	R
RR7      . \        \
        RR
RRR7      .4       R# )zC
        start: thing thing* NEWLINE
        thing: NUMBER
        1 2 3
rM   rN   rR   3rS   rn   NrT   rV   re   rW   rY   r[   ro   rf   rg   s   &   r!   test_repeat_0_simpleTestPegen.test_repeat_0_simple   s     #7+I|4&FYWs&f9 s&f9	 DF	
" E<0&FUS'$f&uU	
r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#     s     +
 +
t +
r$   c                F   R p\        V4      p\        RV4      pV P                  V\        \        RR	R
RR7      \        \
        RRRRR7      \        \        RRRRR7      .\        \
        RRRRR7      \        \        RRRRR7      ..\        \        RRRRR7      .4       R# )zF
        start: term ('+' term)* NEWLINE
        term: NUMBER
        
1 + 2 + 3
rM   rN   rm   rR   r   rS   NrT   rV   re   rW   rY   r[   ro   rU      rU      rU   	   rU   
   rq   rg   s   &   r!   test_repeat_0_complexTestPegen.test_repeat_0_complex  s     #7+M<83f&}
 "s&f= ""#&"( &!.	 "s&f= ""#&"( &!.	4 DG-=!$	
r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#   G  s     . .d .r$   c                   R p\        V4      p\        RV4      pV P                  V\        \        RR	R
RR7      \        \        RRRRR7      \        \        RRRRR7      .\        \
        RRRRR7      .4       V P                  \        4      ;_uu_ 4        \        RV4       RRR4       R#   + '       g   i     R# ; i)zC
        start: thing thing+ NEWLINE
        thing: NUMBER
        r   rM   rN   rR   r   rS   rn   NrT   rV   re   rW   rY   r[   ro   )r   r   r.   r   r	   r   assertRaisesSyntaxErrorrg   s   &   r!   test_repeat_1_simpleTestPegen.test_repeat_1_simpleG  s     #7+I|4&FYWs&f9 s&f9	 DF	
" {++- ,+++s   B--B>	c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#   b  s     -. -.t -.r$   c                   R p\        V4      p\        RV4      pV P                  V\        \        RR
RRR7      \        \
        RRRRR7      \        \        RRRRR7      .\        \
        RRRRR7      \        \        RRRRR7      ..\        \        RRRRR7      .4       V P                  \        4      ;_uu_ 4        \        RV4       R	R	R	4       R	#   + '       g   i     R	# ; i)zF
        start: term ('+' term)+ NEWLINE
        term: NUMBER
        r   rM   rN   rm   rR   r   rS   rn   NrT   rV   re   rW   rY   r[   ro   r   r   r   r   )	r   r   r.   r   r	   r
   r   r   r   rg   s   &   r!   test_repeat_1_complexTestPegen.test_repeat_1_complexb  s     #7+M<83f&}
 "s&f= ""#&"( &!.	 "s&f= ""#&"( &!.	4 DG-=!$	
J {++- ,+++s   >CC&	c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#     s     
 
T 
r$   c                    R p\        V4      p\        RV4      pV P                  V\        \        RRR	RR7      \        \        RR
RRR7      \        \        RRRRR7      .\        \
        RRRRR7      .4       R# )rJ   z1, 2, 3
rM   rN   rR   r   rS   NrT   rV   rW   rY   ro   r   r   rf   rg   s   &   r!   test_repeat_with_sep_simple%TestPegen.test_repeat_with_sep_simple  s     #7+K6 s&f; s&f; s&f;
 DF	
r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#     s     5
 5
T 5
r$   c                   R p\        V\        4      p\        V4      pVP                  pV P	                  VR,          P
                  4       V P                  VR,          P
                  4       V P	                  VR,          P
                  4       V P	                  VR,          P
                  4       V P	                  VR,          P
                  4       V P	                  VR,          P
                  4       \        RV4      pV P                  V\        \        RRRRR	7      \        \        R
RRRR	7      \        \        RRRRR	7      .\        \        R
RRRR	7      \        \        RRRRR	7      .\        \        RRRRR	7      .4       R# )z
        start: expr NEWLINE
        expr: ('-' term | expr '+' term | term)
        term: NUMBER
        foo: NAME+
        bar: NAME*
        baz: NAME?
        r'   exprr+   foobarbazr   rM   rN   rm   rR   r   rS   NrT   rV   re   rW   rY   r[   ro   r   r   r   r   )r   r,   r   r-   assertFalseleft_recursive
assertTruer.   r   r	   r
   r   )r4   r5   r7   r^   r-   r_   s   &     r!   test_left_recursiveTestPegen.test_left_recursive  sj    (F&w/w667f445v556u445u445u445M<8 ""#&"( &!. "s&f= ""#&"( &!.& 3f&} s&f=/6 DG-9"	
r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#     s     # #$ #r$   c                    R p\        V4      p\        RV4      p\        VRR4      p\        V4      pV P	                  VR4       R# )a  
        start: expr NEWLINE? $ { ast.Expression(expr) }
        expr: ( expr '+' term { ast.BinOp(expr, ast.Add(), term, lineno=expr.lineno, col_offset=expr.col_offset, end_lineno=term.end_lineno, end_col_offset=term.end_col_offset) }
            | expr '-' term { ast.BinOp(expr, ast.Sub(), term, lineno=expr.lineno, col_offset=expr.col_offset, end_lineno=term.end_lineno, end_col_offset=term.end_col_offset) }
            | term { term }
            )
        term: ( l=term '*' r=factor { ast.BinOp(l, ast.Mult(), r, lineno=l.lineno, col_offset=l.col_offset, end_lineno=r.end_lineno, end_col_offset=r.end_col_offset) }
            | l=term '/' r=factor { ast.BinOp(l, ast.Div(), r, lineno=l.lineno, col_offset=l.col_offset, end_lineno=r.end_lineno, end_col_offset=r.end_col_offset) }
            | factor { factor }
            )
        factor: ( '(' expr ')' { expr }
                | atom { atom }
                )
        atom: ( n=NAME { ast.Name(id=n.string, ctx=ast.Load(), lineno=n.start[0], col_offset=n.start[1], end_lineno=n.end[0], end_col_offset=n.end[1]) }
            | n=NUMBER { ast.Constant(value=ast.literal_eval(n.string), lineno=n.start[0], col_offset=n.start[1], end_lineno=n.end[0], end_col_offset=n.end[1]) }
            )
        z(1 + 2*3 + 5)/(6 - 2)
 evalg      @N)r   r   compiler   r.   )r4   r7   r^   r_   codevals   &     r!   test_python_exprTestPegen.test_python_expr  sI    " #7+5|DtR(4jc"r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#     s     5 5 5r$   c                x    R p\        V4      p\        RV4      pV P                  VP                  4       R4       R# )zD
        start: n=NAME NEWLINE? $ { f"name -> {n.string}" }
        az
name ->  aN)r   r   r.   r2   rg   s   &   r!   test_f_string_in_action!TestPegen.test_f_string_in_action  s7     #7+C.|4r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#     s     	0 	0t 	0r$   c                    R p\        V\        4      pVP                  p\        V4      pV P	                  VR,          V4       V P                  VR,          V4       R# )z>
        start: sign NUMBER
        sign: ['-' | '+']
        r'   signN)r   r,   r-   r   assertNotInassertInr4   r5   r7   r-   	nullabless   &    r!   test_nullableTestPegen.test_nullable  sP     (F%e,	w3eFmY/r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#     s     7 7d 7r$   c                Z   R p\        V\        4      pVP                  p\        V4      p\	        V4       V P                  VR,          V4       V P                  VR,          V4       V P                  VR,          P                  4       V P                  VR,          P                  4       R# )z@
        start: NUMBER | sign start
        sign: ['-']
        r'   r   N)
r   r,   r-   r   r   r   r   r   r   r   r   s   &    r!   test_advanced_left_recursive&TestPegen.test_advanced_left_recursive  s     (F%e,	&w3eFmY/g556v556r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#     s     Z
 Z
d Z
r$   c                   R p\        V\        4      p\        P                  ! 4       p\	        W#4      pVP
                  pV P                  VR,          P                  4       V P                  VR,          P                  4       V P                  VR,          P                  4       VP                  R4       / p\        VP                  4       V4       VR,          p\        RV4      pV P                  V\        \        RRRRR7      \        \        R	RRRR7      .\        \        R
RRRR7      .\        \        R	RRRR7      .\        \        RRRRR7      .4       \        RV4      pV P                  V\        \        RRRRR7      \        \        R
RRRR7      .\        \        R	RRRR7      .\        \        RRRRR7      .4       R# )zV
        start: foo 'E'
        foo: bar 'A' | 'B'
        bar: foo 'C' | 'D'
        r'   r   r   <string>r   z	D A C A ED)typerO   r'   rP   rQ   ACEzB C A EBNrT   rV   re   rW   rY   r[   ro   r   r   r   )r   r,   ioStringIOr   r-   r   r   r   generateexecgetvaluer.   r   r   )	r4   r5   r7   outgenrr-   nsr^   r_   s	   &        r!   test_mutually_left_recursive&TestPegen.test_mutually_left_recursive  s   
 (Fkkm$W2w667e334e334j!S\\^R %'(9%:K6
 &%)'*&,$*%0 &%)'*&,$*%0  "!%#&"( &!,#2 !"$"(5!D cV+G&)	
T I|4 "!%#&"( &!* "!%#&"( &!*  !#Vi#* cV)-	
r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#   x  s     2 2D 2r$   c                b   R p\        V\        4      p\        P                  ! 4       p\	        W#4      pVP                  R4       / p\        VP                  4       V4       VR,          pV P                  \        4      ;_uu_ 4        \        RV4       RRR4       R#   + '       g   i     R# ; i)zf
        start: target '='
        target: maybe '+' | NAME
        maybe: maybe '-' | target
        r   r   zx - + =N)
r   r,   r   r   r   r   r   r   r   r   )r4   r5   r7   r   r   r   r^   s   &      r!   "test_nasty_mutually_left_recursive,TestPegen.test_nasty_mutually_left_recursivex  s    
 (Fkkm$W2j!S\\^R +,{++L1 ,+++s   BB.	c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#     s     1
 1
 1
r$   c                .   R p\        V4      p\        RV4      pRV n        V P                  V\	        \
        RRR	RR7      \	        \        RR
RRR7      \	        \        RRRRR7      \	        \        RRRRR7      \	        \        RRRRR7      ....4       R# )z
        start: (expr_stmt | assign_stmt) &'.'
        expr_stmt: !(target '=') expr
        assign_stmt: target '=' expr
        expr: term ('+' term)*
        target: NAME
        term: NUMBER
        zfoo = 12 + 12 .Nr   rN   =12rm   rT   rW   rY   r[   ro   r   r   r   )rU      )rU      )r   r   maxDiffr.   r   r   r
   r	   rg   s   &   r!   test_lookaheadTestPegen.test_lookahead  s     #7+-|<f&GX s&fCT #$". & "'*&,$+%6 & &'+&-$+%6"%	
r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#     s     ! !D !r$   c                    R pV P                  \        4      ;_uu_ 4        \        V4       RRR4       R#   + '       g   i     R# ; i)z&
        start: foo=!'x' NAME
        N)r   r   r   r4   r7   s   & r!   test_named_lookahead_error$TestPegen.test_named_lookahead_error  s3     {++  ,+++	   6A	c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#           4 r$   c                     R p\        V4       R# )zA
        start: attr | NAME
        attr: start '.' NAME
        Nr   r   s   & r!   test_start_leaderTestPegen.test_start_leader  s    
 	Gr$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#     r   r$   c                     R p\        V4       R# )z 
        start: [NAME*]
        Nr   r   s   & r!   test_opt_sequenceTestPegen.test_opt_sequence  s    
 	Gr$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#     s     	I 	I 	Ir$   c                    R pV P                  \        4      ;_uu_ 4       p\        V4       V P                  R\	        VP
                  P                  4      9   4       RRR4       R#   + '       g   i     R# ; i)z
        start: foo
        foo: bar '+' | baz '+' | '+'
        bar: baz '-' | foo '-' | '-'
        baz: foo '*' | bar '*' | '*'
        z	no leaderN)r   
ValueErrorr   r   r/   	exceptionvalue)r4   r7   errinfos   &  r!   test_left_recursion_too_complex)TestPegen.test_left_recursion_too_complex  sW     z**g OOK3w/@/@/F/F+GGH +***s   =A''A8	c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#     s     
 
$ 
r$   c                    R p\        V4      p\        RV4      pV P                  V\        \        RRRRR7      \        \
        RRR	RR7      \        \        RR	R
RR7      .4       R# )z<
        start: '(' ~ expr ')'
        expr: NUMBER
        z(1)(rN   rM   )NrT   rV   re   rW   )r   r   r.   r   r
   r	   rg   s   &   r!   test_cutTestPegen.test_cut  sg     #7+E<0"SFO&FUS"SFO	
r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#     s     0 0 0r$   c                    R pV P                  \        4      ;_uu_ 4        \        V4      pRRR4       R#   + '       g   i     R# ; i)z<
        start: foo ENDMARKER
        foo: bar NAME
        Nr   r   r   r4   r7   r^   s   &  r!   test_dangling_reference!TestPegen.test_dangling_reference  5     |,,&w/L -,,,r   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#     s     0 0$ 0r$   c                    R pV P                  \        4      ;_uu_ 4        \        V4      pRRR4       R#   + '       g   i     R# ; i)z/
        start: foo
        foo: NAMEE
        Nr  r  s   &  r!   test_bad_token_reference"TestPegen.test_bad_token_reference  r  r   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#     s     0 0D 0r$   c                    R pV P                  \        4      ;_uu_ 4        \        V4      pRRR4       R#   + '       g   i     R# ; i)z
        foo: NAME
        Nr  r  s   &  r!   test_missing_startTestPegen.test_missing_start  s5     |,,&w/L -,,,r   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#     s     0 0 0r$   c                    R pV P                  \        R4      ;_uu_ 4        \        V4      pRRR4       R#   + '       g   i     R# ; i)z<
        start: _a b
        _a: 'a'
        b: 'b'
        z"cannot start with underscore: '_a'Nr=   r   r   r  s   &  r!   test_invalid_rule_name TestPegen.test_invalid_rule_name  9    
 ##L2VWW&w/L XWWW	   7A	c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#     s     0 0D 0r$   c                    R pV P                  \        R4      ;_uu_ 4        \        V4      pRRR4       R#   + '       g   i     R# ; i)z=
        start: a b
        a: _x='a'
        b: 'b'
        "cannot start with underscore: '_x'Nr  r  s   &  r!   test_invalid_variable_name$TestPegen.test_invalid_variable_name  r  r  c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#     s     0 0T 0r$   c                    R pV P                  \        R4      ;_uu_ 4        \        V4      pRRR4       R#   + '       g   i     R# ; i)zK
        start: a b
        a: (_x='a' | 'b') | 'c'
        b: 'b'
        r  Nr  r  s   &  r!   +test_invalid_variable_name_in_temporal_rule5TestPegen.test_invalid_variable_name_in_temporal_rule  r  r  c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#   (  s     1 14 1r$   c                z   R p\        V4      pV P                  \        RV4      ^4       V P                  \        RV4      R4       V P                  \        RV4      R4       \        RV4      R8X  g   Q hV P                  \        4      ;_uu_ 4        \        RV4       R	R	R	4       R	#   + '       g   i     R	# ; i)
z
        start:
            | "number" n=NUMBER { eval(n.string) }
            | "string" n=STRING { n.string }
            | SOFT_KEYWORD l=NAME n=(NUMBER | NAME | STRING) { l.string + " = " + n.string }
        znumber 1z
string 'b'z'b'znumber test 1ztest = 1zstring test 'b'z
test = 'b'ztest 1N)r   r.   r   r   r   r  s   &  r!   test_soft_keywordTestPegen.test_soft_keyword(  s     #7+j,?ClLA5I,7	
 *L9\I	
I{++<0 ,+++s   B))B:	c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#   ;  s     	8 	8T 	8r$   c                *   R p\        V4      pV P                  \        RV4      4       V P                  \        4      ;_uu_ 4       p\        RV4       RRR4       V P                  R\        XP                  4      4       R#   + '       g   i     L7; i)z*
        start: NAME &&':' | NAME
        number :r   Nzexpected ':')r   r   r   r   r   r   r/   r   r4   r7   r^   es   &   r!   test_forcedTestPegen.test_forced;  sl     #7+Z>?{++ql+ , 	nc!++&67 ,+s   BB	c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#   F  s     	C 	C 	Cr$   c                p   R p\        V4      pV P                  \        RV4      4       V P                  \        RV4      4       V P                  \        4      ;_uu_ 4       p\        RV4       RRR4       V P                  RXP                  P                  ^ ,          4       R#   + '       g   i     L?; i)z2
        start: NAME &&(':' | ';') | NAME
        r'  znumber ;r   Nzexpected (':' | ';'))r   r   r   r   r   r   r   argsr(  s   &   r!   test_forced_with_group TestPegen.test_forced_with_groupF  s     #7+Z>?Z>?{++ql+ ,,akk.>.>q.AB ,+s   !B%%B5	c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#   Q  s     
8 
84 
8r$   c                    R p\        V\        4      p\        P                  ! 4       p\	        W#RR7      pVP                  R4       V P                  RVP                  4       4       R# )z-
        start: NAME { UNREACHABLE }
        This is a testunreachable_formattingr   Nr   r,   r   r   r   r   r   r   r4   sourcer7   r   r   s   &    r!   test_unreachable_explicit#TestPegen.test_unreachable_explicitQ  sU     v}5kkm$1A
 	j!&7r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#   ]       8 8D 8r$   c                    R p\        V\        4      p\        P                  ! 4       p\	        W#RR7      pVP                  R4       V P                  RVP                  4       4       R# )zT
        start: NAME | invalid_input
        invalid_input: NUMBER { None }
        r3  r4  r   Nr6  r7  s   &    r!   test_unreachable_implicit1$TestPegen.test_unreachable_implicit1]  U     v}5kkm$1A
 	j!&7r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#   j  r<  r$   c                    R p\        V\        4      p\        P                  ! 4       p\	        W#RR7      pVP                  R4       V P                  RVP                  4       4       R# )z\
        start: NAME | '(' invalid_input ')'
        invalid_input: NUMBER { None }
        r3  r4  r   Nr6  r7  s   &    r!   test_unreachable_implicit2$TestPegen.test_unreachable_implicit2j  r@  r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#   w  s     ; ;D ;r$   c                    R p\        V\        4      p\        P                  ! 4       p\	        W#RR7      pVP                  R4       V P                  RVP                  4       4       R# )zT
        start: NAME | invalid_input { None }
        invalid_input: NUMBER
        r3  r4  r   N)r   r,   r   r   r   r   r   r   r7  s   &    r!   test_unreachable_implicit3$TestPegen.test_unreachable_implicit3w  sW     v}5kkm$1A
 	j!)3<<>:r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r#     s       r$   c                   R p\        V4      pRp\        P                  ! \        W24      P                  RR7      p\        P                  ! \        P
                  ! V4      P                  ^ ,          P                  RR7      P                  RR4      pRP                  \        P                  ! VP                  R4      VP                  R4      RR4      4      pV P                  V4       R	# )
a  
        start: t=term NEWLINE? $ { ast.Expression(t) }
        term:
            | l=term '*' r=factor { ast.BinOp(l, ast.Mult(), r, LOCATIONS) }
            | l=term '/' r=factor { ast.BinOp(l, ast.Div(), r, LOCATIONS) }
            | factor
        factor:
            | (
                n=NAME { ast.Name(id=n.string, ctx=ast.Load(), LOCATIONS) } |
                n=NUMBER { ast.Constant(value=ast.literal_eval(n.string), LOCATIONS) }
            )
        z2*3
T)include_attributesz kind=None,r   rS   cpythonzpython-pegenN)r   astdumpr   bodyparser   replacejoindifflibunified_diffsplitr   )r4   r7   r^   r8  opdiffs   &      r!   &test_locations_in_alt_action_and_group0TestPegen.test_locations_in_alt_action_and_group  s     #7+HH\&7<<QUVHHSYYv&++A.44NVV2
 yy  qwwt}i

 	r$   )r   N)/__name__
__module____qualname____firstlineno__r9   r>   rB   rF   r`   rh   rr   rw   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/  r9  r>  rC  rG  rY  __static_attributes____classdictcell__r    s   @r!   r   r      s    = =,8 8Y Y$
 

 
>
 
 '
 '
R
 
@'
 '
R 
  
D+
 +
Z. .6-. -.^
 
65
 5
n# #05 5	0 	07 7Z
 Z
x2 221
 1
f! !  	I 	I
 
 0 00 00 00 00 00 01 1&	8 	8	C 	C
8 
88 88 8; ; r$   r   c                      a  ] tR tRt o  ! R R]4      tV 3R lR ltV 3R lR ltV 3R lR	 ltV 3R
 lR lt	V 3R lR lt
RtV tR# )TestGrammarVisitori  c                   P   a a ] tR tRt oV3R lR ltV3R lV 3R lltRtVtV ;t# )TestGrammarVisitor.Visitori  c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   'TestGrammarVisitor.Visitor.__annotate__  s     	 	d 	r$   c                    ^ V n         R# )r   Nn_nodes)r4   s   &r!   __init__#TestGrammarVisitor.Visitor.__init__  s	    DLr$   c                0   < V ^8  d   QhRS[ RS[ RS[ RR/# )r   r_   r.  kwargsr   N)r   )r   r    s   "r!   r"   rg    s)     	1 	1c 	1# 	1 	1 	1r$   c                b   < V ;P                   ^,          un         \        SV `  ! V.VO5/ VB  R# )rU   N)rj  supervisit)r4   r_   r.  rn  	__class__s   &&*,r!   rq   TestGrammarVisitor.Visitor.visit  s'    LLALGM$000r$   ri  )	r[  r\  r]  r^  rk  rq  r_  r`  __classcell__)rr  r    s   @@r!   Visitorre    s     	 		1 	1 	1r$   ru  c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   TestGrammarVisitor.__annotate__  s     	- 	-D 	-r$   c                    R p\        V\        4      pV P                  4       pVP                  V4       V P	                  VP
                  ^4       R# )z
        start: 'a'
        Nr   r,   ru  rq  r.   rj  r4   r7   r-   visitors   &   r!   test_parse_trivial_grammar-TestGrammarVisitor.test_parse_trivial_grammar  sB     Wm4,,.e!,r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   rw    s     . .t .r$   c                    R p\        V\        4      pV P                  4       pVP                  V4       V P	                  VP
                  ^4       R# )z5
        start: rule
        rule: 'a' | 'b'
        Nry  rz  s   &   r!   test_parse_or_grammar(TestGrammarVisitor.test_parse_or_grammar  sD     Wm4,,.e 	"-r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   rw    s     
- 
-D 
-r$   c                    R p\        V\        4      pV P                  4       pVP                  V4       V P	                  VP
                  ^4       R# )z
        start: 'a'+
        Nry  rz  s   &   r!   test_parse_repeat1_grammar-TestGrammarVisitor.test_parse_repeat1_grammar  sD     Wm4,,.e 	!,r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   rw    s     - -D -r$   c                    R p\        V\        4      pV P                  4       pVP                  V4       V P	                  VP
                  ^4       R# )z
        start: 'a'*
        Nry  rz  s   &   r!   test_parse_repeat0_grammar-TestGrammarVisitor.test_parse_repeat0_grammar  sD     Wm4,,.e 	!,r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   rw    s     . .T .r$   c                    R p\        V\        4      pV P                  4       pVP                  V4       V P	                  VP
                  ^4       R# )z"
        start: 'a' ['b']
        Nry  rz  s   &   r!   test_parse_optional_grammar.TestGrammarVisitor.test_parse_optional_grammar  sD     Wm4,,.e
 	"-r$   r   N)r[  r\  r]  r^  r   ru  r|  r  r  r  r  r_  r`  ra  s   @r!   rc  rc    sC     1. 1	- 	-. ."
- 
-- -. .r$   rc  c                   V   a  ] tR tRt o V 3R lR ltV 3R lR ltV 3R lR ltRtV tR	# )
TestGrammarVisualizeri  c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   "TestGrammarVisualizer.__annotate__  s     2 2$ 2r$   c                    R p\        V\        4      p\        4       p. pVP                  W$P                  R7       RP                  V4      p\        P                  ! R4      pV P                  WV4       R# )z 
        start: 'a' 'b'
        printerrS   u           └──Rule
           └──Rhs
              └──Alt
                 ├──NamedItem
                 │  └──StringLeaf("'a'")
                 └──NamedItem
                    └──StringLeaf("'b'")
        N	r   r,   r   print_grammar_astappendrR  r0   r1   r.   r4   r7   r-   r  linesoutputexpected_outputs   &      r!   test_simple_rule&TestGrammarVisualizer.test_simple_rule  sj     Wm4#%!!%!>5!"//

 	1r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r    s     %2 %2T %2r$   c                    R p\        V\        4      p\        4       p. pVP                  W$P                  R7       RP                  V4      p\        P                  ! R4      pV P                  WV4       R# )z:
        start: a b
        a: 'a'
        b: 'b'
        r  rS   u;          └──Rule
           └──Rhs
              └──Alt
                 ├──NamedItem
                 │  └──NameLeaf('a')
                 └──NamedItem
                    └──NameLeaf('b')

        └──Rule
           └──Rhs
              └──Alt
                 └──NamedItem
                    └──StringLeaf("'a'")

        └──Rule
           └──Rhs
              └──Alt
                 └──NamedItem
                    └──StringLeaf("'b'")
                        Nr  r  s   &      r!   test_multiple_rules)TestGrammarVisualizer.test_multiple_rules  sj    
 Wm4#%!!%!>5!"//
0 	1r$   c                   < V ^8  d   QhRR/# r   r   )r   r    s   "r!   r"   r  -  s     '2 '2t '2r$   c                    R p\        V\        4      p\        4       p. pVP                  W$P                  R7       RP                  V4      p\        P                  ! R4      pV P                  WV4       R# )z,
        start: 'a' ['b'['c'['d']]]
        r  rS   u          └──Rule
           └──Rhs
              └──Alt
                 ├──NamedItem
                 │  └──StringLeaf("'a'")
                 └──NamedItem
                    └──Opt
                       └──Rhs
                          └──Alt
                             ├──NamedItem
                             │  └──StringLeaf("'b'")
                             └──NamedItem
                                └──Opt
                                   └──Rhs
                                      └──Alt
                                         ├──NamedItem
                                         │  └──StringLeaf("'c'")
                                         └──NamedItem
                                            └──Opt
                                               └──Rhs
                                                  └──Alt
                                                     └──NamedItem
                                                        └──StringLeaf("'d'")
                                Nr  r  s   &      r!   test_deep_nested_rule+TestGrammarVisualizer.test_deep_nested_rule-  sj     Wm4#%!!%!>5!"//$
8 	1r$   r   N)	r[  r\  r]  r^  r  r  r  r_  r`  ra  s   @r!   r  r    s$     2 22%2 %2N'2 '2r$   r  )*rM  rS  r   r0   unittesttestr   typingr   r   tokenizer   r   r   r	   r
   skip_if_missingimports_under_toolpegen.grammar_parserr   r,   pegen.testutilr   r   r   pegen.grammarr   r   r   pegen.grammar_visualizerr   pegen.parserr   pegen.parser_generatorr   r   pegen.python_generatorr   TestCaser   rc  r  r   r$   r!   <module>r     s    
  	     9 9 
  ? +""?33EIICC:#Q< 4F!! FRJ. J.Zh2H-- h2A 43s   5CC 	