Class: Prism::InterpolatedXStringNode

Inherits:
PrismNode
  • Object
show all
Defined in:
lib/prism/node.rb,
lib/prism/node_ext.rb,
lib/prism/parse_result/newlines.rb,
ext/prism/api_node.c

Overview

Represents an xstring literal that contains interpolation.

`foo #{bar} baz`
^^^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, opening_loc, parts, closing_loc) ⇒ InterpolatedXStringNode

Initialize a new InterpolatedXStringNode node.



11085
11086
11087
11088
11089
11090
11091
11092
11093
# File 'lib/prism/node.rb', line 11085

def initialize(source, node_id, location, flags, opening_loc, parts, closing_loc)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @opening_loc = opening_loc
  @parts = parts
  @closing_loc = closing_loc
end

Instance Attribute Details

#partsObject (readonly)

attr_reader parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode]



11142
11143
11144
# File 'lib/prism/node.rb', line 11142

def parts
  @parts
end

Class Method Details

.typeObject

Return a symbol representation of this node type. See ‘Node::type`.



11178
11179
11180
# File 'lib/prism/node.rb', line 11178

def self.type
  :interpolated_x_string_node
end

Instance Method Details

#===(other) ⇒ Object

Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.



11184
11185
11186
11187
11188
11189
11190
# File 'lib/prism/node.rb', line 11184

def ===(other)
  other.is_a?(InterpolatedXStringNode) &&
    (opening_loc.nil? == other.opening_loc.nil?) &&
    (parts.length == other.parts.length) &&
    parts.zip(other.parts).all? { |left, right| left === right } &&
    (closing_loc.nil? == other.closing_loc.nil?)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



11096
11097
11098
# File 'lib/prism/node.rb', line 11096

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

#child_nodesObject Also known as: deconstruct

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



11101
11102
11103
# File 'lib/prism/node.rb', line 11101

def child_nodes
  [*parts]
end

#closingObject

def closing: () -> String



11163
11164
11165
# File 'lib/prism/node.rb', line 11163

def closing
  closing_loc.slice
end

#closing_locObject

attr_reader closing_loc: Location



11145
11146
11147
11148
11149
# File 'lib/prism/node.rb', line 11145

def closing_loc
  location = @closing_loc
  return location if location.is_a?(Location)
  @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#comment_targetsObject

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



11111
11112
11113
# File 'lib/prism/node.rb', line 11111

def comment_targets
  [opening_loc, *parts, closing_loc] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



11106
11107
11108
# File 'lib/prism/node.rb', line 11106

def compact_child_nodes
  [*parts]
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, parts: self.parts, closing_loc: self.closing_loc) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?opening_loc: Location, ?parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode], ?closing_loc: Location) -> InterpolatedXStringNode



11116
11117
11118
# File 'lib/prism/node.rb', line 11116

def copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, parts: self.parts, closing_loc: self.closing_loc)
  InterpolatedXStringNode.new(source, node_id, location, flags, opening_loc, parts, closing_loc)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, opening_loc: Location, parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode], closing_loc: Location }



11124
11125
11126
# File 'lib/prism/node.rb', line 11124

def deconstruct_keys(keys)
  { node_id: node_id, location: location, opening_loc: opening_loc, parts: parts, closing_loc: closing_loc }
end

#inspectObject

def inspect -> String



11168
11169
11170
# File 'lib/prism/node.rb', line 11168

def inspect
  InspectVisitor.compose(self)
end

#newline_flag!(lines) ⇒ Object

:nodoc:



149
150
151
152
# File 'lib/prism/parse_result/newlines.rb', line 149

def newline_flag!(lines) # :nodoc:
  first = parts.first
  first.newline_flag!(lines) if first
end

#openingObject

def opening: () -> String



11158
11159
11160
# File 'lib/prism/node.rb', line 11158

def opening
  opening_loc.slice
end

#opening_locObject

attr_reader opening_loc: Location



11129
11130
11131
11132
11133
# File 'lib/prism/node.rb', line 11129

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) ⇒ Object

Save the closing_loc location using the given saved source so that it can be retrieved later.



11153
11154
11155
# File 'lib/prism/node.rb', line 11153

def save_closing_loc(repository)
  repository.enter(node_id, :closing_loc)
end

#save_opening_loc(repository) ⇒ Object

Save the opening_loc location using the given saved source so that it can be retrieved later.



11137
11138
11139
# File 'lib/prism/node.rb', line 11137

def save_opening_loc(repository)
  repository.enter(node_id, :opening_loc)
end

#typeObject

Return a symbol representation of this node type. See ‘Node#type`.



11173
11174
11175
# File 'lib/prism/node.rb', line 11173

def type
  :interpolated_x_string_node
end