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



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

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



6071
6072
6073
# File 'lib/syntax_tree/node.rb', line 6071

def comments
  @comments
end

#valueObject (readonly)

String

the value of the identifier



6068
6069
6070
# File 'lib/syntax_tree/node.rb', line 6068

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



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

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

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  []
end

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



6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
# File 'lib/syntax_tree/node.rb', line 6087

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



6100
6101
6102
# File 'lib/syntax_tree/node.rb', line 6100

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

#format(q) ⇒ Object



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

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