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
7453
7454
7455
7456
7457
|
# File 'lib/syntax_tree/node.rb', line 7453
def initialize(value:, location:)
@value = value
@location = location
= []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7451
7452
7453
|
# File 'lib/syntax_tree/node.rb', line 7451
def
end
|
#value ⇒ Object
- String
-
the left parenthesis
7448
7449
7450
|
# File 'lib/syntax_tree/node.rb', line 7448
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.
7497
7498
7499
|
# File 'lib/syntax_tree/node.rb', line 7497
def self.default
new(value: "(", location: Location.default)
end
|
Instance Method Details
#===(other) ⇒ Object
7488
7489
7490
|
# File 'lib/syntax_tree/node.rb', line 7488
def ===(other)
other.is_a?(LParen) && value === other.value
end
|
#accept(visitor) ⇒ Object
7459
7460
7461
|
# File 'lib/syntax_tree/node.rb', line 7459
def accept(visitor)
visitor.visit_lparen(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
7463
7464
7465
|
# File 'lib/syntax_tree/node.rb', line 7463
def child_nodes
[]
end
|
#copy(value: nil, location: nil) ⇒ Object
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
|
# File 'lib/syntax_tree/node.rb', line 7467
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
7480
7481
7482
|
# File 'lib/syntax_tree/node.rb', line 7480
def deconstruct_keys(_keys)
{ value: value, location: location, comments: }
end
|
7484
7485
7486
|
# File 'lib/syntax_tree/node.rb', line 7484
def format(q)
q.text(value)
end
|