Class: SyntaxTree::LBrace
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::LBrace
show all
- Defined in:
- lib/syntax_tree/node.rb
Overview
LBrace represents the use of a left brace, 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 LBrace is a child of another node. This means it’s required at initialization time. To make it easier to create LBrace 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:) ⇒ LBrace
7313
7314
7315
7316
7317
|
# File 'lib/syntax_tree/node.rb', line 7313
def initialize(value:, location:)
@value = value
@location = location
= []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7311
7312
7313
|
# File 'lib/syntax_tree/node.rb', line 7311
def
end
|
#value ⇒ Object
7308
7309
7310
|
# File 'lib/syntax_tree/node.rb', line 7308
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 LBrace is a child of another node. This means it’s required at initialization time. To make it easier to create LBrace nodes without any specific value, this method provides a default node.
7357
7358
7359
|
# File 'lib/syntax_tree/node.rb', line 7357
def self.default
new(value: "{", location: Location.default)
end
|
Instance Method Details
#===(other) ⇒ Object
7348
7349
7350
|
# File 'lib/syntax_tree/node.rb', line 7348
def ===(other)
other.is_a?(LBrace) && value === other.value
end
|
#accept(visitor) ⇒ Object
7319
7320
7321
|
# File 'lib/syntax_tree/node.rb', line 7319
def accept(visitor)
visitor.visit_lbrace(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
7323
7324
7325
|
# File 'lib/syntax_tree/node.rb', line 7323
def child_nodes
[]
end
|
#copy(value: nil, location: nil) ⇒ Object
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
|
# File 'lib/syntax_tree/node.rb', line 7327
def copy(value: nil, location: nil)
node =
LBrace.new(
value: value || self.value,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
7340
7341
7342
|
# File 'lib/syntax_tree/node.rb', line 7340
def deconstruct_keys(_keys)
{ value: value, location: location, comments: }
end
|
7344
7345
7346
|
# File 'lib/syntax_tree/node.rb', line 7344
def format(q)
q.text(value)
end
|