Class: Odin::Parsing::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/odin/parsing/token.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, value, line, column, raw: nil) ⇒ Token

Returns a new instance of Token.



8
9
10
11
12
13
14
15
# File 'lib/odin/parsing/token.rb', line 8

def initialize(type, value, line, column, raw: nil)
  @type = type
  @value = value
  @line = line
  @column = column
  @raw = raw
  freeze
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



6
7
8
# File 'lib/odin/parsing/token.rb', line 6

def column
  @column
end

#lineObject (readonly)

Returns the value of attribute line.



6
7
8
# File 'lib/odin/parsing/token.rb', line 6

def line
  @line
end

#rawObject (readonly)

Returns the value of attribute raw.



6
7
8
# File 'lib/odin/parsing/token.rb', line 6

def raw
  @raw
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/odin/parsing/token.rb', line 6

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



6
7
8
# File 'lib/odin/parsing/token.rb', line 6

def value
  @value
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/odin/parsing/token.rb', line 21

def error?
  type == TokenType::ERROR
end

#to_sObject



17
18
19
# File 'lib/odin/parsing/token.rb', line 17

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