Class: Logicality::Lexer::Token
- Inherits:
-
Object
- Object
- Logicality::Lexer::Token
- 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
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(type, value) ⇒ Token
constructor
A new instance of Token.
- #to_s ⇒ Object
Constructor Details
#initialize(type, value) ⇒ Token
Returns a new instance of Token.
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
#type ⇒ Object (readonly)
Returns the value of attribute type.
24 25 26 |
# File 'lib/logicality/lexer/token.rb', line 24 def type @type end |
#value ⇒ Object (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_s ⇒ Object
34 35 36 |
# File 'lib/logicality/lexer/token.rb', line 34 def to_s "#{type}::#{value}" end |