Class: SyntaxTree::LBracket
Overview
LBracket represents the use of a left bracket, i.e., [.
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#value ⇒ Object
readonly
- String
-
the left bracket.
Attributes inherited from Node
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
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(value: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:) ⇒ LBracket
constructor
A new instance of LBracket.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(value:, location:) ⇒ LBracket
Returns a new instance of LBracket.
7380 7381 7382 7383 7384 |
# File 'lib/syntax_tree/node.rb', line 7380 def initialize(value:, location:) @value = value @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7378 7379 7380 |
# File 'lib/syntax_tree/node.rb', line 7378 def comments @comments end |
#value ⇒ Object (readonly)
- String
-
the left bracket
7375 7376 7377 |
# File 'lib/syntax_tree/node.rb', line 7375 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.
7424 7425 7426 |
# File 'lib/syntax_tree/node.rb', line 7424 def self.default new(value: "[", location: Location.default) end |
Instance Method Details
#===(other) ⇒ Object
7415 7416 7417 |
# File 'lib/syntax_tree/node.rb', line 7415 def ===(other) other.is_a?(LBracket) && value === other.value end |
#accept(visitor) ⇒ Object
7386 7387 7388 |
# File 'lib/syntax_tree/node.rb', line 7386 def accept(visitor) visitor.visit_lbracket(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7390 7391 7392 |
# File 'lib/syntax_tree/node.rb', line 7390 def child_nodes [] end |
#copy(value: nil, location: nil) ⇒ Object
7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 |
# File 'lib/syntax_tree/node.rb', line 7394 def copy(value: nil, location: nil) node = LBracket.new( value: value || self.value, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
7407 7408 7409 |
# File 'lib/syntax_tree/node.rb', line 7407 def deconstruct_keys(_keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
7411 7412 7413 |
# File 'lib/syntax_tree/node.rb', line 7411 def format(q) q.text(value) end |