Skip to content

Commit

Permalink
Merge pull request #1444 from lark-parser/issue1443
Browse files Browse the repository at this point in the history
Bugfix: Earley now respects ambiguity='resolve' again. Bug was introd…
  • Loading branch information
erezsh authored Aug 13, 2024
2 parents ae207df + e6cf570 commit 653296f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lark/parsers/earley.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def parse(self, lexer, start):
transformer = ForestToParseTree(self.Tree, self.callbacks, self.forest_sum_visitor and self.forest_sum_visitor(), self.resolve_ambiguity, use_cache)
solutions = [transformer.transform(s) for s in solutions]

if len(solutions) > 1:
if len(solutions) > 1 and not self.resolve_ambiguity:
t: Tree = self.Tree('_ambig', solutions)
t.expand_kids_by_data('_ambig') # solutions may themselves be _ambig nodes
return t
Expand Down
5 changes: 5 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,11 @@ def test_multiple_start_solutions(self):
)
self.assertEqual(tree, expected)

l = Lark(grammar, ambiguity='resolve', lexer=LEXER)
tree = l.parse('x')
assert tree == Tree('start', ['x'])


def test_cycle(self):
grammar = """
start: start?
Expand Down

0 comments on commit 653296f

Please sign in to comment.