Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessors not generated for rule with multiple same tokens #280

Open
rogerbarton opened this issue Jul 5, 2021 · 1 comment
Open

Accessors not generated for rule with multiple same tokens #280

rogerbarton opened this issue Jul 5, 2021 · 1 comment

Comments

@rogerbarton
Copy link

rogerbarton commented Jul 5, 2021

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 rogerbarton changed the title Accessors not generated for rule with multiple tokens Accessors not generated for rule with multiple same tokens Jul 5, 2021
@rogerbarton
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant