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.



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

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



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

def comments
  @comments
end

#valueObject (readonly)

String

the value of the identifier



6180
6181
6182
# File 'lib/syntax_tree/node.rb', line 6180

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



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

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

#accept(visitor) ⇒ Object



6191
6192
6193
# File 'lib/syntax_tree/node.rb', line 6191

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  []
end

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



6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
# File 'lib/syntax_tree/node.rb', line 6199

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



6212
6213
6214
# File 'lib/syntax_tree/node.rb', line 6212

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

#format(q) ⇒ Object



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

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