[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


评论操作 固定链接

Hi Sergiy
For my opinion the prefered way is:

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

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.