Is it possible to generate parsers that use classes of other shared parsers?
- Dominant language
- Java
- Stars
- 19k
- Forks
- 3.5k
- PR merge metrics
- No merged PRs in 30d
Description
I have a grammar `SharedParser.g4` with rules `a` and `b`. This grammar is imported to grammars `Client1Parser.g4` and `Client2Parser.g4` which use these rules.
When antlr generates Java sources for `Client{1,2}Parser.g4`, each of the parsers define their own types for the shared rules. As a result, there are three types for each of rules `a` and `b`:
- `Client1Parser.A`, `Client1Parser.B`;
- `Client2Parser.A`, `Client2Parser.B`;
- `SharedParser.A`, `SharedParser.B`.
I expected the client parsers to return types `SharedParser.A` and `SharedParser.B` from their methods `parser.a()` and `parser.b()`. Is this possible?
Contributor guide
Research direction
Start with the SharedParser.g4, Client1Parser.g4, and Client2Parser.g4 grammar setup described in the issue, then inspect how ANTLR generates the Java rule context types and parser methods. Determine whether client parsers can return SharedParser.A and SharedParser.B, and document the required generator behavior or constraints.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100