lark: Non-deterministic parser state for ambiguous example with priorities

I have a very small example of an ambiguity in a parser:

from lark import Lark

l = Lark(
'''start: GENERIC | SPECIFIC
GENERIC.2: /\w+/
SPECIFIC.1: "HelloWorld"
''', parser="earley", lexer="dynamic", ambiguity="resolve"
)

for i in range(1, 101):
    print(l.parse("HelloWorld"))

Both GENERIC and SPECIFIC matches, but I have set a priority forcing GENERIC to match. This is not always the result though. If running this program multiple times it will match either GENERIC or SPECIFIC seemingly random. All matches for one run will be the same, but not between runs. This signals that a state in the parser is different between the runs.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (7 by maintainers)

Most upvoted comments

@dirk-thomas 0.7b is the latest candidate. I hope to merge it to master in the next couple of weeks.

An official release might take a little longer, because I’ll want to make sure the documentation reflects all the changes.