Class: Prism::ErrorRecoveryNode

Inherits:
PrismNode
  • Object
show all
Defined in:
lib/prism/node.rb,
sig/generated/prism/node.rbs,
ext/prism/api_node.c

Overview

Represents a node that is either missing or unexpected and results in a syntax error.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, unexpected) ⇒ ErrorRecoveryNode

Initialize a new ErrorRecoveryNode node.

: (Source source, Integer node_id, Location location, Integer flags, Prism::node? unexpected) -> void

Parameters:

  • source (Source)
  • node_id (Integer)
  • location (Location)
  • flags (Integer)
  • unexpected (Prism::node, nil)


12254
12255
12256
12257
12258
12259
12260
# File 'lib/prism/node.rb', line 12254

def initialize(source, node_id, location, flags, unexpected)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @unexpected = unexpected
end

Class Method Details

.type ⇒ :error_recovery_node

See Node.type.

: () -> :error_recovery_node

Returns:

  • (:error_recovery_node)


12341
12342
12343
# File 'lib/prism/node.rb', line 12341

def self.type
  :error_recovery_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


12367
12368
12369
12370
# File 'lib/prism/node.rb', line 12367

def ===(other) # :nodoc:
  other.is_a?(ErrorRecoveryNode) &&
    (unexpected === other.unexpected)
end

#accept(visitor) ⇒ Object

See Node.accept.

: (_Visitor visitor) -> untyped

Parameters:

Returns:

  • (Object)


12276
12277
12278
# File 'lib/prism/node.rb', line 12276

def accept(visitor)
  visitor.visit_error_recovery_node(self)
end

#child_nodes ⇒ Array[node?] Also known as: deconstruct

See Node.child_nodes.

: () -> Array

Returns:

  • (Array[node?])


12283
12284
12285
# File 'lib/prism/node.rb', line 12283

def child_nodes
  [unexpected]
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


12300
12301
12302
12303
12304
# File 'lib/prism/node.rb', line 12300

def compact_child_nodes
  compact = [] #: Array[Prism::node]
  if (unexpected = self.unexpected); compact << unexpected; end
  compact
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, unexpected: self.unexpected) ⇒ ErrorRecoveryNode

:call-seq:

copy(**fields) -> ErrorRecoveryNode

Creates a copy of self with the given fields, using self as the template.

: (?node_id: Integer, ?location: Location, ?flags: Integer, ?unexpected: Prism::node?) -> ErrorRecoveryNode

Parameters:

  • node_id: (Integer) (defaults to: self.node_id)
  • location: (Location) (defaults to: self.location)
  • flags: (Integer) (defaults to: self.flags)
  • unexpected: (Prism::node, nil) (defaults to: self.unexpected)

Returns:



12312
12313
12314
# File 'lib/prism/node.rb', line 12312

def copy(node_id: self.node_id, location: self.location, flags: self.flags, unexpected: self.unexpected)
  ErrorRecoveryNode.new(source, node_id, location, flags, unexpected)
end

#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]

: (Array? keys) -> Hash[Symbol, untyped]

Parameters:

  • keys (Array[Symbol], nil)

Returns:

  • (Hash[Symbol, untyped])


12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
# File 'lib/prism/node.rb', line 12319

def deconstruct_keys(keys) # :nodoc:
  (keys || %i[node_id location unexpected]).each_with_object(
    {} #: Hash[Symbol, untyped]
  ) do |key, deconstructed|
    case key
    when :node_id                 then deconstructed[:node_id] = self.node_id
    when :location                then deconstructed[:location] = self.location
    when :unexpected              then deconstructed[:unexpected] = self.unexpected
    end
  end
end

#each_child_node ⇒ Enumerator[node, void] #each_child_node ⇒ void

See Node.each_child_node.

: () -> Enumerator[node, void] : () { (node) -> void } -> void

Overloads:

  • #each_child_node ⇒ Enumerator[node, void]

    Returns:

    • (Enumerator[node, void])
  • #each_child_node ⇒ void

    This method returns an undefined value.

Yields:

Yield Parameters:

  • arg0 (node)

Yield Returns:

  • (void)


12291
12292
12293
12294
12295
# File 'lib/prism/node.rb', line 12291

def each_child_node(&blk)
  return to_enum(:each_child_node) unless block_given?

  if (unexpected = self.unexpected); yield unexpected; end
end

#inspect ⇒ String

: () -> String

Returns:

  • (String)


12346
12347
12348
# File 'lib/prism/node.rb', line 12346

def inspect # :nodoc:
  InspectVisitor.compose(self)
end

#type ⇒ :error_recovery_node

See Node#type.

: () -> :error_recovery_node

Returns:

  • (:error_recovery_node)


12334
12335
12336
# File 'lib/prism/node.rb', line 12334

def type
  :error_recovery_node
end

#unexpected ⇒ Prism::node?

:call-seq:

unexpected -> Node | nil

The unexpected node that was found in the tree, if there was one.

: () -> Prism::node?

Returns:

  • (Prism::node, nil)


12358
12359
12360
# File 'lib/prism/node.rb', line 12358

def unexpected
  @unexpected
end