a  ze@sddlZddlmZddlmZmZeded@ddlm Z ddl m Z ddl mZddlmZWdn1s~0YGd d d ejZdS) N) test_tools)DictSetZ peg_generator)GeneratedParser) parse_string)FirstSetCalculator)Grammarc@sNeZdZeeeeefdddZddddZdddd Zddd d Z ddd d Z ddddZ ddddZ ddddZ ddddZddddZddddZddddZddddZddddZddd d!Zddd"d#Zddd$d%Zddd&d'Zddd(d)Zddd*d+Zddd,d-Zddd.d/ZdS)0 TestFirstSets)grammar_sourcereturncCst|t}t|jS)N)r GrammarParserrZrulesZ calculate)selfr grammarr[/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_peg_generator/test_first_sets.pycalculate_first_setss z"TestFirstSets.calculate_first_setsN)r cCs4d}|||ddhddhhdhdddS)Nz~ start: expr NEWLINE? ENDMARKER expr: A | B A: 'a' | '-' B: 'b' | '+' 'a''-''+''b'>rrrr)ABexprstart assertEqualrr rrrrtest_alternativess zTestFirstSets.test_alternativescCs(d}|||hdhdddS)NzK start: expr NEWLINE expr: ['a'] ['b'] 'c' 'c'rr)rrrrrrrtest_optionals!s  zTestFirstSets.test_optionalscCs$d}|||dhdhddSNzA start: ','.thing+ NEWLINE thing: NUMBER NUMBERthingrrrrrrtest_repeat_with_separator+sz(TestFirstSets.test_repeat_with_separatorcCs,d}|||dhddhddhddS)NzR start: sum NEWLINE sum: (term)? 'b' term: NUMBER r"rtermsumrrrrrrtest_optional_operator2s  z$TestFirstSets.test_optional_operatorcCs,d}|||dhddhddhddS)NzQ start: sum NEWLINE sum: '+' ? term term: NUMBER r"rr&rrrrrtest_optional_literal>s  z#TestFirstSets.test_optional_literalcCs$d}|||dhdhddS)Nz@ start: term NEWLINE term: NUMBER ['+'] r"r'rrrrrrtest_optional_afterJsz!TestFirstSets.test_optional_aftercCs(d}|||ddhddhddS)Nz@ start: term NEWLINE term: ['+'] NUMBER r"rr+rrrrrtest_optional_beforeQsz"TestFirstSets.test_optional_beforecCs&d}|||dhddhddS)NzA start: thing* "+" NEWLINE thing: NUMBER r"z"+"r#rrrrr test_repeat_0XszTestFirstSets.test_repeat_0cCs&d}|||dhddhddS)NzE start: ('+' '-')* term NEWLINE term: NUMBER r"rr+rrrrrtest_repeat_0_with_group_sz&TestFirstSets.test_repeat_0_with_groupcCs$d}|||dhdhddS)NzA start: thing+ '-' NEWLINE thing: NUMBER r"r#rrrrr test_repeat_1fszTestFirstSets.test_repeat_1cCs$d}|||dhdhddS)NzF start: ('+' term)+ term NEWLINE term: NUMBER r"rr+rrrrrtest_repeat_1_with_groupmsz&TestFirstSets.test_repeat_1_with_groupcCs$d}|||dhdhddSr!rrrrr test_gathertszTestFirstSets.test_gathercCs*d}|||dhdhhdddS)NzY start: expr NEWLINE expr: &'a' opt opt: 'a' | 'b' | 'c' rr)rroptrrrrrtest_positive_lookahead{s  z%TestFirstSets.test_positive_lookaheadcCs.d}|||hdddhddhddS)NzY start: expr NEWLINE expr: !'a' opt opt: 'a' | 'b' | 'c' rrr)r3rrrrrrrtest_negative_lookaheads  z%TestFirstSets.test_negative_lookaheadc Cs8d}|||ddhdhddhdhdhdhddS)Nz start: expr NEWLINE expr: ('-' term | expr '+' term | term) term: NUMBER foo: 'foo' bar: 'bar' baz: 'baz' r"rz'foo'z'bar'z'baz')rr'rfoobarZbazrrrrrtest_left_recursions z!TestFirstSets.test_left_recursioncCs(d}|||ddhddhddS)Nz@ start: NUMBER | sign start sign: ['-'] rr")signrrrrrrtest_advance_left_recursionsz)TestFirstSets.test_advance_left_recursioncCs,d}|||ddhdhddhddS)NzV start: foo 'E' foo: bar 'A' | 'B' bar: foo 'C' | 'D' z'D'z'B')r6r7rrrrrrtest_mutual_left_recursions  z(TestFirstSets.test_mutual_left_recursioncCs(d}|||tdhdhddS)Nzf start: target '=' target: maybe '+' | NAME maybe: maybe '-' | target NAME)maybetargetr)rrsetrrrrtest_nasty_left_recursionsz'TestFirstSets.test_nasty_left_recursioncCs,d}|||ddhdhddhddS)NzO start: sign thing $ sign: ['-'] thing: NUMBER r9rr")r:r$rrrrrrtest_nullable_rules  z TestFirstSets.test_nullable_rulecCs"d}|||dddhidS)Nz start: ['-'] $ r ENDMARKERrrrrrr%test_epsilon_production_in_start_rulesz3TestFirstSets.test_epsilon_production_in_start_rulec Cs6d}|||ddhddhhddhdhddS) Nz start: sign thing other another $ sign: ['-'] thing: ['+'] other: '*' another: '/' r9rr>r'*'rrEz'/')r:r$rotherZanotherrrrrrtest_multiple_nullable_ruless z*TestFirstSets.test_multiple_nullable_rules)__name__ __module__ __qualname__strrrrrr r%r)r*r,r-r.r/r0r1r2r4r5r8r;r<rArBrDrGrrrrr s,        r )ZunittesttestrtypingrrZskip_if_missingZimports_under_toolZpegen.grammar_parserrr Zpegen.testutilrZpegen.first_setsrZ pegen.grammarrZTestCaser rrrrs      *