Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Add a command for adding labels #342

Open
Aleyasen opened this issue Oct 6, 2023 · 2 comments
Open

[Feature Request] Add a command for adding labels #342

Aleyasen opened this issue Oct 6, 2023 · 2 comments

Comments

@Aleyasen
Copy link

Aleyasen commented Oct 6, 2023

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
    ;
@kaby76
Copy link
Owner

kaby76 commented Oct 6, 2023

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.

@Aleyasen
Copy link
Author

Aleyasen commented Oct 7, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants