Class: SyntaxTree::Until
- Inherits:
-
Object
- Object
- SyntaxTree::Until
- Defined in:
- lib/syntax_tree.rb
Overview
Until represents an until
loop.
until predicate
end
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.
-
#statements ⇒ Object
readonly
- Statements
-
the expressions to be executed.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(predicate:, statements:, location:, comments: []) ⇒ Until
constructor
A new instance of Until.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(predicate:, statements:, location:, comments: []) ⇒ Until
Returns a new instance of Until.
12550 12551 12552 12553 12554 12555 |
# File 'lib/syntax_tree.rb', line 12550 def initialize(predicate:, statements:, location:, comments: []) @predicate = predicate @statements = statements @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
12548 12549 12550 |
# File 'lib/syntax_tree.rb', line 12548 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
12545 12546 12547 |
# File 'lib/syntax_tree.rb', line 12545 def location @location end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
12539 12540 12541 |
# File 'lib/syntax_tree.rb', line 12539 def predicate @predicate end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
12542 12543 12544 |
# File 'lib/syntax_tree.rb', line 12542 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object
12557 12558 12559 |
# File 'lib/syntax_tree.rb', line 12557 def child_nodes [predicate, statements] end |
#format(q) ⇒ Object
12561 12562 12563 12564 12565 12566 12567 12568 12569 12570 12571 12572 12573 12574 |
# File 'lib/syntax_tree.rb', line 12561 def format(q) if statements.empty? keyword = "until " q.group do q.text(keyword) q.nest(keyword.length) { q.format(predicate) } q.breakable(force: true) q.text("end") end else LoopFormatter.new("until", self, statements).format(q) end end |
#pretty_print(q) ⇒ Object
12576 12577 12578 12579 12580 12581 12582 12583 12584 12585 12586 12587 12588 |
# File 'lib/syntax_tree.rb', line 12576 def pretty_print(q) q.group(2, "(", ")") do q.text("until") q.breakable q.pp(predicate) q.breakable q.pp(statements) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
12590 12591 12592 12593 12594 12595 12596 12597 12598 |
# File 'lib/syntax_tree.rb', line 12590 def to_json(*opts) { type: :until, pred: predicate, stmts: statements, loc: location, cmts: comments }.to_json(*opts) end |