Class: AdLint::Token
- Inherits:
-
Object
- Object
- AdLint::Token
- Includes:
- LocationHolder, Comparable
- Defined in:
- lib/adlint/token.rb
Overview
DESCRIPTION
Token.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
VALUE Location – Location of this token.
-
#type ⇒ Object
readonly
VALUE Symbol | String – Type of this token.
-
#type_hint ⇒ Object
readonly
VALUE Symbol | String – Hint of the type of this token.
-
#value ⇒ Object
readonly
VALUE String – Value of this token.
Instance Method Summary collapse
-
#<=>(rhs) ⇒ Object
DESCRIPTION Compares tokens.
- #eql?(rhs_tok) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(type, val, loc, type_hint = nil) ⇒ Token
constructor
DESCRIPTION Constructs a token.
- #need_no_further_replacement? ⇒ Boolean
- #replaced? ⇒ Boolean
Methods included from LocationHolder
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
#location ⇒ Object (readonly)
VALUE
Location – Location of this token.
65 66 67 |
# File 'lib/adlint/token.rb', line 65 def location @location end |
#type ⇒ Object (readonly)
VALUE
Symbol | String – Type of this token.
57 58 59 |
# File 'lib/adlint/token.rb', line 57 def type @type end |
#type_hint ⇒ Object (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 |
#value ⇒ Object (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
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 |
#hash ⇒ Object
111 112 113 |
# File 'lib/adlint/token.rb', line 111 def hash [@type, @value, @location].hash end |
#need_no_further_replacement? ⇒ Boolean
75 76 77 |
# File 'lib/adlint/token.rb', line 75 def need_no_further_replacement? false end |
#replaced? ⇒ Boolean
71 72 73 |
# File 'lib/adlint/token.rb', line 71 def replaced? false end |