JetBrains / Grammar-Kit

Grammar files support & parser/PSI generation for IntelliJ IDEA
Other
715 stars 125 forks source link

How to make an external rules as elementTypeClass? #289

Open quovadis1234 opened 2 years ago

quovadis1234 commented 2 years ago

In my .bnf file, I define some rules as follow:

comb_identifier ::= IDENTIFIER | IDENTIFIER_PREDECLARED
OperandName ::= <<identifier_ref>> | QualifiedIdent {extends=Operand}

The code of external rule <> is

 public static boolean identifier_ref(PsiBuilder b, int level) {
        IElementType type = b.getTokenType();
        if (CueTokenTypes.IDENTIFIERS.contains(type)) {
            b.advanceLexer();
            return true;
        }

        // null is a NULL_LIT, true and false are BOOL_LIT, all others are KEYWORD, so we can just remap KEYWORD
        if (type == CueTypes.KEYWORD) {
            b.remapCurrentToken(CueTypes.IDENTIFIER);
            b.advanceLexer();
            return true;
        }
        return false;
    }

It is used for transforming KEYWORD to IDENTIFIER in an OperandName. I want to replace the <> by comb_identifier, so I can resolve the reference of comb_identifier in an OperandName. But if I do so, KEYWORD cannot be remapped as IDENTIFIER. What can I do to achieve my purpose?