Class: OpenvoxLint::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/openvox-lint/token.rb

Overview

Represents a single token produced by the lexer.

Each token has a type (Symbol), a raw value (String), and positional metadata (line, column). Tokens are linked together in a doubly-linked list via prev_token / next_token so that check plugins can easily navigate the stream.

Constant Summary collapse

FORMATTING_TYPES =
%i[
  WHITESPACE INDENT NEWLINE COMMENT MLCOMMENT SLASH_COMMENT
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, value, line, column) ⇒ Token

Returns a new instance of Token.



14
15
16
17
18
19
# File 'lib/openvox-lint/token.rb', line 14

def initialize(type, value, line, column)
  @type   = type
  @value  = value
  @line   = line
  @column = column
end

Instance Attribute Details

#columnObject

Returns the value of attribute column.



11
12
13
# File 'lib/openvox-lint/token.rb', line 11

def column
  @column
end

#lineObject

Returns the value of attribute line.



11
12
13
# File 'lib/openvox-lint/token.rb', line 11

def line
  @line
end

#next_tokenObject

Returns the value of attribute next_token.



11
12
13
# File 'lib/openvox-lint/token.rb', line 11

def next_token
  @next_token
end

#prev_tokenObject

Returns the value of attribute prev_token.



11
12
13
# File 'lib/openvox-lint/token.rb', line 11

def prev_token
  @prev_token
end

#typeObject

Returns the value of attribute type.



11
12
13
# File 'lib/openvox-lint/token.rb', line 11

def type
  @type
end

#valueObject

Returns the value of attribute value.



11
12
13
# File 'lib/openvox-lint/token.rb', line 11

def value
  @value
end

Instance Method Details

#formatting?Boolean

Convenience: is this token a formatting/whitespace token?

Returns:

  • (Boolean)


30
31
32
# File 'lib/openvox-lint/token.rb', line 30

def formatting?
  FORMATTING_TYPES.include?(type)
end

#inspectObject



25
26
27
# File 'lib/openvox-lint/token.rb', line 25

def inspect
  "#<OpenvoxLint::Token #{self}>"
end

#to_sObject



21
22
23
# File 'lib/openvox-lint/token.rb', line 21

def to_s
  "#{type}(#{value.inspect}) @ #{line}:#{column}"
end