Module: RuboCop::Ext::RegexpParser::Expression::Base
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | lib/rubocop/ext/regexp_parser.rb |
Overview
Add expression
and loc
to all regexp_parser
nodes
Instance Attribute Summary
Instance Method Summary
-
#expression
Shortcut to
loc.expression
. -
#loc
E.g.
- #start_index
- #build_location private
Instance Attribute Details
#origin (rw)
[ GitHub ]# File 'lib/rubocop/ext/regexp_parser.rb', line 23
attr_accessor :origin
#source (rw)
Please remove this else
branch when support for regexp_parser 1.8 will be dropped.
It’s for compatibility with regexp_parser 1.8 and will never be maintained.
# File 'lib/rubocop/ext/regexp_parser.rb', line 33
attr_accessor :source
Instance Method Details
#build_location (private)
[ GitHub ]# File 'lib/rubocop/ext/regexp_parser.rb', line 67
def build_location return { body: expression } unless (q = quantifier) body = expression.adjust(end_pos: -q.text.length) q.origin = origin q.source = source if q.respond_to?(:source=) # for regexp_parser 1.8 q_loc = q.expression { body: body, quantifier: q_loc } end
#expression
Shortcut to loc.expression
See additional method definition at line 27.
# File 'lib/rubocop/ext/regexp_parser.rb', line 41
def expression @expression ||= origin.adjust(begin_pos: ts, end_pos: ts + full_length) end
#loc
E.g.
[a-z]2,
^^^ expression
^^ quantifier
^^^ body
^ begin
^ end
Please open issue if you need other locations
# File 'lib/rubocop/ext/regexp_parser.rb', line 61
def loc @loc ||= Map.new(expression, **build_location) end
#start_index
[ GitHub ]# File 'lib/rubocop/ext/regexp_parser.rb', line 35
def start_index # ts is a byte index; convert it to a character index @start_index ||= source.byteslice(0, ts).length end