Class: SyntaxTree::Paren
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::Paren
show all
- Defined in:
- lib/syntax_tree/node.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
Attributes inherited from Node
#location
Instance Method Summary
collapse
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(lparen:, contents:, location:) ⇒ Paren
8352
8353
8354
8355
8356
8357
|
# File 'lib/syntax_tree/node.rb', line 8352
def initialize(lparen:, contents:, location:)
@lparen = lparen
@contents = contents
@location = location
= []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
8350
8351
8352
|
# File 'lib/syntax_tree/node.rb', line 8350
def
end
|
#contents ⇒ Object
- nil | untyped
-
the expression inside the parentheses
8347
8348
8349
|
# File 'lib/syntax_tree/node.rb', line 8347
def contents
@contents
end
|
#lparen ⇒ Object
- LParen
-
the left parenthesis that opened this statement
8344
8345
8346
|
# File 'lib/syntax_tree/node.rb', line 8344
def lparen
@lparen
end
|
Instance Method Details
#===(other) ⇒ Object
8406
8407
8408
8409
|
# File 'lib/syntax_tree/node.rb', line 8406
def ===(other)
other.is_a?(Paren) && lparen === other.lparen &&
contents === other.contents
end
|
#accept(visitor) ⇒ Object
8359
8360
8361
|
# File 'lib/syntax_tree/node.rb', line 8359
def accept(visitor)
visitor.visit_paren(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
8363
8364
8365
|
# File 'lib/syntax_tree/node.rb', line 8363
def child_nodes
[lparen, contents]
end
|
#copy(lparen: nil, contents: nil, location: nil) ⇒ Object
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
|
# File 'lib/syntax_tree/node.rb', line 8367
def copy(lparen: nil, contents: nil, location: nil)
node =
Paren.new(
lparen: lparen || self.lparen,
contents: contents || self.contents,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
8381
8382
8383
8384
8385
8386
8387
8388
|
# File 'lib/syntax_tree/node.rb', line 8381
def deconstruct_keys(_keys)
{
lparen: lparen,
contents: contents,
location: location,
comments:
}
end
|
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
|
# File 'lib/syntax_tree/node.rb', line 8390
def format(q)
q.group do
q.format(lparen)
if contents && (!contents.is_a?(Params) || !contents.empty?)
q.indent do
q.breakable_empty
q.format(contents)
end
end
q.breakable_empty
q.text(")")
end
end
|