Class: SyntaxTree::Ident

Inherits:
Node
  • Object
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.



6188
6189
6190
6191
6192
# File 'lib/syntax_tree/node.rb', line 6188

def initialize(value:, location:)
  @value = value
  @location = location
  @comments = []
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



6186
6187
6188
# File 'lib/syntax_tree/node.rb', line 6186

def comments
  @comments
end

#valueObject (readonly)

String

the value of the identifier



6183
6184
6185
# File 'lib/syntax_tree/node.rb', line 6183

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



6223
6224
6225
# File 'lib/syntax_tree/node.rb', line 6223

def ===(other)
  other.is_a?(Ident) && value === other.value
end

#accept(visitor) ⇒ Object



6194
6195
6196
# File 'lib/syntax_tree/node.rb', line 6194

def accept(visitor)
  visitor.visit_ident(self)
end

#child_nodesObject Also known as: deconstruct



6198
6199
6200
# File 'lib/syntax_tree/node.rb', line 6198

def child_nodes
  []
end

#copy(value: nil, location: nil) ⇒ Object



6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
# File 'lib/syntax_tree/node.rb', line 6202

def copy(value: nil, location: nil)
  node =
    Ident.new(
      value: value || self.value,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end

#deconstruct_keys(_keys) ⇒ Object



6215
6216
6217
# File 'lib/syntax_tree/node.rb', line 6215

def deconstruct_keys(_keys)
  { value: value, location: location, comments: comments }
end

#format(q) ⇒ Object



6219
6220
6221
# File 'lib/syntax_tree/node.rb', line 6219

def format(q)
  q.text(value)
end