Class: SyntaxTree::SymbolLiteral

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

SymbolLiteral represents a symbol in the system with no interpolation (as opposed to a DynaSymbol which has interpolation).

:symbol

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:) ⇒ SymbolLiteral

Returns a new instance of SymbolLiteral.



10575
10576
10577
10578
10579
# File 'lib/syntax_tree/node.rb', line 10575

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



10573
10574
10575
# File 'lib/syntax_tree/node.rb', line 10573

def comments
  @comments
end

#valueObject (readonly)

Backtick | Const | CVar | GVar | Ident | IVar | Kw | Op | TStringContent

the value of the symbol



10570
10571
10572
# File 'lib/syntax_tree/node.rb', line 10570

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



10612
10613
10614
# File 'lib/syntax_tree/node.rb', line 10612

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

#accept(visitor) ⇒ Object



10581
10582
10583
# File 'lib/syntax_tree/node.rb', line 10581

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

#child_nodesObject Also known as: deconstruct



10585
10586
10587
# File 'lib/syntax_tree/node.rb', line 10585

def child_nodes
  [value]
end

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



10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
# File 'lib/syntax_tree/node.rb', line 10589

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

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

#deconstruct_keys(_keys) ⇒ Object



10602
10603
10604
# File 'lib/syntax_tree/node.rb', line 10602

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

#format(q) ⇒ Object



10606
10607
10608
10609
10610
# File 'lib/syntax_tree/node.rb', line 10606

def format(q)
  q.text(":")
  q.text("\\") if value.comments.any?
  q.format(value)
end