Class: YARP::UntilNode

Inherits:
YARPNode
  • Object
show all
Defined in:
lib/yarp/node.rb,
ext/yarp/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

Instance Method Summary collapse

Constructor Details

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

def initialize: (keyword_loc: Location, closing_loc: Location?, predicate: Node, statements: StatementsNode?, flags: Integer, location: Location) -> void



10122
10123
10124
10125
10126
10127
10128
10129
# File 'lib/yarp/node.rb', line 10122

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

Instance Attribute Details

#closing_locObject (readonly)

attr_reader closing_loc: Location?



10110
10111
10112
# File 'lib/yarp/node.rb', line 10110

def closing_loc
  @closing_loc
end

#flagsObject (readonly)

attr_reader flags: Integer



10119
10120
10121
# File 'lib/yarp/node.rb', line 10119

def flags
  @flags
end

#keyword_locObject (readonly)

attr_reader keyword_loc: Location



10107
10108
10109
# File 'lib/yarp/node.rb', line 10107

def keyword_loc
  @keyword_loc
end

#predicateObject (readonly)

attr_reader predicate: Node



10113
10114
10115
# File 'lib/yarp/node.rb', line 10113

def predicate
  @predicate
end

#statementsObject (readonly)

attr_reader statements: StatementsNode?



10116
10117
10118
# File 'lib/yarp/node.rb', line 10116

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



10132
10133
10134
# File 'lib/yarp/node.rb', line 10132

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

#begin_modifier?Boolean

def begin_modifier?: () -> bool

Returns:

  • (Boolean)


10181
10182
10183
# File 'lib/yarp/node.rb', line 10181

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

#child_nodesObject Also known as: deconstruct

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



10141
10142
10143
# File 'lib/yarp/node.rb', line 10141

def child_nodes
  [predicate, statements]
end

#closingObject

def closing: () -> String?



10176
10177
10178
# File 'lib/yarp/node.rb', line 10176

def closing
  closing_loc&.slice
end

#comment_targetsObject

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



10146
10147
10148
# File 'lib/yarp/node.rb', line 10146

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

#copy(**params) ⇒ Object

def copy: (**params) -> UntilNode



10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
# File 'lib/yarp/node.rb', line 10151

def copy(**params)
  UntilNode.new(
    params.fetch(:keyword_loc) { keyword_loc },
    params.fetch(:closing_loc) { closing_loc },
    params.fetch(:predicate) { predicate },
    params.fetch(:statements) { statements },
    params.fetch(:flags) { flags },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

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



10166
10167
10168
# File 'lib/yarp/node.rb', line 10166

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

#inspect(inspector = NodeInspector.new) ⇒ Object



10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
# File 'lib/yarp/node.rb', line 10185

def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  inspector << "├── keyword_loc: #{inspector.location(keyword_loc)}\n"
  inspector << "├── closing_loc: #{inspector.location(closing_loc)}\n"
  inspector << "├── predicate:\n"
  inspector << inspector.child_node(predicate, "")
  if (statements = self.statements).nil?
    inspector << "├── statements: ∅\n"
  else
    inspector << "├── statements:\n"
    inspector << statements.inspect(inspector.child_inspector("")).delete_prefix(inspector.prefix)
  end
  inspector << "└── flags: #{[("begin_modifier" if begin_modifier?)].compact.join(", ")}\n"
  inspector.to_str
end

#keywordObject

def keyword: () -> String



10171
10172
10173
# File 'lib/yarp/node.rb', line 10171

def keyword
  keyword_loc.slice
end

#set_newline_flag(newline_marked) ⇒ Object



10136
10137
10138
# File 'lib/yarp/node.rb', line 10136

def set_newline_flag(newline_marked)
  predicate.set_newline_flag(newline_marked)
end