Class: SyntaxTree::LParen
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::LParen
show all
- Defined in:
- lib/syntax_tree/node.rb
Overview
LParen represents the use of a left parenthesis, i.e., (.
Instance Attribute Summary collapse
Attributes inherited from Node
#location
Class Method Summary
collapse
-
.default ⇒ Object
Because some nodes keep around a ( token so that comments can be attached to it if they occur in the source, oftentimes an LParen is a child of another node. This means it’s required at initialization time. To make it easier to create LParen nodes without any specific value, this method provides a default node..
Instance Method Summary
collapse
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(value:, location:) ⇒ LParen
7396
7397
7398
7399
7400
|
# File 'lib/syntax_tree/node.rb', line 7396
def initialize(value:, location:)
@value = value
@location = location
= []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7394
7395
7396
|
# File 'lib/syntax_tree/node.rb', line 7394
def
end
|
#value ⇒ Object
- String
-
the left parenthesis
7391
7392
7393
|
# File 'lib/syntax_tree/node.rb', line 7391
def value
@value
end
|
Class Method Details
.default ⇒ Object
Because some nodes keep around a ( token so that comments can be attached to it if they occur in the source, oftentimes an LParen is a child of another node. This means it’s required at initialization time. To make it easier to create LParen nodes without any specific value, this method provides a default node.
7440
7441
7442
|
# File 'lib/syntax_tree/node.rb', line 7440
def self.default
new(value: "(", location: Location.default)
end
|
Instance Method Details
#===(other) ⇒ Object
7431
7432
7433
|
# File 'lib/syntax_tree/node.rb', line 7431
def ===(other)
other.is_a?(LParen) && value === other.value
end
|
#accept(visitor) ⇒ Object
7402
7403
7404
|
# File 'lib/syntax_tree/node.rb', line 7402
def accept(visitor)
visitor.visit_lparen(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
7406
7407
7408
|
# File 'lib/syntax_tree/node.rb', line 7406
def child_nodes
[]
end
|
#copy(value: nil, location: nil) ⇒ Object
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
|
# File 'lib/syntax_tree/node.rb', line 7410
def copy(value: nil, location: nil)
node =
LParen.new(
value: value || self.value,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
7423
7424
7425
|
# File 'lib/syntax_tree/node.rb', line 7423
def deconstruct_keys(_keys)
{ value: value, location: location, comments: }
end
|
7427
7428
7429
|
# File 'lib/syntax_tree/node.rb', line 7427
def format(q)
q.text(value)
end
|