Custom Language rule works fine when viewed in PsiViewer but show BAD_CHARACTER

已回答

I'm new to Plugin Development. I have a requirement to turn a json like properties file (Plist) into a custom language. I had the following written in my language definition (bnf) file.

root ::= '{' meta_property [property+] '}'

meta_property ::= 'PARENT' '=' '{' context_property '}'';'

context_property ::= 'CHILD' '=' object

object ::= '{' (property)* '}' ';'

property ::= property_name '=' value ';'
property_name ::= literal
literal ::= SINGLE_QUOTED_STRING|DOUBLE_QUOTED_STRING|IDENTIFIER

reference_expression ::= IDENTIFIER

value ::= object| literal | reference_expression

Tried to borrow the bnf created for json in the Intellij-ide source code (json.bnf)

Everything looks fine but when I observe the output in the PsiViewer, I see the mention of a BAD_CHARACTER for the '=' sign. I'm not sure what is marking it as BAD_CHARACTER. Could someone help me with what is going on ?

0

Please always link to full sources. This seems to be a problem with lexer.

0

Hi Yann, 

           Sorry. Here are the details. 

fofik.bnf:

{
parserClass = "com.fofik.parser.FofikParser"
psiPackage = "com.fofik.psi"
psiImplPackage = "com.fofik.psi.impl"

elementTypeHolderClass = "com.fofik.psi.FofikTypes"
elementTypeClass = "com.fofik.psi.FofikElementType"
psiClassPrefix = "Fofik"
psiVisitorName = "FofikElementVisitor"
tokenTypeClass = "com.fofik.psi.FofikTokenType"

psiImplUtilClass = "com.fofik.psi.impl.FofikPsiImplUtil"
extends("literal|reference_expression")=value
tokens = [
L_CURLY='{'
R_CURLY='}'
L_PAREN = '('
R_PAREN=')'
SEMICOLON = ';'
DOT = '.'
PLUS = '+'
COMMA = ','
ASSIGN = 'regexp:[:=]'
NUMBER="regexp:((0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]*)?)|Infinity|-Infinity|NaN"
LINE_COMMENT='regexp://.*"/*" ([^*]|\*+[^*/])* (\*+"/")?'
BLOCK_COMMENT='regexp:/\*([^*]|\*+[^*/])*(\*+/)?'
DOUBLE_QUOTED_STRING='regexp:"([^\\"\r\n]|\\[^\r\n])*"?'
SINGLE_QUOTED_STRING="regexp:'([^\\'\r\n]|\\[^\r\n])*'?"
IDENTIFIER="regexp:[[:jletterdigit:]~!()*\-./@\^<>=]+"
CRLF = "regexp:[\r\n]"
]
}
root ::= '{' property+ '}'
object ::= '{' (property)* '}'
property ::= property_name ('=' value ';') {
methods = [ getName getValue]
mixin = "com.fofik.psi.impl.FofikNamedElementImpl"
implements = "com.fofik.psi.FofikNamedElement"
pin(".*") = 1
}
private property_name ::= literal |reference_expression
literal ::= SINGLE_QUOTED_STRING|DOUBLE_QUOTED_STRING|IDENTIFIER
reference_expression ::= IDENTIFIER

value ::= object| literal | reference_expression

 fofik.lex:

package com.fofik;

import com.intellij.lexer.FlexLexer;
import com.intellij.psi.tree.IElementType;
import static com.fofik.psi.FofikTypes.*;
import com.intellij.psi.TokenType;
import static com.intellij.psi.TokenType.WHITE_SPACE;
import static com.intellij.psi.TokenType.BAD_CHARACTER;


%%

%class FofikLexer
%implements FlexLexer
%unicode
%function advance
%type IElementType
%eof{ return;
%eof}

WHITE_SPACE=\s+
LINE_COMMENT="//"[^\n]*|"#"[^\n]*
BLOCK_COMMENT="/"\*([^*]|\*+[^*/])*(\*+"/")?
DOUBLE_QUOTED_STRING=\"([^\\\"]|\\[^\r\n])*\"?
SINGLE_QUOTED_STRING='([^\\']|\\[^\r\n])*'?
NUMBER=((0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]*)?)|Infinity|-Infinity|NaN
IDENTIFIER=[a-zA-Z_][a-zA-Z0-9_]*
%%
<YYINITIAL> {
{WHITE_SPACE} { return TokenType.WHITE_SPACE;}
"{" { return L_CURLY; }
"}" { return R_CURLY; }
"(" { return L_PAREN; }
")" { return R_PAREN; }
";" { return SEMICOLON; }
"." { return DOT; }
"+" { return PLUS; }
"," { return COMMA;}
{DOUBLE_QUOTED_STRING} { return DOUBLE_QUOTED_STRING;}
{SINGLE_QUOTED_STRING} { return SINGLE_QUOTED_STRING;}
{LINE_COMMENT} { return LINE_COMMENT; }
{BLOCK_COMMENT} { return BLOCK_COMMENT; }
{IDENTIFIER} { return IDENTIFIER; }
{NUMBER} { return NUMBER; }
}

[^] { return BAD_CHARACTER; }

Unfortunately, I cannot upload my project outside of the company network. Please do let me know if there is any further detail required.Thanks again. 

0

Sorry but it is impossible to diagnose this without having the full project sources.

0

Yann,  I'm working on moving the pieces specific to plugin into another project. 

0

请先登录再写评论。