[GrammarKit] Store parsed token in Psi class

I have the following rule:

Def ::= ('val' | 'var') PatternDef


class which represents 'Def' rule doesn't contain tokens, it contains only PatternDef reference.
Is there a way to make GrammarKit generator to store which token ('var' or 'val') was matched?
Right now I have to do this:

Def ::= 'val' ValDef | 'var' VarDef



Thanks.

0
1 comment

Hi Sergiy
For my opinion the prefered way is:

Def ::= ValDef | VarDef
ValDef ::= 'val' PatternDef
VarDef ::=
'var' 
PatternDef

But your original variant is also possible. You can use com.intellij.psi.formatter.FormatterUtil#getPreviousNonWhitespaceLeaf and understand what the token type placed before PatternDef.

0

Please sign in to leave a comment.