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
10746 10747 10748 10749 10750 |
# File 'lib/syntax_tree/node.rb', line 10746 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
10738 10739 10740 |
# File 'lib/syntax_tree/node.rb', line 10738 def keyword @keyword end |
#node ⇒ Object (readonly)
- Until | UntilMod | While | WhileMod
-
the node that is being formatted
10741 10742 10743 |
# File 'lib/syntax_tree/node.rb', line 10741 def node @node end |
#statements ⇒ Object (readonly)
- untyped
-
the statements associated with the node
10744 10745 10746 |
# File 'lib/syntax_tree/node.rb', line 10744 def statements @statements end |
Instance Method Details
#format(q) ⇒ Object
10752 10753 10754 10755 10756 10757 10758 10759 10760 10761 10762 10763 10764 10765 10766 10767 10768 |
# File 'lib/syntax_tree/node.rb', line 10752 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 |