Class: SyntaxTree::LBracket
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::LBracket
show all
- Defined in:
- lib/syntax_tree/node.rb
Overview
LBracket represents the use of a left bracket, 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 LBracket is a child of another node. This means it’s required at initialization time. To make it easier to create LBracket 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:) ⇒ LBracket
7370
7371
7372
7373
7374
|
# File 'lib/syntax_tree/node.rb', line 7370
def initialize(value:, location:)
@value = value
@location = location
= []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7368
7369
7370
|
# File 'lib/syntax_tree/node.rb', line 7368
def
end
|
#value ⇒ Object
7365
7366
7367
|
# File 'lib/syntax_tree/node.rb', line 7365
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 LBracket is a child of another node. This means it’s required at initialization time. To make it easier to create LBracket nodes without any specific value, this method provides a default node.
7414
7415
7416
|
# File 'lib/syntax_tree/node.rb', line 7414
def self.default
new(value: "[", location: Location.default)
end
|
Instance Method Details
#===(other) ⇒ Object
7405
7406
7407
|
# File 'lib/syntax_tree/node.rb', line 7405
def ===(other)
other.is_a?(LBracket) && value === other.value
end
|
#accept(visitor) ⇒ Object
7376
7377
7378
|
# File 'lib/syntax_tree/node.rb', line 7376
def accept(visitor)
visitor.visit_lbracket(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
7380
7381
7382
|
# File 'lib/syntax_tree/node.rb', line 7380
def child_nodes
[]
end
|
#copy(value: nil, location: nil) ⇒ Object
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
|
# File 'lib/syntax_tree/node.rb', line 7384
def copy(value: nil, location: nil)
node =
LBracket.new(
value: value || self.value,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
7397
7398
7399
|
# File 'lib/syntax_tree/node.rb', line 7397
def deconstruct_keys(_keys)
{ value: value, location: location, comments: }
end
|
7401
7402
7403
|
# File 'lib/syntax_tree/node.rb', line 7401
def format(q)
q.text(value)
end
|