class Prism::Token

This represents a token from the Ruby source.

Attributes

location[R]

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

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(type, value, location) click to toggle source

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

# File prism/parse_result.rb, line 396
def initialize(type, value, location)
  @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 prism/parse_result.rb, line 423
def ==(other)
  other.is_a?(Token) &&
    other.type == type &&
    other.value == value
end
deconstruct_keys(keys) click to toggle source

Implement the hash pattern matching interface for Token.

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

Implement the pretty print interface for Token.

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