@@ -784,6 +784,24 @@ def test_ambiguous_intermediate_node_conditionally_inlined_rule(self):
784784 self .assertEqual (ambig_tree .data , '_ambig' )
785785 self .assertEqual (set (ambig_tree .children ), expected )
786786
787+ @unittest .skipIf (LEXER == 'basic' , 'This ambiguity only occurs with the dynamic lexers' )
788+ def test_ambiguous_ignores (self ):
789+ grammar = """
790+ !start: a "b"
791+ !a: "a" | "a1" | "a12"
792+ %ignore "1"
793+ %ignore "2"
794+ """
795+
796+ l = Lark (grammar , ambiguity = 'explicit' , lexer = LEXER )
797+ tree = l .parse ('a12b' )
798+
799+ expected = Tree ('_ambig' , [
800+ Tree ('start' , [Tree ('a' , ['a' ]), 'b' ]),
801+ Tree ('start' , [Tree ('a' , ['a1' ]), 'b' ]),
802+ Tree ('start' , [Tree ('a' , ['a12' ]), 'b' ]),
803+ ])
804+ self .assertEqual (tree , expected )
787805
788806 @unittest .skipIf (LEXER == 'basic' , "Requires dynamic lexer" )
789807 def test_fruitflies_ambig (self ):
@@ -876,6 +894,26 @@ def test_multiple_start_solutions(self):
876894 tree = l .parse ('x' )
877895 assert tree == Tree ('start' , [Tree ('a' , ['x' ])])
878896
897+ @unittest .skipIf (LEXER == 'basic' , 'This scenario only occurs with the dynamic lexers' )
898+ def test_multiple_start_solutions2 (self ):
899+ grammar = r"""
900+ !start: "foo1" | "foo" | "foo12"
901+ %ignore "1"
902+ %ignore "2"
903+ """
904+ l = Lark (grammar , ambiguity = 'explicit' , lexer = LEXER )
905+ tree = l .parse ('foo12' )
906+
907+ expected = Tree ('_ambig' , [
908+ Tree ('start' , ['foo1' ]),
909+ Tree ('start' , ['foo' ]),
910+ Tree ('start' , ['foo12' ]),
911+ ])
912+ self .assertEqual (tree , expected )
913+
914+ l = Lark (grammar , ambiguity = 'resolve' , lexer = LEXER )
915+ tree = l .parse ('foo12' )
916+ self .assertEqual (tree , Tree ('start' , ['foo1' ]))
879917
880918 def test_cycle (self ):
881919 grammar = """
0 commit comments