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

Add unused group name mutation #1200

Merged
merged 1 commit into from
Jan 5, 2021
Merged

Conversation

dgollahon
Copy link
Collaborator

@dgollahon dgollahon commented Jan 3, 2021

  • Mutates capture group names: /(?<foo>bar)/ -> /(?<_foo>)/.
  • Closes Add mutation /(?<foo>)//(?<foo__mutant__>)/ #573. NOTE: I have deviated from the issue slightly and chosen a _ prefix so that, like with local variables, names can be left in unused if they are explicitly marked as such. I have decided to extend the behavior to not mutating to a non-capture group as well in this case because the _ prefix seems like a clear choice that the user would rather keep the label even if the capturing functionality is unused.

@dgollahon dgollahon changed the title Add named capture to non-capturing group mutation Add named group name underscore mutation Jan 3, 2021
@dgollahon dgollahon changed the title Add named group name underscore mutation Add unused group name mutation Jan 3, 2021
@dgollahon dgollahon force-pushed the add-named_group-name-mutation branch 2 times, most recently from 875b1bb to 16e5211 Compare January 3, 2021 05:22
Comment on lines 22 to 23
unless name_underscored?
emit(s(:regexp_passive_group, group))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbj What do you think of this behavior? I added the passive group mutation to the guard so that if you deliberately underscore a named group (sort of like a comment) you are able to keep it and not be forced to the non-capturing passive group. I could also move it outside of the guard but this was my intuition for what I would likely prefer if I were a user.

@dgollahon dgollahon force-pushed the add-named_group-name-mutation branch from 16e5211 to d646dfe Compare January 3, 2021 05:25
@dgollahon dgollahon marked this pull request as ready for review January 3, 2021 05:25
@dgollahon dgollahon requested a review from mbj January 3, 2021 05:25
@dgollahon dgollahon force-pushed the add-named_group-name-mutation branch 2 times, most recently from 2e09662 to 3887b37 Compare January 3, 2021 09:02
- Mutates capture group names: `/(?<foo>bar)/` -> `/(?<_foo>bar)/`.
- Closes #573. NOTE: I have deviated from the issue slightly and chosen a `_` prefix so that, like with local variables, names can be left in unused if they are explicitly marked as such. I have decided to extend the behavior to not mutating to a non-capture group as well in this case because the `_` prefix seems like a clear choice that the user would rather keep the label even if the capturing functionality is unused.
@dgollahon dgollahon force-pushed the add-named_group-name-mutation branch from 3887b37 to 1c4f875 Compare January 5, 2021 03:10
@dgollahon dgollahon merged commit 1da85b3 into master Jan 5, 2021
@dgollahon dgollahon deleted the add-named_group-name-mutation branch January 5, 2021 20:57
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

Successfully merging this pull request may close these issues.

Add mutation /(?<foo>)//(?<foo__mutant__>)/
2 participants