Module: RuboCop::Ext::RegexpParser::Expression::Base

Included in:
RuboCop::Ext::RegexpParser
Defined in:
lib/rubocop/ext/regexp_parser.rb

Overview

Add `expression` and `loc` to all `regexp_parser` nodes

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#originObject

Returns the value of attribute origin


23
24
25
# File 'lib/rubocop/ext/regexp_parser.rb', line 23

def origin
  @origin
end

#sourceObject

Please remove this `else` branch when support for regexp_parser 1.8 will be dropped. It's for compatibility with regexp_arser 1.8 and will never be maintained.


33
34
35
# File 'lib/rubocop/ext/regexp_parser.rb', line 33

def source
  @source
end

Instance Method Details

#expressionObject

Shortcut to `loc.expression`


27
28
29
# File 'lib/rubocop/ext/regexp_parser.rb', line 27

def expression
  @expression ||= origin.adjust(begin_pos: ts, end_pos: ts + full_length)
end

#locObject

E.g.

[a-z]{2,}
^^^^^^^^^ expression
     ^^^^ quantifier
^^^^^     body
^         begin
    ^     end

Please open issue if you need other locations


62
63
64
65
66
# File 'lib/rubocop/ext/regexp_parser.rb', line 62

def loc
  @loc ||= begin
    Map.new(expression, **build_location)
  end
end

#start_indexObject


35
36
37
38
# 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