Class: JSONP3::Token

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

Overview

Tokens are produced by the lexer and consumed by the parser. Each token contains sub string from a JSONPath expression, its location within the JSONPath expression and a symbol indicating what type of token it is.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, value, start, query, message: nil) ⇒ Token

Returns a new instance of Token.



13
14
15
16
17
18
19
# File 'lib/json_p3/token.rb', line 13

def initialize(type, value, start, query, message: nil)
  @type = type
  @value = value
  @start = start
  @query = query
  @message = message
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



11
12
13
# File 'lib/json_p3/token.rb', line 11

def message
  @message
end

#queryObject (readonly)

Returns the value of attribute query.



11
12
13
# File 'lib/json_p3/token.rb', line 11

def query
  @query
end

#startObject (readonly)

Returns the value of attribute start.



11
12
13
# File 'lib/json_p3/token.rb', line 11

def start
  @start
end

#typeObject (readonly)

Returns the value of attribute type.



11
12
13
# File 'lib/json_p3/token.rb', line 11

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



11
12
13
# File 'lib/json_p3/token.rb', line 11

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



21
22
23
24
25
26
27
28
# File 'lib/json_p3/token.rb', line 21

def ==(other)
  self.class == other.class &&
    @type == other.type &&
    @value == other.value &&
    @start == other.start &&
    @query == other.query &&
    @message == other.message
end

#hashObject



32
33
34
# File 'lib/json_p3/token.rb', line 32

def hash
  [@type, @value].hash
end