Class: Prism::Token
- Inherits:
-
Object
- Object
- Prism::Token
- Defined in:
- lib/prism/parse_result.rb,
ext/prism/extension.c
Overview
This represents a token from the Ruby source.
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
A Location object representing the location of this token in the source.
-
#type ⇒ Object
readonly
The type of token that this token is.
-
#value ⇒ Object
readonly
A byteslice of the source that this token represents.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Returns true if the given other token is equal to this token.
-
#deconstruct_keys(keys) ⇒ Object
Implement the hash pattern matching interface for Token.
-
#initialize(type, value, location) ⇒ Token
constructor
Create a new token object with the given type, value, and location.
-
#pretty_print(q) ⇒ Object
Implement the pretty print interface for Token.
Constructor Details
#initialize(type, value, location) ⇒ Token
Create a new token object with the given type, value, and location.
427 428 429 430 431 |
# File 'lib/prism/parse_result.rb', line 427 def initialize(type, value, location) @type = type @value = value @location = location end |
Instance Attribute Details
#location ⇒ Object (readonly)
A Location object representing the location of this token in the source.
424 425 426 |
# File 'lib/prism/parse_result.rb', line 424 def location @location end |
#type ⇒ Object (readonly)
The type of token that this token is.
418 419 420 |
# File 'lib/prism/parse_result.rb', line 418 def type @type end |
#value ⇒ Object (readonly)
A byteslice of the source that this token represents.
421 422 423 |
# File 'lib/prism/parse_result.rb', line 421 def value @value end |
Instance Method Details
#==(other) ⇒ Object
Returns true if the given other token is equal to this token.
454 455 456 457 458 |
# File 'lib/prism/parse_result.rb', line 454 def ==(other) other.is_a?(Token) && other.type == type && other.value == value end |
#deconstruct_keys(keys) ⇒ Object
Implement the hash pattern matching interface for Token.
434 435 436 |
# File 'lib/prism/parse_result.rb', line 434 def deconstruct_keys(keys) { type: type, value: value, location: location } end |
#pretty_print(q) ⇒ Object
Implement the pretty print interface for Token.
439 440 441 442 443 444 445 446 447 448 449 450 451 |
# File 'lib/prism/parse_result.rb', line 439 def pretty_print(q) q.group do q.text(type.to_s) self.location.pretty_print(q) q.text("(") q.nest(2) do q.breakable("") q.pp(value) end q.breakable("") q.text(")") end end |