Class: SyntaxTree::LParen

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

Instance Method Summary collapse

Methods inherited from Node

#construct_keys, #pretty_print, #to_json

Constructor Details

#initialize(value:, location:) ⇒ LParen

Returns a new instance of LParen.



7324
7325
7326
7327
7328
# File 'lib/syntax_tree/node.rb', line 7324

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



7322
7323
7324
# File 'lib/syntax_tree/node.rb', line 7322

def comments
  @comments
end

#valueObject (readonly)

String

the left parenthesis



7319
7320
7321
# File 'lib/syntax_tree/node.rb', line 7319

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 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.



7368
7369
7370
# File 'lib/syntax_tree/node.rb', line 7368

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

Instance Method Details

#===(other) ⇒ Object



7359
7360
7361
# File 'lib/syntax_tree/node.rb', line 7359

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

#accept(visitor) ⇒ Object



7330
7331
7332
# File 'lib/syntax_tree/node.rb', line 7330

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

#child_nodesObject Also known as: deconstruct



7334
7335
7336
# File 'lib/syntax_tree/node.rb', line 7334

def child_nodes
  []
end

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



7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
# File 'lib/syntax_tree/node.rb', line 7338

def copy(value: nil, location: nil)
  node =
    LParen.new(
      value: value || self.value,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end

#deconstruct_keys(_keys) ⇒ Object



7351
7352
7353
# File 'lib/syntax_tree/node.rb', line 7351

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

#format(q) ⇒ Object



7355
7356
7357
# File 'lib/syntax_tree/node.rb', line 7355

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