Class: RuboCop::AST::NodePattern::Parser::WithMeta::Lexer
- Defined in:
- lib/rubocop/ast/node_pattern/with_meta.rb
Overview
Overrides Lexer to token locations and comments
Constant Summary
Constants inherited from Lexer
Instance Attribute Summary collapse
-
#source_buffer ⇒ Object
readonly
Returns the value of attribute source_buffer.
Attributes inherited from Lexer
Instance Method Summary collapse
- #emit_comment ⇒ Object
-
#initialize(str_or_buffer) ⇒ Lexer
constructor
A new instance of Lexer.
-
#pos ⇒ ::Parser::Source::Range
Last match’s position.
- #token(type, value) ⇒ Object
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_buffer ⇒ Object (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_comment ⇒ Object
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.
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 |