Class: SyntaxTree::FlowControlFormatter
- Inherits:
-
Object
- Object
- SyntaxTree::FlowControlFormatter
- Defined in:
- lib/syntax_tree/node.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.
2506 2507 2508 2509 |
# File 'lib/syntax_tree/node.rb', line 2506 def initialize(keyword, node) @keyword = keyword @node = node end |
Instance Attribute Details
#keyword ⇒ Object (readonly)
- String
-
the keyword to print
2501 2502 2503 |
# File 'lib/syntax_tree/node.rb', line 2501 def keyword @keyword end |
#node ⇒ Object (readonly)
- Break | Next
-
the node being formatted
2504 2505 2506 |
# File 'lib/syntax_tree/node.rb', line 2504 def node @node end |
Instance Method Details
#format(q) ⇒ Object
2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 |
# File 'lib/syntax_tree/node.rb', line 2511 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 |