Hi,
I have a situation where I get something like this in my parser (over simplified example to make the question clear!!):
rule1: something ( a | b | c | d | e | f | g )
| somethingElse ( a | b | c | d | e | f | g )
;
rule2: moreStuff ( a | b | c | d | e | f | g )
| evenMoreStuff ( a | b | c | d | e | f | g )
As you can see the rule block ( a | b | c | d | e | f | g ) appears several times and I would like to make my rules more readable.
So I try this to improve the maintainability and readability of my code:
letters: ( a | b | c | d | e | f | g );
rule1: something letters
| somethingElse letters
;
rule2: moreStuff letters
| evenMoreStuff letters
;
Yet when I do this I get (as expected) an additional "Letters" level in the parse tree.
But because I'm actually "walking around" the tree this extra level makes things like "go up 1 level" and "go down 1 level" more tricky.
Now my question is: Can I specify the rule "Letters" as being something for which NO ParseTree node should be created?
At this point the only "Solution" I see is to use something like the C-preprocessor and use macros to write a 'readable' form and generate the other one from that.
What is the best way to 'solve' this in Antlr4?
Niels Basjes