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, #pretty_print, #to_json

Constructor Details

#initialize(value:, location:) ⇒ Ident

Returns a new instance of Ident.



6078
6079
6080
6081
6082
# File 'lib/syntax_tree/node.rb', line 6078

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



6076
6077
6078
# File 'lib/syntax_tree/node.rb', line 6076

def comments
  @comments
end

#valueObject (readonly)

String

the value of the identifier



6073
6074
6075
# File 'lib/syntax_tree/node.rb', line 6073

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



6113
6114
6115
# File 'lib/syntax_tree/node.rb', line 6113

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

#accept(visitor) ⇒ Object



6084
6085
6086
# File 'lib/syntax_tree/node.rb', line 6084

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

#child_nodesObject Also known as: deconstruct



6088
6089
6090
# File 'lib/syntax_tree/node.rb', line 6088

def child_nodes
  []
end

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



6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
# File 'lib/syntax_tree/node.rb', line 6092

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



6105
6106
6107
# File 'lib/syntax_tree/node.rb', line 6105

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

#format(q) ⇒ Object



6109
6110
6111
# File 'lib/syntax_tree/node.rb', line 6109

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