Skip to content

Parse fails based on order #339

Answered by ColinH
jimmydevine asked this question in Q&A
Mar 10, 2023 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

You need to take into account how backtracking works in PEGs, i.e. the only reason to choose a different (which will always be the next) branch of an sor is when one fails to match. PEGs will never go looking for a better (i.e. longer) match once they found one.

When you use the version of GrammarNumber that does not work it's because when you give it a something like 1.2 as input then the first branch of the sor with GrammarInteger will match and consume the 1 from the input, returning control to the sor rule signalling success. The sor will therefore not attempt to match the subsequent GrammarFloat.

That is why, with PEGs, you always need to take care that a rule B that can match a pref…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@jimmydevine
Comment options

@ColinH
Comment options

@jimmydevine
Comment options

Answer selected by jimmydevine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants