Class: Janeway::Token
- Inherits:
-
Object
- Object
- Janeway::Token
- Extended by:
- Forwardable
- Defined in:
- lib/janeway/token.rb
Instance Attribute Summary collapse
-
#lexeme ⇒ Object
readonly
Returns the value of attribute lexeme.
-
#literal ⇒ Object
write-access so ‘-’ operator can modify number value.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(type, lexeme, literal, location) ⇒ Token
constructor
A new instance of Token.
- #to_s ⇒ Object
Constructor Details
#initialize(type, lexeme, literal, location) ⇒ Token
Returns a new instance of Token.
16 17 18 19 20 21 |
# File 'lib/janeway/token.rb', line 16 def initialize(type, lexeme, literal, location) @type = type @lexeme = lexeme @literal = literal @location = location end |
Instance Attribute Details
#lexeme ⇒ Object (readonly)
Returns the value of attribute lexeme.
9 10 11 |
# File 'lib/janeway/token.rb', line 9 def lexeme @lexeme end |
#literal ⇒ Object
write-access so ‘-’ operator can modify number value
12 13 14 |
# File 'lib/janeway/token.rb', line 12 def literal @literal end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
9 10 11 |
# File 'lib/janeway/token.rb', line 9 def location @location end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
9 10 11 |
# File 'lib/janeway/token.rb', line 9 def type @type end |
Instance Method Details
#==(other) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/janeway/token.rb', line 27 def ==(other) # This is intended to make unit test expectations simple to define, experimental, may drop case other when Integer, String then @literal == other when Symbol then @type == other when Token @type == other.type && @lexeme == other.lexem && @literal = other.literal else raise ArgumentError, "don't know how to compare Token with #{other.inspect}" end end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/janeway/token.rb', line 23 def to_s "Token<#{@type}: #{@lexeme.inspect}>" end |