Class: SyntaxTree::Paren
- Inherits:
-
Object
- Object
- SyntaxTree::Paren
- Defined in:
- lib/syntax_tree.rb
Overview
Paren represents using balanced parentheses in a couple places in a Ruby program. In general parentheses can be used anywhere a Ruby expression can be used.
(1 + 2)
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#contents ⇒ Object
readonly
- nil | untyped
-
the expression inside the parentheses.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#lparen ⇒ Object
readonly
- LParen
-
the left parenthesis that opened this statement.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(lparen:, contents:, location:, comments: []) ⇒ Paren
constructor
A new instance of Paren.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(lparen:, contents:, location:, comments: []) ⇒ Paren
Returns a new instance of Paren.
9129 9130 9131 9132 9133 9134 |
# File 'lib/syntax_tree.rb', line 9129 def initialize(lparen:, contents:, location:, comments: []) @lparen = lparen @contents = contents @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
9127 9128 9129 |
# File 'lib/syntax_tree.rb', line 9127 def comments @comments end |
#contents ⇒ Object (readonly)
- nil | untyped
-
the expression inside the parentheses
9121 9122 9123 |
# File 'lib/syntax_tree.rb', line 9121 def contents @contents end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
9124 9125 9126 |
# File 'lib/syntax_tree.rb', line 9124 def location @location end |
#lparen ⇒ Object (readonly)
- LParen
-
the left parenthesis that opened this statement
9118 9119 9120 |
# File 'lib/syntax_tree.rb', line 9118 def lparen @lparen end |
Instance Method Details
#child_nodes ⇒ Object
9136 9137 9138 |
# File 'lib/syntax_tree.rb', line 9136 def child_nodes [lparen, contents] end |
#format(q) ⇒ Object
9140 9141 9142 9143 9144 9145 9146 9147 9148 9149 9150 9151 9152 9153 9154 |
# File 'lib/syntax_tree.rb', line 9140 def format(q) q.group do q.format(lparen) if contents && (!contents.is_a?(Params) || !contents.empty?) q.indent do q.breakable("") q.format(contents) end end q.breakable("") q.text(")") end end |
#pretty_print(q) ⇒ Object
9156 9157 9158 9159 9160 9161 9162 9163 9164 9165 |
# File 'lib/syntax_tree.rb', line 9156 def pretty_print(q) q.group(2, "(", ")") do q.text("paren") q.breakable q.pp(contents) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
9167 9168 9169 9170 9171 9172 9173 9174 9175 |
# File 'lib/syntax_tree.rb', line 9167 def to_json(*opts) { type: :paren, lparen: lparen, cnts: contents, loc: location, cmts: comments }.to_json(*opts) end |