Okay, well... by default, the individual Node subclasses do not have access to the XXXParser object. Now, there actually is a global setting you can set at the top of your grammar, which is NODE_USES_PARSER
which will generate code such that the various node objects have a parser
field. So, with NODE_USES_PARSER
set, you could just get the propertyWords
via parser.getPropertyWords()
, I guess. I mean, from within any Node class.
The above is a solution but it might be considered a bit heavy-handed. Another possibility might be to just pass in the propertyWords
as a parameter to the method, as in:
public CompoundId compoundId(Set<String> propertyWords) {
....
}
The above method would be injected into the generated CreateMemberBodyClause class.
Then you could just invoke that method from a code action in your grammar production, as in:
CreateMemberBodyClause :
CompoundId
{
CompoundId cid = CURRENT_NODE.compoundId(propertyWords); // here you have access to
// propertyWords because this
// is a code action generated inside the parser class.
// CURRENT_NODE is an instance of CreateMemberBodyClause
...
...
pokeNode(cid);
}
...
...
;
I mean, I guess it's maybe a question of clarifying in your mind where the code is being generated. Then you know what is in scope and what is not visible. The code inside a code action in a grammar rule is being generated inside the generated XXXParser class, so it has access to propertyWords
and whatever else inside that generated parser class (including things that are private). But the code injected inside of the CreateMemberBodyClause
does not have access to anything inside the parser class unless you pass it in somehow, though there is the more heavy-handed global solution of just using the NODE_USES_PARSER
option and then all the nodes have a parser field they can use. And they can get propertyWords
via that, and anything else, as long as it's public.
I hope that's helpful.