Parsing always fails when explicitly using whitespace, with implicit whitespaces enabled #653
Replies: 1 comment
-
The "correct" solution is to mark the This is a property of how PEG works, and the assumptions made about how trivia behaves in a language. A PEG-defined parser is greedy. Once it's made a decision, that decision is final, and no backtracking of any sort is done. (For me, it's helped to think of, in complicated cases, think of writing the grammar as writing a parser, not as writing a traditional grammar.) The other solution is for your keywords to encode that they can't be followed by more identifier-like characters. (i.e. you encode the fact that a traditional lexer is greedy.) Using some #333-styled syntax for clarity, an example:
If you get really fancy, preventing identifiers from being keywords (unchecked pest:2.0 syntax this time):
|
Beta Was this translation helpful? Give feedback.
-
If I want to parse something with at least one space in between and given the following rule:
parsing always fails.
This is because the implicit whitespace rule is auto inserted and matches before the explicit whitespace can match.
Maybe it would be possible to turn that around and first try to match the explicit rule and only if that fails, try to match the implicit rule.
Beta Was this translation helpful? Give feedback.
All reactions