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
According to the documentation, the MatchResult is supposed to provide the rightmost fail position along with the list of expected rules at that position.
However, I have observed some confusing alterations of this behavior.
Consider the following grammar (I've tried to make it as short as possible to illustrate the case):
Foo {
Program = Definition *
Definition =
| Fun
Fun = "fun" identifier "(" ")" Statements
Statements = "{" Statement* "}"
Statement (a statement) =
| Return
Expression (an expression) = number | VarAccess
Return (a return statement) = "return" Expression ";"
VarAccess (a variable) = identifier
number (a constant) = digit+
identifier = letter (alnum)*
}
Now I am trying to parse the following broken program:
fun a()
{
quit;
}
Note that the quit statement is obviously wrong. Matching this input against the grammar above yields the following result:
Line 3, col 3:
1 | fun a()
2 | {
3 | quit;
^
4 | }
Expected "}" or a statement
So far, so good. But if we alter the grammar above with a supposedly innocent decoration - adding a description to the Fun rule - the result becomes much less funny:
Line 1, col 1:
1 | fun a()
^
2 | {
Expected end of input
So, the matcher is no longer able to point me to the exact location of the problem. It reports it much further left in the source than it should.
Neither it lists all of the possible alternatives - it should tell me that it expects end of input OR a function definition.
So, the question is: how do I get the "right" rightmost failure without stripping off all the rule descriptions?
P.S. The ohm version I'm running is 17.1.0
Below is the complete grammar that produces this broken result:
Foo {
Program = Definition *
Definition =
| Fun
Fun (a function definition) = "fun" identifier "(" ")" Statements
Statements = "{" Statement* "}"
Statement (a statement) =
| Return
Expression (an expression) = number | VarAccess
Return (a return statement) = "return" Expression ";"
VarAccess (a variable) = identifier
number (a constant) = digit+
identifier = letter (alnum)*
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
According to the documentation, the MatchResult is supposed to provide the rightmost fail position along with the list of expected rules at that position.
However, I have observed some confusing alterations of this behavior.
Consider the following grammar (I've tried to make it as short as possible to illustrate the case):
Now I am trying to parse the following broken program:
Note that the
quit
statement is obviously wrong. Matching this input against the grammar above yields the following result:So far, so good. But if we alter the grammar above with a supposedly innocent decoration - adding a description to the Fun rule - the result becomes much less funny:
So, the matcher is no longer able to point me to the exact location of the problem. It reports it much further left in the source than it should.
Neither it lists all of the possible alternatives - it should tell me that it expects end of input OR a function definition.
So, the question is: how do I get the "right" rightmost failure without stripping off all the rule descriptions?
P.S. The ohm version I'm running is 17.1.0
Below is the complete grammar that produces this broken result:
Beta Was this translation helpful? Give feedback.
All reactions