class RuboCop::AST::Token

A basic wrapper around Parser’s tokens.

def self.from_parser_token(parser_token)

def self.from_parser_token(parser_token)
  type, details = parser_token
  text, range = details
  new(range, type, text)
end

def begin_pos

def begin_pos
  @pos.begin_pos
end

def column

def column
  @pos.column
end

def comma?

def comma?
  type == :tCOMMA
end

def comment?

def comment?
  type == :tCOMMENT
end

def dot?

def dot?
  type == :tDOT
end

def end?

def end?
  type == :kEND
end

def end_pos

def end_pos
  @pos.end_pos
end

def equal_sign?

def equal_sign?
  %i[tEQL tOP_ASGN].include?(type)
end

def initialize(pos, type, text)

def initialize(pos, type, text)
  @pos = pos
  @type = type
  # Parser token "text" may be an Integer
  @text = text.to_s
end

def left_array_bracket?

def left_array_bracket?
  type == :tLBRACK
end

def left_brace?

def left_brace?
  type == :tLBRACE
end

def left_bracket?

def left_bracket?
  %i[tLBRACK tLBRACK2].include?(type)
end

def left_curly_brace?

def left_curly_brace?
  type == :tLCURLY || type == :tLAMBEG
end

def left_parens?

def left_parens?
  LEFT_PAREN_TYPES.include?(type)
end

def left_ref_bracket?

def left_ref_bracket?
  type == :tLBRACK2
end

def line

def line
  @pos.line
end

def new_line?

def new_line?
  type == :tNL
end

def regexp_dots?

def regexp_dots?
  %i[tDOT2 tDOT3].include?(type)
end

def rescue_modifier?

def rescue_modifier?
  type == :kRESCUE_MOD
end

def right_bracket?

def right_bracket?
  type == :tRBRACK
end

def right_curly_brace?

def right_curly_brace?
  type == :tRCURLY
end

def right_parens?

def right_parens?
  type == :tRPAREN
end

def semicolon?

def semicolon?
  type == :tSEMI
end

def space_after?

Checks if there is whitespace after token
def space_after?
  pos.source_buffer.source.match(/\G\s/, end_pos)
end

def space_before?

Checks if there is whitespace before token
def space_before?
  position = begin_pos.zero? ? begin_pos : begin_pos - 1
  pos.source_buffer.source.match(/\G\s/, position)
end

def to_s

def to_s
  "[[#{line}, #{column}], #{type}, #{text.inspect}]"
end