Carry across .g4 file comments into the generated code #4844
The-Futurist
started this conversation in
Ideas
Replies: 1 comment
-
Propagating comments is a very very tricky problem, for not much added value (as far as I can see here). ruley: X Y Z; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
It would be potentially very helpful to have comments from the .g4 file, copied across into the generated code.
The comment could appear as a C# comment to aid in reading the generated code but also as an attribute on the generated class.
For example having this comment in my .g4:
Would lead to the attribute being present on the class:
If Antlr doesn't parse comments then it could just be a raw copy:
The goal being that a developer could embed directives to aid in AST generation by reflecting on these comments and extracting metadata to aid in AST generation/processing. I'm currently exploring an idea where I consume the generated .CS files, compile them in memory and then reflect upon them to assist in AST code generation - currently just an idea but potentially a huge time saver.
The comments can then themselves represent a simple language for expressing metadata that's helpful in the generation of AST code. As visit the CST we can pull out these comments and do interesting stuff and because the comments are ignored by Antlr their meaning and so on is down to the developer.
Beta Was this translation helpful? Give feedback.
All reactions