You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I understand that the documentation warns about this, but how can I define a working PEG file that will correctly fallback on tokens when the value is not a valid number?
The documentation:
This means that the options are tried in order and the first choice that leads to a successful parse is kept. If this choice results in a parsing error later on in the input, the parser does not backtrack and try any other choices, the parse simply fails.
I don't get the difference between a successful parse that will be used to choose the right choice, and a parsing on the input that can fail.
The text was updated successfully, but these errors were encountered:
What happens when trying to parse the string: 1.2.3:
The first rule, query, is tried.
query is a choice whose first member is number, so number is tried
number matches the string 1.2, leaving .3 unparsed
Since number succeeded in matching the input, query succeeds with its result
After applying the first rule, query, to the input, we have not consumed the entire string, so the parse fails
The problem here is that you have a choice where one member (number) matches prefixes of another member (token). In general this is a bad idea when using PEGs, and you need to redesign the grammar so that this does not happen.
I'm trying to use canopy to parse search queries, and I'm struggling with ordered choices that raise parsing errors.
What I want to do (this is one use case that I extracted from the syntax I need to parse):
text
-
, consider the token as negatedI tried to achieve this with the following PEG file:
When parsing the string
1.2.3
with the parser generated by canopy & this PEG file, it raises the following error:I understand that the documentation warns about this, but how can I define a working PEG file that will correctly fallback on tokens when the value is not a valid number?
The documentation:
I don't get the difference between a successful parse that will be used to choose the right choice, and a parsing on the input that can fail.
The text was updated successfully, but these errors were encountered: