PairedBraceMatcher is not working for Bracket followed by an identifier
Answered
Hi all,
In my custom language plugin, I have added simple PairedBraceMatcher implementation and it works fine for Brace and Parenthesis
It works for Brackets also but if there is a "[" followed by a token, it fails to recognize the bracket. Any idea what is the issue ?
Below is the snapshot highlighting the error
Here the braces and parenthesis are matched(even though there is no space between brace and identifier) in line 1
Brackets are also matched(space between bracket and identifier) in line 2.
But same bracket matching fails in line 3 when there is no space between bracket and identifier.
Below is my bracketmatcher impl
public class CDSBracketMatcher implements PairedBraceMatcher {
@Override
public BracePair @NotNull [] getPairs() {
BracePair braces = new BracePair(CDSTypes.LEFTBRACE, CDSTypes.RIGHTBRACE, false);
BracePair brackets = new BracePair(CDSTypes.LEFTBRACKET, CDSTypes.RIGHTBRACKET, false);
BracePair parentheses = new BracePair(CDSTypes.LEFTPARENTHESES, CDSTypes.RIGHTPARENTHESES, false);
BracePair[] bracePairs = new BracePair[3];
bracePairs[0] = braces;
bracePairs[1] = brackets;
bracePairs[2] = parentheses;
return bracePairs;
}
@Override
public boolean isPairedBracesAllowedBeforeType(@NotNull IElementType lbraceType, @Nullable IElementType contextType) {
return false;
}
@Override
public int getCodeConstructStart(PsiFile file, int openingBraceOffset) {
return 0;
}
}
Thanks and regards,
Ajit
Please sign in to leave a comment.
The `[code` part has the same colour as the other identifiers. Is your lexer tokenizing that properly as two separate tokens, or is it tokenizing it as a single identifier token?
Yes, It is tokenizing it as single token(Identifier)
Only in the case of Brackets ("[]").
Braces and Parenthesis work absolutely fine.
I found the issue. It was a Lexer problem although I find it a little weird.
Initially, my lexer was like this for matching identifiers
After changing it to the below form, it started working(added space between brackets)
Thanks and regards,
Ajit