Class: Prism::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/prism/parse_result.rb,
ext/prism/extension.c

Overview

This represents a token from the Ruby source.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, value, location) ⇒ Token

Returns a new instance of Token.



236
237
238
239
240
# File 'lib/prism/parse_result.rb', line 236

def initialize(type, value, location)
  @type = type
  @value = value
  @location = location
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



234
235
236
# File 'lib/prism/parse_result.rb', line 234

def location
  @location
end

#typeObject (readonly)

Returns the value of attribute type.



234
235
236
# File 'lib/prism/parse_result.rb', line 234

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



234
235
236
# File 'lib/prism/parse_result.rb', line 234

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



260
261
262
263
264
# File 'lib/prism/parse_result.rb', line 260

def ==(other)
  other.is_a?(Token) &&
    other.type == type &&
    other.value == value
end

#deconstruct_keys(keys) ⇒ Object



242
243
244
# File 'lib/prism/parse_result.rb', line 242

def deconstruct_keys(keys)
  { type: type, value: value, location: location }
end

#pretty_print(q) ⇒ Object



246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/prism/parse_result.rb', line 246

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