Class: Logicality::Lexer::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/logicality/lexer/token.rb

Overview

Class that defines the main structure of a Token. A token is a parsed set of characters.

Defined Under Namespace

Modules: Type

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, value) ⇒ Token

Returns a new instance of Token.

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
# File 'lib/logicality/lexer/token.rb', line 26

def initialize(type, value)
  raise ArgumentError, 'type is required'   unless type   && type.to_s.length.positive?
  raise ArgumentError, 'value is required'  unless value  && value.to_s.length.positive?

  @type   = Type.const_get(type.to_s.upcase.to_sym)
  @value  = value.to_s
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



24
25
26
# File 'lib/logicality/lexer/token.rb', line 24

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



24
25
26
# File 'lib/logicality/lexer/token.rb', line 24

def value
  @value
end

Instance Method Details

#to_sObject



34
35
36
# File 'lib/logicality/lexer/token.rb', line 34

def to_s
  "#{type}::#{value}"
end