antlr / intellij-plugin-v4

An IntelliJ plugin for ANTLR v4
https://plugins.jetbrains.com/plugin/7358-antlr-v4
BSD 3-Clause "New" or "Revised" License
462 stars 103 forks source link

Antlr Preview tree creates the tree based on the entire lexer #615

Closed Ajris closed 1 year ago

Ajris commented 1 year ago

Hi,

I have found an issue with the preview tree.

If i get the simplest grammar, for instance: image

And the simplest lexer with some obsolete values: image

I would have seen an error in a preview: image

After removing the obsolite line from the lexer (so the line with NOT_SOMETHING), I am finally seeing the correct results: image

I believe that the tree shouldnt show the elements from the Lexer which are not used (they should be completely disregarded) and not considered in the preview tree.

parrt commented 1 year ago

I don't see why it should ignore things that match the input. Does NOT_SOMETHING match? It looks like it does to me and then you get a parse error.

Ajris commented 1 year ago

Because they are not in the grammar yet they are available in the lexer. Isnt only the grammar evaluated in the plugin? If the grammar doesn't use the NOT_SOMETHING in any way, should it be still showed in the tree? I thought that the plugin can help me understand the grammar - so I would expect it compare it to the grammar that I have provided and evaluate all the rules based on the grammar that i have presented (especially if its possible) and not compare it with additional keywords that I might have specified in the lexer which are NOT added to the grammar at all and could be completely removed.

parrt commented 1 year ago

Well this is not a filtering tool. All characters that are not tokens get flagged as an error. All other tokens get sent to the parser. If the person doesn't recognize some thing it causes an error. Imagine you build a parser for a programming language that accepts any kind of random crap that doesn't happen to be Java or whatever. Not what you want ;)