Class: Ruby::Rego::Token
- Inherits:
-
Object
- Object
- Ruby::Rego::Token
- Defined in:
- lib/ruby/rego/token.rb
Overview
Represents a single token emitted by the lexer.
Instance Attribute Summary collapse
-
#location ⇒ Location?
readonly
-
#type ⇒ Symbol
readonly
-
#value ⇒ Object?
readonly
Instance Method Summary collapse
-
#initialize(type:, value: nil, location: nil) ⇒ Token
constructor
A new instance of Token.
-
#keyword? ⇒ Boolean
-
#literal? ⇒ Boolean
-
#operator? ⇒ Boolean
-
#to_s ⇒ String
Constructor Details
#initialize(type:, value: nil, location: nil) ⇒ Token
Returns a new instance of Token.
168 169 170 171 172 |
# File 'lib/ruby/rego/token.rb', line 168 def initialize(type:, value: nil, location: nil) @type = type @value = value @location = location end |
Instance Attribute Details
#location ⇒ Location? (readonly)
181 182 183 |
# File 'lib/ruby/rego/token.rb', line 181 def location @location end |
#type ⇒ Symbol (readonly)
175 176 177 |
# File 'lib/ruby/rego/token.rb', line 175 def type @type end |
#value ⇒ Object? (readonly)
178 179 180 |
# File 'lib/ruby/rego/token.rb', line 178 def value @value end |
Instance Method Details
#keyword? ⇒ Boolean
184 185 186 |
# File 'lib/ruby/rego/token.rb', line 184 def keyword? TokenType.keyword?(type) end |
#literal? ⇒ Boolean
194 195 196 |
# File 'lib/ruby/rego/token.rb', line 194 def literal? TokenType.literal?(type) end |
#operator? ⇒ Boolean
189 190 191 |
# File 'lib/ruby/rego/token.rb', line 189 def operator? TokenType.operator?(type) end |
#to_s ⇒ String
199 200 201 202 203 |
# File 'lib/ruby/rego/token.rb', line 199 def to_s parts = ["type=#{type}", "value=#{value.inspect}"] parts << "location=#{location}" if location "Token(#{parts.join(", ")})" end |