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
Parse tree rendering fails in the presence of rules matching an empty string #52
Comments
That's kinda duplicate of #44. The cause is the same. The underlying antlr4ts library tries to optimize the ATN from this grammar and fails. However, matching an empty input string is a problem anyway and must be avoided. ANTLR4 will issue a warning for that. |
FWIW I would not consider a rule that may match empty string and a warning (note: not an error) generated by the ANTLR runtime to be sufficient reason to expect no parse tree at all. IIUC the matching behaviour is also subtly different. When examining the output generated by While that context does not necessarily have any children, it makes for a different API |
Just as a small note: Antlr only generates a warning for a rule matching an empty string if this rule is made optional in another rule using it. (In that case, the outcome is non-deterministic.) |
I see. Didn't think of that possibility (why would one want a node for no match?), but it seems people have their own use cases. Thanks. |
- Rules which don't match anything don't have a stop token. This makes it unreliable the token range display for a non-terminal. Instead the explicit range now comes with the data. - Fixed also a problem where token range strings in graphical parse trees were misplaced.
I have the issue mentioned in the title in the current version in the VS Marketplace (2.0.4).
MCVE:
grammar:
input:
Note that for the given input the mandatory rule
digits
instartRule
matches no tokens, i.e. an empty string.After making
digits
optional instartRule
and forcingdigits
to match at least one digit, the parse tree visualization gets generated.Originally, I encountered this problem with a grammar used to parse VBA.
The text was updated successfully, but these errors were encountered: