I’m trying to modify a rule depending on it’s context with as few copy/paste as possible. I’ll best begin with a pseudocode variant of what I’m trying to achieve:
module[boolean isParam]: 'module' id=identity?
declaration+
update+
'endmodule' -> ^(MODULE ({if (isParam)} IS_PARAMETER {else} $id) declaration+ update+);
If isParam is set I want the module to not match the identity rule but create a IS_PARAMETER token in its place. I’m sure I can do this with two separate module rules but is there a cleaner way with less code duplication or without splitting the module rule into a number of smaller rules?
I believe something like this works: