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

Inherits:
Lexer
  • Object
show all
Defined in:
lib/rubocop/ast/node_pattern/with_meta.rb

Overview

Overrides Lexer to token locations and comments

Constant Summary

Constants inherited from Lexer

Lexer::Error

Constants inherited from LexerRex

LexerRex::CALL, LexerRex::CONST_NAME, LexerRex::IDENTIFIER, LexerRex::NODE_TYPE, LexerRex::REGEXP, LexerRex::REGEXP_BODY, LexerRex::SYMBOL_NAME

Instance Attribute Summary collapse

Attributes inherited from Lexer

#comments, #tokens

Attributes inherited from LexerRex

#filename, #ss, #state

Instance Method Summary collapse

Methods inherited from LexerRex

#action, #location, #matches, #next_token, #parse, #parse_file, #scanner_class

Constructor Details

#initialize(str_or_buffer) ⇒ Lexer

Returns a new instance of Lexer.


13
14
15
16
17
18
19
20
21
# 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_bufferObject (readonly)

Returns the value of attribute source_buffer.


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

def source_buffer
  @source_buffer
end

Instance Method Details

#emit_commentObject


27
28
29
30
# 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 last match's position.

Returns:

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

    last match's position


33
34
35
# 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) ⇒ Object


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

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