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

Bad characters rebuild whole PsiTree #12

Open
MrTsepa opened this issue Apr 10, 2018 · 1 comment
Open

Bad characters rebuild whole PsiTree #12

MrTsepa opened this issue Apr 10, 2018 · 1 comment
Labels

Comments

@MrTsepa
Copy link

MrTsepa commented Apr 10, 2018

Hello everyone, I'm not sure if this question related to previous issues or not, but I have a difficulty.

In my verilog support plugin, I got a grammar from here and started to implement the plugin. I successfully implemented highlighting, referencing and completion, but I sometimes get strange behavior, when proposed variants in completion proposals are duplicated.

image

It happens because if I insert incomplete name it is not only considered as a bad character bud rebuild PsiTree.

For example, right tree

image

and tree with bad character

image

As you can see a parent of highlighted flop1 differs and lead to duplicates in completion proposals. It's because all elements of type IdentifierPsiNode are proposed now (if everything is correct they appear only in declarations so it's okay).

So my question is if there any ways to bypass this problem, for example, stopping tree rebuilding if bad characters are found. It's desirable to find decision which doesn't involve correcting grammar.

Thanks.

@bjansen
Copy link
Collaborator

bjansen commented Feb 21, 2019

@MrTsepa is this issue still relevant?

This might be caused by the fact that your Bad_character token is not sent to the HIDDEN channel. Instead it is sent to the parser, which of course does not know what to do with it.

See this comment in ANTLRv4Lexer:

// -----------------
// Illegal Character
//
// This is an illegal character trap which is always the last rule in the
// lexer specification. It matches a single character of any value and being
// the last rule in the file will match when no other rule knows what to do
// about the character. It is reported as an error but is not passed on to the
// parser.
This means that the parser to deal with the gramamr file anyway
// but we will not try to analyse or code generate from a file with lexical
// errors.
//
ERRCHAR
: . -> channel(HIDDEN)
;

Some tweaks have to be applied to existing ANTLRv4 grammars in order to make them work correctly in an IntelliJ plugin. For example, you should never -> skip tokens, and you should send tokens you don't want to parse (comments, etc) to the HIDDEN channel. I guess we should clarify that in a tutorial or something like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants