Class
This represents a token from the Ruby source.
Attributes
Read
The type of token that this token is.
Read
A byteslice of the source that this token represents.
Class Methods
lib/prism/parse_result.rb
View on GitHub
# File tmp/rubies/ruby-3.3.0/lib/prism/parse_result.rb, line 427
def initialize(type, value, location)
@type = type
@value = value
@location = location
end
Create a new token object with the given type, value, and location.
Instance Methods
lib/prism/parse_result.rb
View on GitHub
# File tmp/rubies/ruby-3.3.0/lib/prism/parse_result.rb, line 454
def ==(other)
other.is_a?(Token) &&
other.type == type &&
other.value == value
end
Returns true if the given other token is equal to this token.
lib/prism/parse_result.rb
View on GitHub
# File tmp/rubies/ruby-3.3.0/lib/prism/parse_result.rb, line 434
def deconstruct_keys(keys)
{ type: type, value: value, location: location }
end
Implement the hash pattern matching interface for Token
.
lib/prism/parse_result.rb
View on GitHub
# File tmp/rubies/ruby-3.3.0/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
Implement the pretty print interface for Token
.