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.
2038 2039 2040 2041 |
# File 'lib/syntax_tree/node.rb', line 2038 def initialize(keyword, node) @keyword = keyword @node = node end |
Instance Attribute Details
#keyword ⇒ Object (readonly)
- String
-
the keyword to print
2033 2034 2035 |
# File 'lib/syntax_tree/node.rb', line 2033 def keyword @keyword end |
#node ⇒ Object (readonly)
- Break | Next
-
the node being formatted
2036 2037 2038 |
# File 'lib/syntax_tree/node.rb', line 2036 def node @node end |
Instance Method Details
#format(q) ⇒ Object
2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 |
# File 'lib/syntax_tree/node.rb', line 2043 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 |