File: token.rb

package info (click to toggle)
ruby-hocon 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 768 kB
  • sloc: ruby: 7,903; makefile: 4
file content (45 lines) | stat: -rw-r--r-- 933 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# encoding: utf-8

require_relative '../../hocon/impl'
require_relative '../../hocon/impl/token_type'

class Hocon::Impl::Token
  attr_reader :token_type, :token_text
  def self.new_without_origin(token_type, debug_string, token_text)
    Hocon::Impl::Token.new(token_type, nil, token_text, debug_string)
  end

  def initialize(token_type, origin, token_text = nil, debug_string = nil)
    @token_type = token_type
    @origin = origin
    @token_text = token_text
    @debug_string = debug_string
  end

  attr_reader :origin

  def line_number
    if @origin
      @origin.line_number
    else
      -1
    end
  end

  def to_s
    if !@debug_string.nil?
      @debug_string
    else
      Hocon::Impl::TokenType.token_type_name(@token_type)
    end
  end

  def ==(other)
    # @origin deliberately left out
    other.is_a?(Hocon::Impl::Token) && @token_type == other.token_type
  end

  def hash
    @token_type.hash
  end
end