-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apparently infinite recursive rule #290
Comments
From memory, yacc (or Bison maybe?) statically detects such cases and refuses to compile them (or, at least, issues a warning). If that memory is correct, we should consider doing something similar IMHO. |
StateTableError previously required a PIdx. At the point we discover this self loop we don't have one. In order to convey this error change StateTableError into an enum, combining the `pidx` field with its kind.
I wrote a gist that contains, some graphs and a breakdown of the issue, some potential ways we could go about fixing it. https://gist.github.com/ratmice/180cc7daa6e28a285885affd2e623f71 I mostly wanted to think through the semver ramifications of fixing this, and I think there are 2 options for fixing it with low impact to the code or semver, however changing the goto table the way yacc appears to seems to be quite impactful. If you think that one of these low impact options is viable, I'm kind of inclined not to be in any rush to fix this, |
Broadly speaking I'm in favour of making these errors (with the minor caveat that I'd like https://softdevteam.github.io/grmtools/master/book/errorrecovery.html#turning-lexing-errors-into-parsing-errors (where we use an otherwise-unused rule) to remain possible, but there might be a better way of doing it!). I find it hard to imagine anyone writes a grammar intending to leave such problems in. |
I would think that perhaps a new declaration like I'm mildly cognizant though of where it seems likely when you are initially writing a rule, you are less likely to have referenced within the rest of your grammar, which is kind of why I was thinking of the same way that One last thing, is I'm getting the impression that |
This feels quite yacc-y to me! I can certainly live with that. [I must admit that the other parts of statetable generation / analysis have receded so far into the back of my brain that I can't remember how this edge-case stuff might work!] |
One of the "fun" things about my project is running the parser on strange, half edited/incomplete changes.
Here is one such case I encountered that way, and have minimized.
given the input character
a
, this will cause an infinite loop pushing topstack
betweenhttps://github.com/softdevteam/grmtools/blob/master/lrpar/src/lib/parser.rs#L297
https://github.com/softdevteam/grmtools/blob/master/lrtable/src/lib/statetable.rs#L461-L466
adding a case like:
Some(i) if i == usize::from(stidx) + 1 => None,
togoto
fixes it, (i.e. the return value of goto ==prior
).Filing this as a bug report rather than sending a PR though, because I haven't yet tested it against valid parsers, or
as of yet tried to surmise if this case can only and always lead to infinite recursion or if it ever actually comes up in a valid way.
The text was updated successfully, but these errors were encountered: