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.
6164
6165
6166
6167
6168
|
# File 'lib/syntax_tree/node.rb', line 6164
def initialize(value:, location:)
@value = value
@location = location
@comments = []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
6162
6163
6164
|
# File 'lib/syntax_tree/node.rb', line 6162
def
@comments
end
|
#value ⇒ Object
- String
-
the value of the identifier
6159
6160
6161
|
# File 'lib/syntax_tree/node.rb', line 6159
def value
@value
end
|
Instance Method Details
#===(other) ⇒ Object
6199
6200
6201
|
# File 'lib/syntax_tree/node.rb', line 6199
def ===(other)
other.is_a?(Ident) && value === other.value
end
|
#accept(visitor) ⇒ Object
6170
6171
6172
|
# File 'lib/syntax_tree/node.rb', line 6170
def accept(visitor)
visitor.visit_ident(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
6174
6175
6176
|
# File 'lib/syntax_tree/node.rb', line 6174
def child_nodes
[]
end
|
#copy(value: nil, location: nil) ⇒ Object
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
|
# File 'lib/syntax_tree/node.rb', line 6178
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
6191
6192
6193
|
# File 'lib/syntax_tree/node.rb', line 6191
def deconstruct_keys(_keys)
{ value: value, location: location, comments: }
end
|
6195
6196
6197
|
# File 'lib/syntax_tree/node.rb', line 6195
def format(q)
q.text(value)
end
|