Class: SyntaxTree::LoopFormatter
- Inherits:
-
Object
- Object
- SyntaxTree::LoopFormatter
- Defined in:
- lib/syntax_tree/node.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.
8438 8439 8440 8441 8442 |
# File 'lib/syntax_tree/node.rb', line 8438 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
8430 8431 8432 |
# File 'lib/syntax_tree/node.rb', line 8430 def keyword @keyword end |
#node ⇒ Object (readonly)
- Until | UntilMod | While | WhileMod
-
the node that is being formatted
8433 8434 8435 |
# File 'lib/syntax_tree/node.rb', line 8433 def node @node end |
#statements ⇒ Object (readonly)
- untyped
-
the statements associated with the node
8436 8437 8438 |
# File 'lib/syntax_tree/node.rb', line 8436 def statements @statements end |
Instance Method Details
#format(q) ⇒ Object
8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 |
# File 'lib/syntax_tree/node.rb', line 8444 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 |