123456789_123456789_123456789_123456789_123456789_

Class: RuboCop::AST::NodePattern::Parser::WithMeta::Lexer

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: RuboCop::AST::NodePattern::Lexer
Defined in: lib/rubocop/ast/node_pattern/with_meta.rb

Overview

Overrides Lexer to token locations and comments

Constant Summary

::RuboCop::AST::NodePattern::Lexer - Inherited

Error, REGEXP_OPTIONS

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(str_or_buffer) ⇒ Lexer

[ GitHub ]

  
# File 'lib/rubocop/ast/node_pattern/with_meta.rb', line 13

def initialize(str_or_buffer)
  @source_buffer = if str_or_buffer.respond_to?(:source)
                     str_or_buffer
                   else
                     ::Parser::Source::Buffer.new('(string)', source: str_or_buffer)
                   end
  @comments = []
  super(@source_buffer.source)
end

Instance Attribute Details

#source_buffer (readonly)

[ GitHub ]

  
# File 'lib/rubocop/ast/node_pattern/with_meta.rb', line 11

attr_reader :source_buffer

Instance Method Details

#emit_comment

[ GitHub ]

  
# File 'lib/rubocop/ast/node_pattern/with_meta.rb', line 27

def emit_comment
  @comments << Comment.new(pos)
  super
end

#pos::Parser::Source::Range

Returns:

  • (::Parser::Source::Range)

    last match’s position

[ GitHub ]

  
# File 'lib/rubocop/ast/node_pattern/with_meta.rb', line 33

def pos
  ::Parser::Source::Range.new(source_buffer, ss.pos - ss.matched_size, ss.pos)
end

#token(type, value)

[ GitHub ]

  
# File 'lib/rubocop/ast/node_pattern/with_meta.rb', line 23

def token(type, value)
  super(type, [value, pos])
end