[Cpp][Dart] Superclass option doesn't generate import/#include statement for Dart/Cpp target
- Dominant language
- Java
- Stars
- 19k
- Forks
- 3.5k
- PR merge metrics
- No merged PRs in 30d
Description
This is a problem with grammars that are derived from a base class using the `options { superClass=...; }` statement, and targets that require some kind of "include" for the generated parser to know what the base class is for compilation.
I am rewriting the grammars-v4/java/java9/Java9.g4 grammar, which currently contains a [predicate in Java](https://github.com/antlr/grammars-v4/blob/090c0fbebbdc43701f04f2de82279d2338ae954f/java/java9/Java9.g4#L1832), to instead call a method. While rewriting the predicate as a method call is not strictly "target independent", the trick works across CSharp and Java. I am trying to see if the trick will work for other targets.
Unfortunately, when I go to compile the generated Dart code, the generated code does not know what the base class is because there is no "import" statement added to the generated lexer (or parser). I'll admit that I am no expert in Dart, but a Dart file that references code in another file--even if those files are part of the same package--must be explicitly imported using "import 'foobarbaseclass.dart';". As a workaround, I can add a "header" declaration to the grammar file to do the import, but the grammar is now Dart specific.
The error also occurs for the Cpp target because a `#include` is not generated to include the header file that I wrote for the parser.
I have to now special case the grammar for Dart and Cpp.
Should not the Antlr Tool template for Dart generate "import 'foobarbaseclass.dart';" for superclasses so I don't have to in special-case version of the grammar?
--Ken
Contributor guide
Research direction
Start with the ANTLR Tool templates for the Dart and Cpp targets and inspect how generated lexers and parsers handle the grammar's superClass option. Reproduce the issue with a grammar using options { superClass=...; } and check the generated output. Done means the Dart output has the needed import and the Cpp output has the needed #include without target-specific header declarations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, dart
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100