Skip to content

Commit

Permalink
Small fixes mentioned by PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
erezsh committed Jun 21, 2024
1 parent 74d328d commit f7c98bb
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lark/parsers/earley.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,20 @@ def parse(self, lexer, start):
except ImportError:
logger.warning("Cannot find dependency 'pydot', will not generate sppf debug image")
else:
debug_walker.visit(solutions[0], "sppf.png")
for i, s in enumerate(solutions):
debug_walker.visit(s, f"sppf{i}.png")


if self.Tree is not None:
# Perform our SPPF -> AST conversion
transformer = ForestToParseTree(self.Tree, self.callbacks, self.forest_sum_visitor and self.forest_sum_visitor(), self.resolve_ambiguity)
solutions = [transformer.transform(s) for s in solutions]

return solutions[0] if len(solutions) == 1 else self.Tree('_ambig', solutions)
if len(solutions) > 1:
t: Tree = self.Tree('_ambig', solutions)
t.expand_kids_by_data('_ambig') # solutions may themselves be _ambig nodes
return t
return solutions[0]

# return the root of the SPPF
# TODO return a list of solutions, or join them together somehow
Expand Down

0 comments on commit f7c98bb

Please sign in to comment.