lark-parser / lark

Lark is a parsing toolkit for Python, built with a focus on ergonomics, performance and modularity.
MIT License
4.88k stars 414 forks source link

Earley parse of ambiguous grammar crashes when `debug=True` #1170

Closed joodicator closed 2 years ago

joodicator commented 2 years ago
>>> from lark import Lark
>>> Lark('\n'.join(['start: a | b', 'a: "x"', 'b: "x"']), debug=True).parse('x')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\Python310\lib\site-packages\lark\lark.py", line 625, in parse
    return self.parser.parse(text, start=start, on_error=on_error)
  File "C:\Program Files\Python310\lib\site-packages\lark\parser_frontends.py", line 96, in parse
    return self.parser.parse(stream, chosen_start, **kw)
  File "C:\Program Files\Python310\lib\site-packages\lark\parsers\earley.py", line 283, in parse
    debug_walker.visit(solutions[0], "sppf.png")
  File "C:\Program Files\Python310\lib\site-packages\lark\parsers\earley_forest.py", line 742, in visit
    super(ForestToPyDotVisitor, self).visit(root)
  File "C:\Program Files\Python310\lib\site-packages\lark\parsers\earley_forest.py", line 336, in visit
    vpno(current)
  File "C:\Program Files\Python310\lib\site-packages\lark\parsers\earley_forest.py", line 774, in visit_packed_node_out
    child_graph_node = self.graph.get_node(child_graph_node_id)[0]
IndexError: list index out of range

lark version: 1.1.2 pydot version: 1.4.2

MegaIng commented 2 years ago

Could this be a duplicate of #1121 , which should be fixed in master?

joodicator commented 2 years ago

Could this be a duplicate of #1121 , which should be fixed in master?

Oh, yes, it is indeed fixed on master. Apologies for the duplicate; I searched for this issue, but apparently not thoroughly enough.