Minimum example:
grammar = '''start: expression
expression: expression " " expression | terminal
terminal: "token1"
| "token2"
'''.strip()
parser = Lark(grammar, parser='lalr')
p = ParserState(parser)
Now, this works for incomplete parses, e.g.
{'TOKEN1', 'TOKEN2'}
{'TOKEN1', 'TOKEN2'}
Now, let's say you have a state that is itself a valid parse, but which also allows for more tokens to be generated (notice I removed the trailing whitespace):
[]