[Feature Request] Add a command for adding labels
Aleyasen opened this issue · comments
I am wondering if it's possible to have a command that automatically adds labels to the rules. For example:
exampleRule
: firstAlternative
| secondAlternative
| thirdAlternative
;
to
exampleRule
: firstAlternative # exampleRuleAlt1
| secondAlternative # exampleRuleAlt2
| thirdAlternative # exampleRuleAlt3
;
The main problem will be to come up with meaningful names of the actions.
"#<rule-name>-<alt-number>"
Any other suggestions? The only other thing may be to find something unique about the alt.
expr : expr ('+'/'-') expr #add_sub_alt
| expr ('=='|'!=') expr #equals_notequals_alt
...
;
I was planning to write a tool that adds missing rules for string literals as lexer rules, which is required for splitting the grammar. I think I can devise something similar for this transformation. But, I would need to go through the alt and find what is different about it relative to other alts.
@kaby76 Thank you for the prompt response. Your suggestion to use more meaningful names is intriguing. However,
"#<rule-name>-<alt-number>"
might also suffice.
In my use case, I had to add labels to nearly all rules containing |. The specific name of the label wasn't crucial, but because the parser file was extensive, it became burdensome. That's why I submitted the feature request.