Class: Janeway::Token

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/janeway/token.rb

Overview

Tokens are produced by the lexer, they represent jsonpath query elements in a low-level, non-hierarchical way.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, lexeme, literal, location) ⇒ Token

Returns a new instance of Token.



17
18
19
20
21
22
# File 'lib/janeway/token.rb', line 17

def initialize(type, lexeme, literal, location)
  @type = type
  @lexeme = lexeme
  @literal = literal
  @location = location
end

Instance Attribute Details

#lexemeObject (readonly)

Returns the value of attribute lexeme.



10
11
12
# File 'lib/janeway/token.rb', line 10

def lexeme
  @lexeme
end

#literalObject

write-access so ‘-’ operator can modify number value



13
14
15
# File 'lib/janeway/token.rb', line 13

def literal
  @literal
end

#locationObject (readonly)

Returns the value of attribute location.



10
11
12
# File 'lib/janeway/token.rb', line 10

def location
  @location
end

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'lib/janeway/token.rb', line 10

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/janeway/token.rb', line 28

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_sObject



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

def to_s
  "Token<#{@type}: #{@lexeme.inspect}>"
end