Grammar-Kit
Grammar-Kit copied to clipboard
Accessors not generated for rule with multiple same tokens
I have a problem with getters not being generated for the PsiElement's when using multiple regexp tokens of the same type in one rule.
{
...
tokens = [
NUMBER = 'regexp:\d[_\d]*'
]
}
UnpackedDimension ::= '[' NUMBER ':' NUMBER ']' {
methods = [
first = "/NUMBER[0]"
last = "/NUMBER[1]"
]
}
When running Generate Parser Code, the generated class MyUnpackedDimension does not have getters for the two numbers.
So I added the methods first and last, however these give me the error:
UnpackedDimension#first("/NUMBER[0]"): 'NUMBER' not found in 'UnpackedDimension' (available: COLON, LBRACK, RBRACK)
If I implement NUMBER as a rule, not a token:
fake NumberRule ::= NUMBER
UnpackedDimension ::= '[' NumberRule ':' NumberRule ']'
Then I get a getNumberRuleList function generated. Why can I generate this for a token directly?
Thanks in advance :)
Having looked at the ExprParser.bnf example it uses the trivial rule:
literal_expr ::= number
where number is a token. So I will do it this way. Not sure if this is optimal though.