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, #pretty_print, #to_json
Constructor Details
#initialize(value:, location:) ⇒ LBrace
7222
7223
7224
7225
7226
|
# File 'lib/syntax_tree/node.rb', line 7222
def initialize(value:, location:)
@value = value
@location = location
= []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7220
7221
7222
|
# File 'lib/syntax_tree/node.rb', line 7220
def
end
|
#value ⇒ Object
7217
7218
7219
|
# File 'lib/syntax_tree/node.rb', line 7217
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.
7266
7267
7268
|
# File 'lib/syntax_tree/node.rb', line 7266
def self.default
new(value: "{", location: Location.default)
end
|
Instance Method Details
#===(other) ⇒ Object
7257
7258
7259
|
# File 'lib/syntax_tree/node.rb', line 7257
def ===(other)
other.is_a?(LBrace) && value === other.value
end
|
#accept(visitor) ⇒ Object
7228
7229
7230
|
# File 'lib/syntax_tree/node.rb', line 7228
def accept(visitor)
visitor.visit_lbrace(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
7232
7233
7234
|
# File 'lib/syntax_tree/node.rb', line 7232
def child_nodes
[]
end
|
#copy(value: nil, location: nil) ⇒ Object
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
|
# File 'lib/syntax_tree/node.rb', line 7236
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
7249
7250
7251
|
# File 'lib/syntax_tree/node.rb', line 7249
def deconstruct_keys(_keys)
{ value: value, location: location, comments: }
end
|
7253
7254
7255
|
# File 'lib/syntax_tree/node.rb', line 7253
def format(q)
q.text(value)
end
|