class Prism::Token
This represents a token from the Ruby source.
Attributes
The Source
object that represents the source this token came from.
The type of token that this token is.
A byteslice of the source that this token represents.
Public Class Methods
Source
# File lib/prism/parse_result.rb, line 811 def initialize(source, type, value, location) @source = source @type = type @value = value @location = location end
Create a new token object with the given type, value, and location.
Public Instance Methods
Source
# File lib/prism/parse_result.rb, line 846 def ==(other) Token === other && other.type == type && other.value == value end
Returns true if the given other token is equal to this token.
Source
# File lib/prism/parse_result.rb, line 819 def deconstruct_keys(keys) { type: type, value: value, location: location } end
Implement the hash pattern matching interface for Token
.
Source
# File lib/prism/parse_result.rb, line 853 def inspect location super end
Returns a string representation of this token.
Calls superclass method
Source
# File lib/prism/parse_result.rb, line 824 def location location = @location return location if location.is_a?(Location) @location = Location.new(source, location >> 32, location & 0xFFFFFFFF) end
A Location
object representing the location of this token in the source.
Source
# File lib/prism/parse_result.rb, line 831 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
Implement the pretty print interface for Token
.