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.



10558
10559
10560
10561
10562
# File 'lib/syntax_tree/node.rb', line 10558

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



10556
10557
10558
# File 'lib/syntax_tree/node.rb', line 10556

def comments
  @comments
end

#valueObject (readonly)

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

the value of the symbol



10553
10554
10555
# File 'lib/syntax_tree/node.rb', line 10553

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



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

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

#accept(visitor) ⇒ Object



10564
10565
10566
# File 'lib/syntax_tree/node.rb', line 10564

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

#child_nodesObject Also known as: deconstruct



10568
10569
10570
# File 'lib/syntax_tree/node.rb', line 10568

def child_nodes
  [value]
end

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



10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
# File 'lib/syntax_tree/node.rb', line 10572

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



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

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

#format(q) ⇒ Object



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

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