-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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 Regexp::Expression#loc
and #expression
. Remove parsed_tree_expr_loc
#8960
Conversation
We'll be adding references to the source to the nodes, so I can't think of any other way to proceed that won't involve unacceptable memory leaks.
cc/ @owst |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice @marcandre, I wish I'd thought of this 😄 - a few minor comments.
@@ -43,7 +43,7 @@ def each_repeated_character_class_element_loc(node) | |||
|
|||
child_source = child.to_s | |||
|
|||
yield node.parsed_tree_expr_loc(child) if seen.include?(child_source) | |||
yield child.expression if seen.include?(child_source) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much neater 👍
RegexpRegexp::Expression#loc
and #expression
. Deprecate parsed_tree_expr_loc
Regexp::Expression#loc
and #expression
. Deprecate parsed_tree_expr_loc
Regexp::Expression#loc
and #expression
. Deprecate parsed_tree_expr_loc
Regexp::Expression#loc
and #expression
. Remove parsed_tree_expr_loc
LGTM 👍 |
Thanks for the quick review @owst 💛 |
Nice improvement! |
…terClass with %r This commit uses `RegexpNode::RegexpParser#body` (rubocop#8960) instead of `Parser::Source::Range#adjust` in Style/RedundantRegexpCharacterClass. When regular expression are written by %r literal, RedundantRegexpCharacterClass made incorrect loc as following. ``` %r{abc[\d]+} ^^^^^^ ``` This bug are caused by calling`node.loc.begin.adjust` to get range of character class with %r regexp. `Parser::Source::Range#adjust` adjust based on `Parser::Source::Range#begin_pos` but it with %r literal doesn't indicate start of regular expression source, point to location of '%'. So, RedundantRegexpCharacterClass makes incorrect loc if %r literal are used in code. ``` r = %r{abc} ^ # `node.loc.begin.begin_pos` ``` ``` r = %r{abs} ^ # `node.loc.begin.end_pos` ```
…s with %r This commit uses `RegexpNode::RegexpParser#body` (#8960) instead of `Parser::Source::Range#adjust` in Style/RedundantRegexpCharacterClass. When regular expression are written by %r literal, RedundantRegexpCharacterClass made incorrect loc as following. ``` %r{abc[\d]+} ^^^^^^ ``` This bug are caused by calling`node.loc.begin.adjust` to get range of character class with %r regexp. `Parser::Source::Range#adjust` adjust based on `Parser::Source::Range#begin_pos` but it with %r literal doesn't indicate start of regular expression source, point to location of '%'. So, RedundantRegexpCharacterClass makes incorrect loc if %r literal are used in code. ``` r = %r{abc} ^ # `node.loc.begin.begin_pos` ``` ``` r = %r{abs} ^ # `node.loc.begin.end_pos` ```
The source information provided by
regexp_parser
is difficult to use.This PR adds a
parser
-like location map to these nodes. E.g.:Will be useful for #8948