class RuboCop::AST::Token
A basic wrapper around Parser's tokens.
Attributes
pos[R]
text[R]
type[R]
Public Class Methods
from_parser_token(parser_token)
click to toggle source
# File lib/rubocop/ast/token.rb, line 9 def self.from_parser_token(parser_token) type, details = parser_token text, range = details new(range, type, text) end
new(pos, type, text)
click to toggle source
# File lib/rubocop/ast/token.rb, line 15 def initialize(pos, type, text) @pos = pos @type = type # Parser token "text" may be an Integer @text = text.to_s end
Public Instance Methods
begin_pos()
click to toggle source
# File lib/rubocop/ast/token.rb, line 30 def begin_pos @pos.begin_pos end
column()
click to toggle source
# File lib/rubocop/ast/token.rb, line 26 def column @pos.column end
comma?()
click to toggle source
# File lib/rubocop/ast/token.rb, line 99 def comma? type == :tCOMMA end
comment?()
click to toggle source
Type Predicates
# File lib/rubocop/ast/token.rb, line 55 def comment? type == :tCOMMENT end
end?()
click to toggle source
# File lib/rubocop/ast/token.rb, line 107 def end? type == :kEND end
end_pos()
click to toggle source
# File lib/rubocop/ast/token.rb, line 34 def end_pos @pos.end_pos end
equal_sign?()
click to toggle source
# File lib/rubocop/ast/token.rb, line 111 def equal_sign? %i[tEQL tOP_ASGN].include?(type) end
left_array_bracket?()
click to toggle source
# File lib/rubocop/ast/token.rb, line 63 def left_array_bracket? type == :tLBRACK end
left_brace?()
click to toggle source
# File lib/rubocop/ast/token.rb, line 79 def left_brace? type == :tLBRACE end
left_bracket?()
click to toggle source
# File lib/rubocop/ast/token.rb, line 71 def left_bracket? %i[tLBRACK tLBRACK2].include?(type) end
left_curly_brace?()
click to toggle source
# File lib/rubocop/ast/token.rb, line 83 def left_curly_brace? type == :tLCURLY end
left_parens?()
click to toggle source
# File lib/rubocop/ast/token.rb, line 91 def left_parens? %i[tLPAREN tLPAREN2].include?(type) end
left_ref_bracket?()
click to toggle source
# File lib/rubocop/ast/token.rb, line 67 def left_ref_bracket? type == :tLBRACK2 end
line()
click to toggle source
# File lib/rubocop/ast/token.rb, line 22 def line @pos.line end
rescue_modifier?()
click to toggle source
# File lib/rubocop/ast/token.rb, line 103 def rescue_modifier? type == :kRESCUE_MOD end
right_bracket?()
click to toggle source
# File lib/rubocop/ast/token.rb, line 75 def right_bracket? type == :tRBRACK end
right_curly_brace?()
click to toggle source
# File lib/rubocop/ast/token.rb, line 87 def right_curly_brace? type == :tRCURLY end
right_parens?()
click to toggle source
# File lib/rubocop/ast/token.rb, line 95 def right_parens? type == :tRPAREN end
semicolon?()
click to toggle source
# File lib/rubocop/ast/token.rb, line 59 def semicolon? type == :tSEMI end
space_after?()
click to toggle source
Checks if there is whitespace after token
# File lib/rubocop/ast/token.rb, line 43 def space_after? pos.source_buffer.source.match(/\G\s/, end_pos) end
space_before?()
click to toggle source
Checks if there is whitespace before token
# File lib/rubocop/ast/token.rb, line 48 def space_before? position = begin_pos.zero? ? begin_pos : begin_pos - 1 pos.source_buffer.source.match(/\G\s/, position) end
to_s()
click to toggle source
# File lib/rubocop/ast/token.rb, line 38 def to_s "[[#{line}, #{column}], #{type}, #{text.inspect}]" end