Open smontanaro opened 1 year ago
The typical practice with Parsimonious grammars is to add a whitespace term (e.g. spc
) to the right side of every "leaf" node of a grammar. Take a look at what I did in the grammar that describes Parsimonious grammars themselves: https://github.com/erikrose/parsimonious/blob/d5636a6ae4d7fe2ddb96f567e289ab3eeb454b49/parsimonious/grammar.py#L220-L256.
I'm trying to parse Gmail-like queries, stuff like
Since I'm dealing entirely with strings and
parsimonious
doesn't seem to have a tokenizer, I'm happy for now to use something like this, so the character set of the operators is completely distinct from the character set of words:Still, I'm not getting that to work. My grammar looks like this:
When trying to parse the second query string I get:
If I tack optional whitespace around the and/or operators to gobble up the space before the
||
operator, it parses:but that seems like a crude hack. While I'm not totally averse to the idea of hacking my way to a solution, it still seems there should be a cleaner way to define the grammar. None of the
parsimonious
examples I found dealt with anything like this. Am I missing something?