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

Parsed Regexp utilities #8510

Merged
merged 2 commits into from Aug 26, 2020
Merged

Parsed Regexp utilities #8510

merged 2 commits into from Aug 26, 2020

Conversation

marcandre
Copy link
Contributor

We are starting to have more Cops handling Regexp. This PR

  • simplifies the access to the regexp parsed tree with RegexpNode#parsed_tree
  • caches to avoid reparsing the same node multiple times
  • adds RegexpNode#each_capture which simplifies processing.

This could be helpful for #8504 too.

I'm hesitating between adding it to rubocop-ast or extending it as in this PR.

@bbatsov
Copy link
Collaborator

bbatsov commented Aug 14, 2020

Won't we end up duplicating functionality from https://github.com/ammar/regexp_parser ?

@marcandre
Copy link
Contributor Author

Right, I thought of making a PR for the gem itself; there are a few things that are annoying with the current API, etc.

In any case, RegexpNode#each_capture seems like a nice addition; maybe in the future it can be refactored to delegate the call to the gem?

@bbatsov
Copy link
Collaborator

bbatsov commented Aug 17, 2020

In any case, RegexpNode#each_capture seems like a nice addition

I agree.

maybe in the future it can be refactored to delegate the call to the gem?

Yeah, that sounds reasonable.

@mergify mergify bot merged commit b5f5b5e into rubocop:master Aug 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants