Class: Logicality::Lexer::Token

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

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)


23
24
25
26
27
28
29
# File 'lib/logicality/lexer/token.rb', line 23

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

  @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.



21
22
23
# File 'lib/logicality/lexer/token.rb', line 21

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



21
22
23
# File 'lib/logicality/lexer/token.rb', line 21

def value
  @value
end

Instance Method Details

#to_sObject



31
32
33
# File 'lib/logicality/lexer/token.rb', line 31

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