Skip to content
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

Closed
MDoerner opened this issue Oct 20, 2018 · 4 comments
Labels
possible bug Could be a bug

Comments

@MDoerner
Copy link

MDoerner commented Oct 20, 2018

I have the issue mentioned in the title in the current version in the VS Marketplace (2.0.4).

MCVE:

grammar:

grammar TreeVisualizationFail;

LETTER : [a-zA-Z];
DIGIT : [0-9];

 
startRule : digits letters EOF;

letters : LETTER+;

digits : DIGIT*;

input:

foo

Note that for the given input the mandatory rule digits in startRule matches no tokens, i.e. an empty string.

After making digits optional in startRule and forcing digits to match at least one digit, the parse tree visualization gets generated.

Originally, I encountered this problem with a grammar used to parse VBA.

@mike-lischke
Copy link
Owner

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.

@Vogel612
Copy link

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 startRule in the minimal example, accessing the generated digits will never be null (interesting for languages such as C# or java), but instead will always generate a DigitsContext node.

While that context does not necessarily have any children, it makes for a different API

@MDoerner
Copy link
Author

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.)

@mike-lischke
Copy link
Owner

mike-lischke commented Oct 20, 2018

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.

@mike-lischke mike-lischke added the possible bug Could be a bug label Oct 20, 2018
mike-lischke added a commit that referenced this issue Dec 17, 2018
- 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
possible bug Could be a bug
Projects
None yet
Development

No branches or pull requests

3 participants