JetBrains / JetBrains/Grammar-Kit

Accessors not generated for rule with multiple same tokens

Open
#280 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
771
Forks
137
Avg merge
11h 14m
Merged PRs (30d)
1

Description

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

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the grammar snippets and the Generate Parser Code entry point, then compare token handling with the rule-based NumberRule example in the generated MyUnpackedDimension class. Reproduce the missing accessors and the NUMBER-not-found error; the issue is resolved when repeated NUMBER tokens receive usable generated accessors like the rule form.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.