BNF generated classes accepting ASTNode in constructor instead of IElementType

Answered

Hi,

I am developing a intelliJ custom language plugin for one of our DSL. I am referring to GrammarKit code base.

Earlier i had this line in my bnf file: extends="com.intellij.extapi.psi.ASTWrapperPsiElement"

Now I replaced this with the custom classes,

implements="com.matrix.whiterabbit.dejavu.language.MyComposite"
extends="com.matrix.whiterabbit.dejavu.language.impl.MyCompositeImpl"

 

Now my bnf file looks like below,

{
generate=[java="8" names="long" visitor-value="R"]
parserClass="com.matrix.whiterabbit.dejavu.parser.MyParser"
parserUtilClass="com.matrix.whiterabbit.dejavu.psi.GeneratedParserUtilBase"

implements="com.matrix.whiterabbit.dejavu.language.MyComposite"
extends="com.matrix.whiterabbit.dejavu.language.impl.MyCompositeImpl"
...
}
rule ::= ruleId EQ expression SEMICOLON

MyCompositeImpl looks like below,

public class MyCompositeImpl extends CompositePsiElement implements PaniniComposite {

protected MyCompositeImpl(IElementType type) {
super(type);
}

@Override
public <R> R accept(@NotNull PaniniVisitor<R> visitor) {
return visitor.visitComposite(this);
}
}

Now when I generate Parser code, it creates the MyRuleImpl like below,

public class MyRuleImpl extends MyCompositeImpl implements MyRule {

public MyRuleImpl(ASTNode node) {
super(node);
}

In the generated parser code I am getting compilation exception as MyRuleImpl is accepting ASTNode in constructor and MyCompositeImpl accept IElementType.

GrammarKit has the same configuration in its BNF file and all its element generated Impl classes with Constructor that accepts IElementType. Example here

I am not sure what I am missing here.

Can you please help me resolve this issue ?

Thanks,

Subhojit

 

1 comment
Comment actions Permalink

Actually I figured this out. This was because in MyCompositeImpl , the constructor was protected, when I make it public the generated code created constructor with IElementType which resolve the issue.

 

I searched all the places except this :(

 

Thanks,

Subhojit

0

Please sign in to leave a comment.