Class: Prism::ParenthesesNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::ParenthesesNode
- Defined in:
- lib/prism/node.rb,
lib/prism/parse_result/newlines.rb,
sig/generated/prism/node.rbs,
sig/generated/prism/parse_result/newlines.rbs,
ext/prism/api_node.c
Overview
Class Method Summary collapse
-
.type ⇒ :parentheses_node
See
Node.type.
Instance Method Summary collapse
-
#===(other) ⇒ boolish
: (untyped other) -> boolish.
-
#accept(visitor) ⇒ Object
See Node.accept.
-
#body ⇒ Prism::node?
:call-seq: body -> Node | nil.
-
#child_nodes ⇒ Array[node?]
(also: #deconstruct)
See Node.child_nodes.
-
#closing ⇒ String
:call-seq: closing -> String.
-
#closing_loc ⇒ Location
:category: Locations :call-seq: closing_loc -> Location.
-
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
-
#copy(node_id: self.node_id, location: self.location, flags: self.flags, body: self.body, opening_loc: self.opening_loc, closing_loc: self.closing_loc) ⇒ ParenthesesNode
:call-seq: copy(**fields) -> ParenthesesNode.
-
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped].
-
#each_child_node {|arg0| ... } ⇒ Object
See Node.each_child_node.
-
#initialize(source, node_id, location, flags, body, opening_loc, closing_loc) ⇒ ParenthesesNode
constructor
Initialize a new ParenthesesNode node.
-
#inspect ⇒ String
: () -> String.
-
#multiple_statements? ⇒ Boolean
:category: Flags parentheses that contain multiple potentially void statements.
-
#newline_flag!(lines) ⇒ void
: (Array lines) -> void.
-
#opening ⇒ String
:call-seq: opening -> String.
-
#opening_loc ⇒ Location
:category: Locations :call-seq: opening_loc -> Location.
-
#save_closing_loc(repository) ⇒ Relocation::Entry
:category: Repository Save the closing_loc location using the given saved source so that it can be retrieved later.
-
#save_opening_loc(repository) ⇒ Relocation::Entry
:category: Repository Save the opening_loc location using the given saved source so that it can be retrieved later.
-
#type ⇒ :parentheses_node
See
Node#type.
Constructor Details
#initialize(source, node_id, location, flags, body, opening_loc, closing_loc) ⇒ ParenthesesNode
Initialize a new ParenthesesNode node.
: (Source source, Integer node_id, Location location, Integer flags, Prism::node? body, Location opening_loc, Location closing_loc) -> void
26310 26311 26312 26313 26314 26315 26316 26317 26318 |
# File 'lib/prism/node.rb', line 26310 def initialize(source, node_id, location, flags, body, opening_loc, closing_loc) @source = source @node_id = node_id @location = location @flags = flags @body = body @opening_loc = opening_loc @closing_loc = closing_loc end |
Class Method Details
.type ⇒ :parentheses_node
See Node.type.
: () -> :parentheses_node
26403 26404 26405 |
# File 'lib/prism/node.rb', line 26403 def self.type :parentheses_node end |
Instance Method Details
#===(other) ⇒ boolish
: (untyped other) -> boolish
26501 26502 26503 26504 26505 26506 26507 |
# File 'lib/prism/node.rb', line 26501 def ===(other) # :nodoc: other.is_a?(ParenthesesNode) && (flags === other.flags) && (body === other.body) && (opening_loc.nil? == other.opening_loc.nil?) && (closing_loc.nil? == other.closing_loc.nil?) end |
#accept(visitor) ⇒ Object
See Node.accept.
: (_Visitor visitor) -> untyped
26334 26335 26336 |
# File 'lib/prism/node.rb', line 26334 def accept(visitor) visitor.visit_parentheses_node(self) end |
#body ⇒ Prism::node?
:call-seq:
body -> Node | nil
Returns the body attribute.
: () -> Prism::node?
26428 26429 26430 |
# File 'lib/prism/node.rb', line 26428 def body @body end |
#child_nodes ⇒ Array[node?] Also known as: deconstruct
See Node.child_nodes.
: () -> Array
26341 26342 26343 |
# File 'lib/prism/node.rb', line 26341 def child_nodes [body] end |
#closing ⇒ String
:call-seq:
closing -> String
Slice the location of closing_loc from the source.
: () -> String
26494 26495 26496 |
# File 'lib/prism/node.rb', line 26494 def closing closing_loc.slice end |
#closing_loc ⇒ Location
:category: Locations :call-seq:
closing_loc -> Location
Returns the Location represented by closing_loc.
: () -> Location
26461 26462 26463 26464 26465 |
# File 'lib/prism/node.rb', line 26461 def closing_loc location = @closing_loc return location if location.is_a?(Location) @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
: () -> Array
26358 26359 26360 26361 26362 |
# File 'lib/prism/node.rb', line 26358 def compact_child_nodes compact = [] #: Array[Prism::node] if (body = self.body); compact << body; end compact end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, body: self.body, opening_loc: self.opening_loc, closing_loc: self.closing_loc) ⇒ ParenthesesNode
:call-seq:
copy(**fields) -> ParenthesesNode
Creates a copy of self with the given fields, using self as the template.
: (?node_id: Integer, ?location: Location, ?flags: Integer, ?body: Prism::node?, ?opening_loc: Location, ?closing_loc: Location) -> ParenthesesNode
26370 26371 26372 |
# File 'lib/prism/node.rb', line 26370 def copy(node_id: self.node_id, location: self.location, flags: self.flags, body: self.body, opening_loc: self.opening_loc, closing_loc: self.closing_loc) ParenthesesNode.new(source, node_id, location, flags, body, opening_loc, closing_loc) end |
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped]
26377 26378 26379 26380 26381 26382 26383 26384 26385 26386 26387 26388 26389 26390 26391 |
# File 'lib/prism/node.rb', line 26377 def deconstruct_keys(keys) # :nodoc: (keys || %i[node_id location body opening_loc closing_loc opening closing]).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 :body then deconstructed[:body] = self.body when :opening_loc then deconstructed[:opening_loc] = self.opening_loc when :closing_loc then deconstructed[:closing_loc] = self.closing_loc when :opening then deconstructed[:opening] = self.opening when :closing then deconstructed[:closing] = self.closing end end end |
#each_child_node ⇒ Enumerator[node, void] #each_child_node ⇒ void
See Node.each_child_node.
: () -> Enumerator[node, void] : () { (node) -> void } -> void
26349 26350 26351 26352 26353 |
# File 'lib/prism/node.rb', line 26349 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? if (body = self.body); yield body; end end |
#inspect ⇒ String
: () -> String
26408 26409 26410 |
# File 'lib/prism/node.rb', line 26408 def inspect # :nodoc: InspectVisitor.compose(self) end |
#multiple_statements? ⇒ Boolean
:category: Flags parentheses that contain multiple potentially void statements
: () -> bool
26418 26419 26420 |
# File 'lib/prism/node.rb', line 26418 def multiple_statements? flags.anybits?(ParenthesesNodeFlags::MULTIPLE_STATEMENTS) end |
#newline_flag!(lines) ⇒ void
This method returns an undefined value.
: (Array lines) -> void
236 237 238 |
# File 'lib/prism/parse_result/newlines.rb', line 236 def newline_flag!(lines) # :nodoc: # Never mark ParenthesesNode with a newline flag, mark children instead. end |
#opening ⇒ String
:call-seq:
opening -> String
Slice the location of opening_loc from the source.
: () -> String
26484 26485 26486 |
# File 'lib/prism/node.rb', line 26484 def opening opening_loc.slice end |
#opening_loc ⇒ Location
:category: Locations :call-seq:
opening_loc -> Location
Returns the Location represented by opening_loc.
: () -> Location
26439 26440 26441 26442 26443 |
# File 'lib/prism/node.rb', line 26439 def opening_loc location = @opening_loc return location if location.is_a?(Location) @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#save_closing_loc(repository) ⇒ Relocation::Entry
:category: Repository Save the closing_loc location using the given saved source so that it can be retrieved later.
: (_Repository repository) -> Relocation::Entry
26472 26473 26474 |
# File 'lib/prism/node.rb', line 26472 def save_closing_loc(repository) repository.enter(node_id, :closing_loc) end |
#save_opening_loc(repository) ⇒ Relocation::Entry
:category: Repository Save the opening_loc location using the given saved source so that it can be retrieved later.
: (_Repository repository) -> Relocation::Entry
26450 26451 26452 |
# File 'lib/prism/node.rb', line 26450 def save_opening_loc(repository) repository.enter(node_id, :opening_loc) end |
#type ⇒ :parentheses_node
See Node#type.
: () -> :parentheses_node
26396 26397 26398 |
# File 'lib/prism/node.rb', line 26396 def type :parentheses_node end |