antlr / antlr/antlr4

rule generation, in java, does not support variable arguments

Open
#222 0 comments 0 reactions 0 assignees View on GitHub
type:feature
Dominant language
Java
Stars
19k
Forks
3.5k
PR merge metrics
No merged PRs in 30d

Description

write a rules like this:

``` antlr
rule1[String... mode] : // rule content ;

rule2 : rule1["read","write"] ;
```

This was working without problem with antlrv3.

In antlrv4, the generated ParserRuleContext is wrongly generated:

``` java
public static class rule1Context extends ParserRuleContext {
public String... mode;
// rest of the code
}
```

should be

``` java
public static class rule1Context extends ParserRuleContext
{
public String[] mode;
/// rest of the code
}
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the rule1 and rule2 grammar shown in the report, then trace generation of the Java ParserRuleContext for rule1. Confirm the generated context declares the variable argument as String[] mode rather than String... mode; no specific source file or test is named in the issue.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.