Class: SyntaxTree::UntilMod
Overview
UntilMod represents the modifier form of a until loop.
expression until predicate
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#predicate ⇒ Object
readonly
- untyped
-
the expression to be checked.
-
#statement ⇒ Object
readonly
- untyped
-
the expression to be executed.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(statement:, predicate:, location:, comments: []) ⇒ UntilMod
constructor
A new instance of UntilMod.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(statement:, predicate:, location:, comments: []) ⇒ UntilMod
Returns a new instance of UntilMod.
9398 9399 9400 9401 9402 9403 |
# File 'lib/syntax_tree/node.rb', line 9398 def initialize(statement:, predicate:, location:, comments: []) @statement = statement @predicate = predicate @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
9396 9397 9398 |
# File 'lib/syntax_tree/node.rb', line 9396 def comments @comments end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
9393 9394 9395 |
# File 'lib/syntax_tree/node.rb', line 9393 def predicate @predicate end |
#statement ⇒ Object (readonly)
- untyped
-
the expression to be executed
9390 9391 9392 |
# File 'lib/syntax_tree/node.rb', line 9390 def statement @statement end |
Instance Method Details
#accept(visitor) ⇒ Object
9405 9406 9407 |
# File 'lib/syntax_tree/node.rb', line 9405 def accept(visitor) visitor.visit_until_mod(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
9409 9410 9411 |
# File 'lib/syntax_tree/node.rb', line 9409 def child_nodes [statement, predicate] end |
#deconstruct_keys(_keys) ⇒ Object
9415 9416 9417 9418 9419 9420 9421 9422 |
# File 'lib/syntax_tree/node.rb', line 9415 def deconstruct_keys(_keys) { statement: statement, predicate: predicate, location: location, comments: comments } end |
#format(q) ⇒ Object
9424 9425 9426 9427 9428 9429 9430 9431 9432 9433 9434 9435 9436 9437 9438 9439 9440 9441 9442 9443 9444 9445 9446 |
# File 'lib/syntax_tree/node.rb', line 9424 def format(q) # If we're in the modifier form and we're modifying a `begin`, then this # is a special case where we need to explicitly use the modifier form # because otherwise the semantic meaning changes. This looks like: # # begin # foo # end until bar # # Also, if the statement of the modifier includes an assignment, then we # can't know for certain that it won't impact the predicate, so we need to # force it to stay as it is. This looks like: # # foo = bar until foo # if statement.is_a?(Begin) || ContainsAssignment.call(statement) q.format(statement) q.text(" until ") q.format(predicate) else LoopFormatter.new("until", self, statement).format(q) end end |