Class: SyntaxTree::LoopFormatter
- Inherits:
-
Object
- Object
- SyntaxTree::LoopFormatter
- Defined in:
- lib/syntax_tree.rb
Overview
Formats an Until, UntilMod, While, or WhileMod node.
Instance Attribute Summary collapse
-
#keyword ⇒ Object
readonly
- String
-
the name of the keyword used for this loop.
-
#node ⇒ Object
readonly
- Until | UntilMod | While | WhileMod
-
the node that is being formatted.
-
#statements ⇒ Object
readonly
- untyped
-
the statements associated with the node.
Instance Method Summary collapse
- #format(q) ⇒ Object
-
#initialize(keyword, node, statements) ⇒ LoopFormatter
constructor
A new instance of LoopFormatter.
Constructor Details
#initialize(keyword, node, statements) ⇒ LoopFormatter
Returns a new instance of LoopFormatter.
12494 12495 12496 12497 12498 |
# File 'lib/syntax_tree.rb', line 12494 def initialize(keyword, node, statements) @keyword = keyword @node = node @statements = statements end |
Instance Attribute Details
#keyword ⇒ Object (readonly)
- String
-
the name of the keyword used for this loop
12486 12487 12488 |
# File 'lib/syntax_tree.rb', line 12486 def keyword @keyword end |
#node ⇒ Object (readonly)
- Until | UntilMod | While | WhileMod
-
the node that is being formatted
12489 12490 12491 |
# File 'lib/syntax_tree.rb', line 12489 def node @node end |
#statements ⇒ Object (readonly)
- untyped
-
the statements associated with the node
12492 12493 12494 |
# File 'lib/syntax_tree.rb', line 12492 def statements @statements end |
Instance Method Details
#format(q) ⇒ Object
12500 12501 12502 12503 12504 12505 12506 12507 12508 12509 12510 12511 12512 12513 12514 12515 12516 |
# File 'lib/syntax_tree.rb', line 12500 def format(q) if ContainsAssignment.call(node.predicate) format_break(q) q.break_parent return end q.group do q.if_break { format_break(q) }.if_flat do Parentheses.flat(q) do q.format(statements) q.text(" #{keyword} ") q.format(node.predicate) end end end end |