Grammar-Kit icon indicating copy to clipboard operation
Grammar-Kit copied to clipboard

Accessors not generated for rule with multiple same tokens

Open rogerbarton opened this issue 4 years ago • 1 comments

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 :)

rogerbarton avatar Jul 05 '21 20:07 rogerbarton

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.

rogerbarton avatar Jul 06 '21 09:07 rogerbarton