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.
12474 12475 12476 12477 12478 12479 |
# File 'lib/syntax_tree.rb', line 12474 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
12472 12473 12474 |
# File 'lib/syntax_tree.rb', line 12472 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
12469 12470 12471 |
# File 'lib/syntax_tree.rb', line 12469 def location @location end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
12463 12464 12465 |
# File 'lib/syntax_tree.rb', line 12463 def predicate @predicate end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
12466 12467 12468 |
# File 'lib/syntax_tree.rb', line 12466 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object
12481 12482 12483 |
# File 'lib/syntax_tree.rb', line 12481 def child_nodes [predicate, statements] end |
#format(q) ⇒ Object
12485 12486 12487 12488 12489 12490 12491 12492 12493 12494 12495 12496 12497 12498 |
# File 'lib/syntax_tree.rb', line 12485 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
12500 12501 12502 12503 12504 12505 12506 12507 12508 12509 12510 12511 12512 |
# File 'lib/syntax_tree.rb', line 12500 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
12514 12515 12516 12517 12518 12519 12520 12521 12522 |
# File 'lib/syntax_tree.rb', line 12514 def to_json(*opts) { type: :until, pred: predicate, stmts: statements, loc: location, cmts: comments }.to_json(*opts) end |