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.



10590
10591
10592
10593
10594
# File 'lib/syntax_tree/node.rb', line 10590

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



10588
10589
10590
# File 'lib/syntax_tree/node.rb', line 10588

def comments
  @comments
end

#valueObject (readonly)

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

the value of the symbol



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

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



10627
10628
10629
# File 'lib/syntax_tree/node.rb', line 10627

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

#accept(visitor) ⇒ Object



10596
10597
10598
# File 'lib/syntax_tree/node.rb', line 10596

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

#child_nodesObject Also known as: deconstruct



10600
10601
10602
# File 'lib/syntax_tree/node.rb', line 10600

def child_nodes
  [value]
end

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



10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
# File 'lib/syntax_tree/node.rb', line 10604

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



10617
10618
10619
# File 'lib/syntax_tree/node.rb', line 10617

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

#format(q) ⇒ Object



10621
10622
10623
10624
10625
# File 'lib/syntax_tree/node.rb', line 10621

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