Class: Prism::UntilNode

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

Overview

Represents the use of the ‘until` keyword, either in the block form or the modifier form.

bar until foo
^^^^^^^^^^^^^

until foo do bar end
^^^^^^^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, keyword_loc, closing_loc, predicate, statements) ⇒ UntilNode

Initialize a new UntilNode node.



16071
16072
16073
16074
16075
16076
16077
16078
16079
16080
# File 'lib/prism/node.rb', line 16071

def initialize(source, node_id, location, flags, keyword_loc, closing_loc, predicate, statements)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @keyword_loc = keyword_loc
  @closing_loc = closing_loc
  @predicate = predicate
  @statements = statements
end

Instance Attribute Details

#predicateObject (readonly)

attr_reader predicate: Prism::node



16144
16145
16146
# File 'lib/prism/node.rb', line 16144

def predicate
  @predicate
end

#statementsObject (readonly)

attr_reader statements: StatementsNode?



16147
16148
16149
# File 'lib/prism/node.rb', line 16147

def statements
  @statements
end

Class Method Details

.typeObject

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



16170
16171
16172
# File 'lib/prism/node.rb', line 16170

def self.type
  :until_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.



16176
16177
16178
16179
16180
16181
16182
16183
# File 'lib/prism/node.rb', line 16176

def ===(other)
  other.is_a?(UntilNode) &&
    (flags === other.flags) &&
    (keyword_loc.nil? == other.keyword_loc.nil?) &&
    (closing_loc.nil? == other.closing_loc.nil?) &&
    (predicate === other.predicate) &&
    (statements === other.statements)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



16083
16084
16085
# File 'lib/prism/node.rb', line 16083

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

#begin_modifier?Boolean

def begin_modifier?: () -> bool

Returns:

  • (Boolean)


16119
16120
16121
# File 'lib/prism/node.rb', line 16119

def begin_modifier?
  flags.anybits?(LoopFlags::BEGIN_MODIFIER)
end

#child_nodesObject Also known as: deconstruct

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



16088
16089
16090
# File 'lib/prism/node.rb', line 16088

def child_nodes
  [predicate, statements]
end

#closingObject

def closing: () -> String?



16155
16156
16157
# File 'lib/prism/node.rb', line 16155

def closing
  closing_loc&.slice
end

#closing_locObject

attr_reader closing_loc: Location?



16131
16132
16133
16134
16135
16136
16137
16138
16139
16140
16141
# File 'lib/prism/node.rb', line 16131

def closing_loc
  location = @closing_loc
  case location
  when nil
    nil
  when Location
    location
  else
    @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
  end
end

#comment_targetsObject

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



16101
16102
16103
# File 'lib/prism/node.rb', line 16101

def comment_targets
  [keyword_loc, *closing_loc, predicate, *statements] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



16093
16094
16095
16096
16097
16098
# File 'lib/prism/node.rb', line 16093

def compact_child_nodes
  compact = [] #: Array[Prism::node]
  compact << predicate
  compact << statements if statements
  compact
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, closing_loc: self.closing_loc, predicate: self.predicate, statements: self.statements) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?closing_loc: Location?, ?predicate: Prism::node, ?statements: StatementsNode?) -> UntilNode



16106
16107
16108
# File 'lib/prism/node.rb', line 16106

def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, closing_loc: self.closing_loc, predicate: self.predicate, statements: self.statements)
  UntilNode.new(source, node_id, location, flags, keyword_loc, closing_loc, predicate, statements)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, keyword_loc: Location, closing_loc: Location?, predicate: Prism::node, statements: StatementsNode? }



16114
16115
16116
# File 'lib/prism/node.rb', line 16114

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

#inspectObject

def inspect -> String



16160
16161
16162
# File 'lib/prism/node.rb', line 16160

def inspect
  InspectVisitor.compose(self)
end

#keywordObject

def keyword: () -> String



16150
16151
16152
# File 'lib/prism/node.rb', line 16150

def keyword
  keyword_loc.slice
end

#keyword_locObject

attr_reader keyword_loc: Location



16124
16125
16126
16127
16128
# File 'lib/prism/node.rb', line 16124

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

#newline_flag!(lines) ⇒ Object

:nodoc:



103
104
105
# File 'lib/prism/parse_result/newlines.rb', line 103

def newline_flag!(lines) # :nodoc:
  predicate.newline_flag!(lines)
end

#typeObject

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



16165
16166
16167
# File 'lib/prism/node.rb', line 16165

def type
  :until_node
end