Open ptal opened 10 years ago
A solution might be to check if sub-rules of a choice are overlapping. We need to define what overlapping means for all PEG operators.
Such an analysis can draw some inspiration in the FIRST/FOLLOW analysis of LL(1) grammar. An optimization could be to detect such LL(1) cases and to optimize the code accordingly (using match
instead of nested if, and avoiding backtracking in this case: it would also improve the error reporting since we do not the try the other (not relevant) alternatives).
A first draft has been wrote by Chao Lin & William Sergeant. See unreachable_rule.rs
.
For this simple example, the
neq
rule will never match becauselt
will always match first and so the rulecomparison
will succeed and>
will not be matched. We could find a way to statically analyse such situation and report the error to the user.