Class: AdLint::Token

Inherits:
Object
  • Object
show all
Includes:
LocationHolder, Comparable
Defined in:
lib/adlint/token.rb

Overview

DESCRIPTION

Token.

Direct Known Subclasses

ReplacedToken

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LocationHolder

#analysis_target?

Constructor Details

#initialize(type, val, loc, type_hint = nil) ⇒ Token

DESCRIPTION

Constructs a token.

PARAMETER

type

Symbol | String – Type of the token.

val

String – String value of the token.

loc

Location – Location of the token.

type_hint

Symbol | String – Hint of the token type.



50
51
52
53
# File 'lib/adlint/token.rb', line 50

def initialize(type, val, loc, type_hint = nil)
  @type, @value, @location = type, val, loc
  @type_hint = type_hint
end

Instance Attribute Details

#locationObject (readonly)

VALUE

Location – Location of this token.



65
66
67
# File 'lib/adlint/token.rb', line 65

def location
  @location
end

#typeObject (readonly)

VALUE

Symbol | String – Type of this token.



57
58
59
# File 'lib/adlint/token.rb', line 57

def type
  @type
end

#type_hintObject (readonly)

VALUE

Symbol | String – Hint of the type of this token.



69
70
71
# File 'lib/adlint/token.rb', line 69

def type_hint
  @type_hint
end

#valueObject (readonly)

VALUE

String – Value of this token.



61
62
63
# File 'lib/adlint/token.rb', line 61

def value
  @value
end

Instance Method Details

#<=>(rhs) ⇒ Object

DESCRIPTION

Compares tokens.

PARAMETER

rhs

Token – Right-hand-side token.

RETURN VALUE

Integer – Comparision result.



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/adlint/token.rb', line 87

def <=>(rhs)
  case rhs
  when Symbol, String
    @type <=> rhs
  when Token
    if (type_diff = @type <=> rhs.type) == 0
      if (val_diff = @value <=> rhs.value) == 0
        @location <=> rhs.location
      else
        val_diff
      end
    else
      type_diff
    end
  else
    raise TypeError
  end
end

#eql?(rhs_tok) ⇒ Boolean

Returns:

  • (Boolean)


106
107
108
109
# File 'lib/adlint/token.rb', line 106

def eql?(rhs_tok)
  @type == rhs_tok.type && @value == rhs_tok.value &&
    @location == rhs_tok.location
end

#hashObject



111
112
113
# File 'lib/adlint/token.rb', line 111

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

#need_no_further_replacement?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/adlint/token.rb', line 75

def need_no_further_replacement?
  false
end

#replaced?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/adlint/token.rb', line 71

def replaced?
  false
end