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.
9205 9206 9207 9208 9209 9210 |
# File 'lib/syntax_tree.rb', line 9205 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
9203 9204 9205 |
# File 'lib/syntax_tree.rb', line 9203 def comments @comments end |
#contents ⇒ Object (readonly)
- nil | untyped
-
the expression inside the parentheses
9197 9198 9199 |
# File 'lib/syntax_tree.rb', line 9197 def contents @contents end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
9200 9201 9202 |
# File 'lib/syntax_tree.rb', line 9200 def location @location end |
#lparen ⇒ Object (readonly)
- LParen
-
the left parenthesis that opened this statement
9194 9195 9196 |
# File 'lib/syntax_tree.rb', line 9194 def lparen @lparen end |
Instance Method Details
#child_nodes ⇒ Object
9212 9213 9214 |
# File 'lib/syntax_tree.rb', line 9212 def child_nodes [lparen, contents] end |
#format(q) ⇒ Object
9216 9217 9218 9219 9220 9221 9222 9223 9224 9225 9226 9227 9228 9229 9230 |
# File 'lib/syntax_tree.rb', line 9216 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
9232 9233 9234 9235 9236 9237 9238 9239 9240 9241 |
# File 'lib/syntax_tree.rb', line 9232 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
9243 9244 9245 9246 9247 9248 9249 9250 9251 |
# File 'lib/syntax_tree.rb', line 9243 def to_json(*opts) { type: :paren, lparen: lparen, cnts: contents, loc: location, cmts: comments }.to_json(*opts) end |