Class: SyntaxTree::UntilMod
- Inherits:
-
Object
- Object
- SyntaxTree::UntilMod
- Defined in:
- lib/syntax_tree.rb
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.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#predicate ⇒ Object
readonly
- untyped
-
the expression to be checked.
-
#statement ⇒ Object
readonly
- untyped
-
the expression to be executed.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(statement:, predicate:, location:, comments: []) ⇒ UntilMod
constructor
A new instance of UntilMod.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(statement:, predicate:, location:, comments: []) ⇒ UntilMod
Returns a new instance of UntilMod.
12566 12567 12568 12569 12570 12571 |
# File 'lib/syntax_tree.rb', line 12566 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
12564 12565 12566 |
# File 'lib/syntax_tree.rb', line 12564 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
12561 12562 12563 |
# File 'lib/syntax_tree.rb', line 12561 def location @location end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
12558 12559 12560 |
# File 'lib/syntax_tree.rb', line 12558 def predicate @predicate end |
#statement ⇒ Object (readonly)
- untyped
-
the expression to be executed
12555 12556 12557 |
# File 'lib/syntax_tree.rb', line 12555 def statement @statement end |
Instance Method Details
#child_nodes ⇒ Object
12573 12574 12575 |
# File 'lib/syntax_tree.rb', line 12573 def child_nodes [statement, predicate] end |
#format(q) ⇒ Object
12577 12578 12579 12580 12581 12582 12583 12584 12585 12586 12587 12588 12589 12590 12591 12592 12593 12594 |
# File 'lib/syntax_tree.rb', line 12577 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 # # The above is effectively a `do...until` loop. if statement.is_a?(Begin) q.format(statement) q.text(" until ") q.format(predicate) else LoopFormatter.new("until", self, statement).format(q) end end |
#pretty_print(q) ⇒ Object
12596 12597 12598 12599 12600 12601 12602 12603 12604 12605 12606 12607 12608 |
# File 'lib/syntax_tree.rb', line 12596 def pretty_print(q) q.group(2, "(", ")") do q.text("until_mod") q.breakable q.pp(statement) q.breakable q.pp(predicate) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
12610 12611 12612 12613 12614 12615 12616 12617 12618 |
# File 'lib/syntax_tree.rb', line 12610 def to_json(*opts) { type: :until_mod, stmt: statement, pred: predicate, loc: location, cmts: comments }.to_json(*opts) end |