You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from lark import Lark
parser = Lark("""
?inner: "a"
outer: "a" "b" -> one
| inner "b" -> two
start: outer
%import common.WS
%ignore WS
""")
parser.parse("a b")
This grammar definition makes no sense, but never mind that. The output produced is:
Traceback (most recent call last):
File "test2.py", line 15, in <module>
parser.parse("a b")
File "*/site-packages/lark/lark.py", line 190, in parse
return self.parser.parse(text)
File "*/site-packages/lark/parser_frontends.py", line 137, in parse
return self.parser.parse(text)
File "*/site-packages/lark/parsers/xearley.py", line 131, in parse
ResolveAmbig().visit(tree)
File "*/site-packages/lark/tree.py", line 132, in visit
getattr(self, subtree.data, self.__default__)(subtree)
File "*/site-packages/lark/parsers/earley.py", line 282, in _ambig
_resolve_ambig(tree)
File "*/site-packages/lark/parsers/earley.py", line 273, in _resolve_ambig
best = min(tree.children, key=cmp_to_key(_compare_drv))
File "*/site-packages/lark/parsers/earley.py", line 263, in _compare_drv
c = _compare_drv(t1, t2)
File "*/site-packages/lark/parsers/earley.py", line 263, in _compare_drv
c = _compare_drv(t1, t2)
File "*/site-packages/lark/parsers/earley.py", line 241, in _compare_drv
return -compare(tree1, tree2)
File "*/site-packages/lark/utils.py", line 86, in compare
elif a > b:
TypeError: '>' not supported between instances of 'Derivation' and 'Token'
I would expect some kind of parser error that notifies me of an unresolvable ambiguity. (I found this because my parser would work in version 0.3.1 but not in 0.3.6, so somewhere along the line the behaviour of ambiguities changed. I've been unable to construct a small example that shows this behaviour though.)
The text was updated successfully, but these errors were encountered:
Fixed and pushed as 0.3.7
Thanks for catching the bug and giving a useful example!
Just a note, @thijsmie : Lark chooses a single derivation by default, using a sensible (but arbitrary) set of rules.
If you want to see all possible derivations, so you can choose for yourself, you'll have to call Lark(..., ambiguity='explicit')
Good luck!
Thanks for the quick fix! In my case the ambiguity resulted from a mistake in my grammar definition, but I'll keep the "explicit" option in mind for future projects.
Consider the following snippet:
parser.parse("a b")
This grammar definition makes no sense, but never mind that. The output produced is:
I would expect some kind of parser error that notifies me of an unresolvable ambiguity. (I found this because my parser would work in version 0.3.1 but not in 0.3.6, so somewhere along the line the behaviour of ambiguities changed. I've been unable to construct a small example that shows this behaviour though.)
The text was updated successfully, but these errors were encountered: