Class: Postsvg::Model::Token

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

Overview

Lexical token. Type is one of: :number, :operator, :name, :string, :hexstring, :proc_open, :proc_close, :array_open, :array_close, :dict_open, :dict_close, :dsc.

literal is true when a :name was written with a leading slash (i.e. it is a literal name, not an operator-style name reference).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, value, line: nil, column: nil, literal: false) ⇒ Token

Returns a new instance of Token.



15
16
17
18
19
20
21
22
# File 'lib/postsvg/model/token.rb', line 15

def initialize(type, value, line: nil, column: nil, literal: false)
  @type = type
  @value = value
  @line = line
  @column = column
  @literal = literal
  freeze
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



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

def column
  @column
end

#lineObject (readonly)

Returns the value of attribute line.



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

def line
  @line
end

#literalObject (readonly)

Returns the value of attribute literal.



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

def literal
  @literal
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

Instance Method Details

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



28
29
30
31
32
33
34
35
# File 'lib/postsvg/model/token.rb', line 28

def ==(other)
  other.is_a?(Token) &&
    other.type == @type &&
    other.value == @value &&
    other.line == @line &&
    other.column == @column &&
    other.literal == @literal
end

#hashObject



38
39
40
# File 'lib/postsvg/model/token.rb', line 38

def hash
  [@type, @value, @line, @column, @literal].hash
end

#positionObject



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

def position
  [line, column]
end