Class: SyntaxTree::LParen
Overview
LParen represents the use of a left parenthesis, i.e., (.
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#value ⇒ Object
readonly
- String
-
the left parenthesis.
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 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
- #===(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:) ⇒ LParen
constructor
A new instance of LParen.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(value:, location:) ⇒ LParen
Returns a new instance of LParen.
7437 7438 7439 7440 7441 |
# File 'lib/syntax_tree/node.rb', line 7437 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
7435 7436 7437 |
# File 'lib/syntax_tree/node.rb', line 7435 def comments @comments end |
#value ⇒ Object (readonly)
- String
-
the left parenthesis
7432 7433 7434 |
# File 'lib/syntax_tree/node.rb', line 7432 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.
7481 7482 7483 |
# File 'lib/syntax_tree/node.rb', line 7481 def self.default new(value: "(", location: Location.default) end |
Instance Method Details
#===(other) ⇒ Object
7472 7473 7474 |
# File 'lib/syntax_tree/node.rb', line 7472 def ===(other) other.is_a?(LParen) && value === other.value end |
#accept(visitor) ⇒ Object
7443 7444 7445 |
# File 'lib/syntax_tree/node.rb', line 7443 def accept(visitor) visitor.visit_lparen(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7447 7448 7449 |
# File 'lib/syntax_tree/node.rb', line 7447 def child_nodes [] end |
#copy(value: nil, location: nil) ⇒ Object
7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 |
# File 'lib/syntax_tree/node.rb', line 7451 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
7464 7465 7466 |
# File 'lib/syntax_tree/node.rb', line 7464 def deconstruct_keys(_keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
7468 7469 7470 |
# File 'lib/syntax_tree/node.rb', line 7468 def format(q) q.text(value) end |