I've got a small query language where the empty string makes sense as a query. I'm handling it as a special case outside of Lark, and I'd like to be able to get rid of that special case. I've tried things like:
?start: the_actual_grammar
| "" -> op_empty
and:
?start: the_actual_grammar
| / */ -> op_empty
But it fails with "Dynamic Earley doesn't allow zero-width regexps" which pretty much explains the situation.
Any ideas how to work around this?
Why not use an empty rule?
>>> p = Lark('!start: "a" | ')
>>> p.parse('a')
Tree(start, [Token(A, 'a')])
>>> p.parse('')
Tree(start, [])
Thanks, didn't realize that was possible!
Most helpful comment
Why not use an empty rule?