class Prism::Token

This represents a token from the Ruby source.

Attributes

source[R]

The Source object that represents the source this token came from.

type[R]

The type of token that this token is.

value[R]

A byteslice of the source that this token represents.

Public Class Methods

new(source, type, value, location) click to toggle source

Create a new token object with the given type, value, and location.

# File lib/prism/parse_result.rb, line 577
def initialize(source, type, value, location)
  @source = source
  @type = type
  @value = value
  @location = location
end

Public Instance Methods

==(other) click to toggle source

Returns true if the given other token is equal to this token.

# File lib/prism/parse_result.rb, line 612
def ==(other)
  Token === other &&
    other.type == type &&
    other.value == value
end
deconstruct_keys(keys) click to toggle source

Implement the hash pattern matching interface for Token.

# File lib/prism/parse_result.rb, line 585
def deconstruct_keys(keys)
  { type: type, value: value, location: location }
end
location() click to toggle source

A Location object representing the location of this token in the source.

# File lib/prism/parse_result.rb, line 590
def location
  location = @location
  return location if location.is_a?(Location)
  @location = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end
pretty_print(q) click to toggle source

Implement the pretty print interface for Token.

# File lib/prism/parse_result.rb, line 597
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