Class: SyntaxTree::Ident
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::Ident
show all
- Defined in:
- lib/syntax_tree/node.rb
Overview
Ident represents an identifier anywhere in code. It can represent a very large number of things, depending on where it is in the syntax tree.
value
Instance Attribute Summary collapse
Attributes inherited from Node
#location
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:) ⇒ Ident
Returns a new instance of Ident.
6203
6204
6205
6206
6207
|
# File 'lib/syntax_tree/node.rb', line 6203
def initialize(value:, location:)
@value = value
@location = location
@comments = []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
6201
6202
6203
|
# File 'lib/syntax_tree/node.rb', line 6201
def
@comments
end
|
#value ⇒ Object
- String
-
the value of the identifier
6198
6199
6200
|
# File 'lib/syntax_tree/node.rb', line 6198
def value
@value
end
|
Instance Method Details
#===(other) ⇒ Object
6238
6239
6240
|
# File 'lib/syntax_tree/node.rb', line 6238
def ===(other)
other.is_a?(Ident) && value === other.value
end
|
#accept(visitor) ⇒ Object
6209
6210
6211
|
# File 'lib/syntax_tree/node.rb', line 6209
def accept(visitor)
visitor.visit_ident(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
6213
6214
6215
|
# File 'lib/syntax_tree/node.rb', line 6213
def child_nodes
[]
end
|
#copy(value: nil, location: nil) ⇒ Object
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
|
# File 'lib/syntax_tree/node.rb', line 6217
def copy(value: nil, location: nil)
node =
Ident.new(
value: value || self.value,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
6230
6231
6232
|
# File 'lib/syntax_tree/node.rb', line 6230
def deconstruct_keys(_keys)
{ value: value, location: location, comments: }
end
|
6234
6235
6236
|
# File 'lib/syntax_tree/node.rb', line 6234
def format(q)
q.text(value)
end
|