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.
3033 3034 3035 3036 |
# File 'lib/syntax_tree.rb', line 3033 def initialize(keyword, node) @keyword = keyword @node = node end |
Instance Attribute Details
#keyword ⇒ Object (readonly)
- String
-
the keyword to print
3028 3029 3030 |
# File 'lib/syntax_tree.rb', line 3028 def keyword @keyword end |
#node ⇒ Object (readonly)
- Break | Next
-
the node being formatted
3031 3032 3033 |
# File 'lib/syntax_tree.rb', line 3031 def node @node end |
Instance Method Details
#format(q) ⇒ Object
3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 |
# File 'lib/syntax_tree.rb', line 3038 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 |