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.
11910 11911 11912 11913 11914 |
# File 'lib/syntax_tree.rb', line 11910 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
11902 11903 11904 |
# File 'lib/syntax_tree.rb', line 11902 def keyword @keyword end |
#node ⇒ Object (readonly)
- Until | UntilMod | While | WhileMod
-
the node that is being formatted
11905 11906 11907 |
# File 'lib/syntax_tree.rb', line 11905 def node @node end |
#statements ⇒ Object (readonly)
- untyped
-
the statements associated with the node
11908 11909 11910 |
# File 'lib/syntax_tree.rb', line 11908 def statements @statements end |
Instance Method Details
#format(q) ⇒ Object
11916 11917 11918 11919 11920 11921 11922 11923 11924 11925 11926 11927 11928 11929 11930 11931 11932 11933 |
# File 'lib/syntax_tree.rb', line 11916 def format(q) q.group do q.if_break do q.text("#{keyword} ") q.nest(keyword.length + 1) { q.format(node.predicate) } q.indent do q.breakable("") q.format(statements) end q.breakable("") q.text("end") end.if_flat do q.format(statements) q.text(" #{keyword} ") q.format(node.predicate) end end end |