Sha256: a86f31d571f83ab9c56657546af28230c4768ce3f5e31a7758a0d94c5f341654
Contents?: true
Size: 1.81 KB
Versions: 4
Compression:
Stored size: 1.81 KB
Contents
# frozen_string_literal: true module RuboCop # A basic wrapper around Parser's tokens. class Token attr_reader :pos, :type, :text def self.from_parser_token(parser_token) type, details = parser_token text, range = details new(range, type, text) end def initialize(pos, type, text) @pos = pos @type = type # Parser token "text" may be an Integer @text = text.to_s end def line @pos.line end def column @pos.column end def begin_pos @pos.begin_pos end def end_pos @pos.end_pos end def to_s "[[#{line}, #{column}], #{type}, #{text.inspect}]" end # Checks if there is whitespace after token def space_after? pos.source_buffer.source.match(/\G\s/, end_pos) end # Checks if there is whitespace before token def space_before? pos.source_buffer.source.match(/\G\s/, begin_pos - 1) end ## Type Predicates def comment? type == :tCOMMENT end def semicolon? type == :tSEMI end def left_array_bracket? type == :tLBRACK end def left_ref_bracket? type == :tLBRACK2 end def left_bracket? %i[tLBRACK tLBRACK2].include?(type) end def right_bracket? type == :tRBRACK end def left_brace? type == :tLBRACE end def left_curly_brace? type == :tLCURLY end def right_curly_brace? type == :tRCURLY end def left_parens? %i[tLPAREN tLPAREN2].include?(type) end def right_parens? type == :tRPAREN end def comma? type == :tCOMMA end def rescue_modifier? type == :kRESCUE_MOD end def end? type == :kEND end def equal_sign? %i[tEQL tOP_ASGN].include?(type) end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
rubocop-0.56.0 | lib/rubocop/token.rb |
rubocop-0.55.0 | lib/rubocop/token.rb |
rubocop-0.54.0 | lib/rubocop/token.rb |
rubocop-0.53.0 | lib/rubocop/token.rb |