Class: SyntaxTree::LBracket

Inherits:
Node
  • Object
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

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

Returns a new instance of LBracket.



7395
7396
7397
7398
7399
# File 'lib/syntax_tree/node.rb', line 7395

def initialize(value:, location:)
  @value = value
  @location = location
  @comments = []
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



7393
7394
7395
# File 'lib/syntax_tree/node.rb', line 7393

def comments
  @comments
end

#valueObject (readonly)

String

the left bracket



7390
7391
7392
# File 'lib/syntax_tree/node.rb', line 7390

def value
  @value
end

Class Method Details

.defaultObject

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.



7439
7440
7441
# File 'lib/syntax_tree/node.rb', line 7439

def self.default
  new(value: "[", location: Location.default)
end

Instance Method Details

#===(other) ⇒ Object



7430
7431
7432
# File 'lib/syntax_tree/node.rb', line 7430

def ===(other)
  other.is_a?(LBracket) && value === other.value
end

#accept(visitor) ⇒ Object



7401
7402
7403
# File 'lib/syntax_tree/node.rb', line 7401

def accept(visitor)
  visitor.visit_lbracket(self)
end

#child_nodesObject Also known as: deconstruct



7405
7406
7407
# File 'lib/syntax_tree/node.rb', line 7405

def child_nodes
  []
end

#copy(value: nil, location: nil) ⇒ Object



7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
# File 'lib/syntax_tree/node.rb', line 7409

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



7422
7423
7424
# File 'lib/syntax_tree/node.rb', line 7422

def deconstruct_keys(_keys)
  { value: value, location: location, comments: comments }
end

#format(q) ⇒ Object



7426
7427
7428
# File 'lib/syntax_tree/node.rb', line 7426

def format(q)
  q.text(value)
end