Class: YARP::PostExecutionNode

Inherits:
YARPNode
  • Object
show all
Defined in:
lib/yarp/node.rb,
ext/yarp/api_node.c

Overview

Represents the use of the ‘END` keyword.

END { foo }
^^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(statements, keyword_loc, opening_loc, closing_loc, location) ⇒ PostExecutionNode

def initialize: (statements: StatementsNode?, keyword_loc: Location, opening_loc: Location, closing_loc: Location, location: Location) -> void



8087
8088
8089
8090
8091
8092
8093
# File 'lib/yarp/node.rb', line 8087

def initialize(statements, keyword_loc, opening_loc, closing_loc, location)
  @statements = statements
  @keyword_loc = keyword_loc
  @opening_loc = opening_loc
  @closing_loc = closing_loc
  @location = location
end

Instance Attribute Details

#closing_locObject (readonly)

attr_reader closing_loc: Location



8084
8085
8086
# File 'lib/yarp/node.rb', line 8084

def closing_loc
  @closing_loc
end

#keyword_locObject (readonly)

attr_reader keyword_loc: Location



8078
8079
8080
# File 'lib/yarp/node.rb', line 8078

def keyword_loc
  @keyword_loc
end

#opening_locObject (readonly)

attr_reader opening_loc: Location



8081
8082
8083
# File 'lib/yarp/node.rb', line 8081

def opening_loc
  @opening_loc
end

#statementsObject (readonly)

attr_reader statements: StatementsNode?



8075
8076
8077
# File 'lib/yarp/node.rb', line 8075

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



8096
8097
8098
# File 'lib/yarp/node.rb', line 8096

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



8101
8102
8103
# File 'lib/yarp/node.rb', line 8101

def child_nodes
  [statements]
end

#closingObject

def closing: () -> String



8140
8141
8142
# File 'lib/yarp/node.rb', line 8140

def closing
  closing_loc.slice
end

#comment_targetsObject

def comment_targets: () -> Array[Node | Location]



8106
8107
8108
# File 'lib/yarp/node.rb', line 8106

def comment_targets
  [*statements, keyword_loc, opening_loc, closing_loc]
end

#copy(**params) ⇒ Object

def copy: (**params) -> PostExecutionNode



8111
8112
8113
8114
8115
8116
8117
8118
8119
# File 'lib/yarp/node.rb', line 8111

def copy(**params)
  PostExecutionNode.new(
    params.fetch(:statements) { statements },
    params.fetch(:keyword_loc) { keyword_loc },
    params.fetch(:opening_loc) { opening_loc },
    params.fetch(:closing_loc) { closing_loc },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array | String | Token | Array | Location]



8125
8126
8127
# File 'lib/yarp/node.rb', line 8125

def deconstruct_keys(keys)
  { statements: statements, keyword_loc: keyword_loc, opening_loc: opening_loc, closing_loc: closing_loc, location: location }
end

#inspect(inspector = NodeInspector.new) ⇒ Object



8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
# File 'lib/yarp/node.rb', line 8144

def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  if (statements = self.statements).nil?
    inspector << "├── statements: ∅\n"
  else
    inspector << "├── statements:\n"
    inspector << statements.inspect(inspector.child_inspector("│   ")).delete_prefix(inspector.prefix)
  end
  inspector << "├── keyword_loc: #{inspector.location(keyword_loc)}\n"
  inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n"
  inspector << "└── closing_loc: #{inspector.location(closing_loc)}\n"
  inspector.to_str
end

#keywordObject

def keyword: () -> String



8130
8131
8132
# File 'lib/yarp/node.rb', line 8130

def keyword
  keyword_loc.slice
end

#openingObject

def opening: () -> String



8135
8136
8137
# File 'lib/yarp/node.rb', line 8135

def opening
  opening_loc.slice
end