123456789_123456789_123456789_123456789_123456789_

Class: RuboCop::AST::NodePattern::Lexer

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, LexerRex
Instance Chain:
self, LexerRex
Inherits: LexerRex
  • Object
Defined in: lib/rubocop/ast/node_pattern/lexer.rb

Overview

Lexer class for ::RuboCop::AST::NodePattern

Doc on how this fits in the compiling process: /docs/modules/ROOT/pages/node_pattern.adoc

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(source) ⇒ Lexer

[ GitHub ]

  
# File 'lib/rubocop/ast/node_pattern/lexer.rb', line 31

def initialize(source)
  @tokens = []
  super()
  parse(source)
end

Instance Attribute Details

#comments (readonly)

[ GitHub ]

  
# File 'lib/rubocop/ast/node_pattern/lexer.rb', line 29

attr_reader :source_buffer, :comments, :tokens

#source_buffer (readonly)

[ GitHub ]

  
# File 'lib/rubocop/ast/node_pattern/lexer.rb', line 29

attr_reader :source_buffer, :comments, :tokens

#tokens (readonly)

[ GitHub ]

  
# File 'lib/rubocop/ast/node_pattern/lexer.rb', line 29

attr_reader :source_buffer, :comments, :tokens

Instance Method Details

#do_parse (private)

[ GitHub ]

  
# File 'lib/rubocop/ast/node_pattern/lexer.rb', line 60

def do_parse
  # Called by the generated `parse` method, do nothing here.
end

#emit(type) ⇒ token (private)

[ GitHub ]

  
# File 'lib/rubocop/ast/node_pattern/lexer.rb', line 40

def emit(type)
  value = ss[1] || ss.matched
  value = yield value if block_given?
  token = token(type, value)
  @tokens << token
  token
end

#emit_comment (private)

[ GitHub ]

  
# File 'lib/rubocop/ast/node_pattern/lexer.rb', line 48

def emit_comment
  nil
end

#emit_regexp (private)

[ GitHub ]

  
# File 'lib/rubocop/ast/node_pattern/lexer.rb', line 52

def emit_regexp
  body = ss[1]
  options = ss[2]
  flag = options.each_char.sum { |c| REGEXP_OPTIONS[c] }

  emit(:tREGEXP) { Regexp.new(body, flag) }
end

#token(type, value) (private)

[ GitHub ]

  
# File 'lib/rubocop/ast/node_pattern/lexer.rb', line 64

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