Class: SyntaxTree::FlowControlFormatter
- Inherits:
-
Object
- Object
- SyntaxTree::FlowControlFormatter
- Defined in:
- lib/syntax_tree.rb
Overview
Formats either a Break or Next node.
Instance Attribute Summary collapse
-
#keyword ⇒ Object
readonly
- String
-
the keyword to print.
-
#node ⇒ Object
readonly
- Break | Next
-
the node being formatted.
Instance Method Summary collapse
- #format(q) ⇒ Object
-
#initialize(keyword, node) ⇒ FlowControlFormatter
constructor
A new instance of FlowControlFormatter.
Constructor Details
#initialize(keyword, node) ⇒ FlowControlFormatter
Returns a new instance of FlowControlFormatter.
3171 3172 3173 3174 |
# File 'lib/syntax_tree.rb', line 3171 def initialize(keyword, node) @keyword = keyword @node = node end |
Instance Attribute Details
#keyword ⇒ Object (readonly)
- String
-
the keyword to print
3166 3167 3168 |
# File 'lib/syntax_tree.rb', line 3166 def keyword @keyword end |
#node ⇒ Object (readonly)
- Break | Next
-
the node being formatted
3169 3170 3171 |
# File 'lib/syntax_tree.rb', line 3169 def node @node end |
Instance Method Details
#format(q) ⇒ Object
3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 |
# File 'lib/syntax_tree.rb', line 3176 def format(q) arguments = node.arguments q.group do q.text(keyword) if arguments.parts.any? if arguments.parts.length == 1 part = arguments.parts.first if part.is_a?(Paren) q.format(arguments) elsif part.is_a?(ArrayLiteral) q.text(" ") q.format(arguments) else format_arguments(q, "(", ")") end else format_arguments(q, " [", "]") end end end end |