123456789_123456789_123456789_123456789_123456789_

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

Instance Attribute Details

#origin (rw)

[ GitHub ]

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

attr_accessor :origin

Instance Method Details

#build_location (private)

[ GitHub ]

  
# File 'lib/rubocop/ext/regexp_parser.rb', line 50

def build_location
  return { body: expression } unless (q = quantifier)

  body = expression.adjust(end_pos: -q.text.length)
  q.origin = origin
  q_loc = q.expression

  { body: body, quantifier: q_loc }
end

#expression

Shortcut to loc.expression

[ GitHub ]

  
# File 'lib/rubocop/ext/regexp_parser.rb', line 26

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

[ GitHub ]

  
# File 'lib/rubocop/ext/regexp_parser.rb', line 44

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