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
9615 9616 9617 9618 9619 9620 |
# File 'lib/syntax_tree/node.rb', line 9615 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
9613 9614 9615 |
# File 'lib/syntax_tree/node.rb', line 9613 def comments @comments end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
9610 9611 9612 |
# File 'lib/syntax_tree/node.rb', line 9610 def predicate @predicate end |
#statement ⇒ Object (readonly)
- untyped
-
the expression to be executed
9607 9608 9609 |
# File 'lib/syntax_tree/node.rb', line 9607 def statement @statement end |
Instance Method Details
#accept(visitor) ⇒ Object
9622 9623 9624 |
# File 'lib/syntax_tree/node.rb', line 9622 def accept(visitor) visitor.visit_until_mod(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
9626 9627 9628 |
# File 'lib/syntax_tree/node.rb', line 9626 def child_nodes [statement, predicate] end |
#deconstruct_keys(_keys) ⇒ Object
9632 9633 9634 9635 9636 9637 9638 9639 |
# File 'lib/syntax_tree/node.rb', line 9632 def deconstruct_keys(_keys) { statement: statement, predicate: predicate, location: location, comments: comments } end |
#format(q) ⇒ Object
9641 9642 9643 9644 9645 9646 9647 9648 9649 9650 9651 9652 9653 9654 9655 9656 9657 9658 9659 9660 9661 9662 9663 |
# File 'lib/syntax_tree/node.rb', line 9641 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 |