Class: SyntaxTree::SymbolLiteral
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::SymbolLiteral
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
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#value ⇒ Object
readonly
- Backtick | Const | CVar | GVar | Ident | IVar | Kw | Op | TStringContent
-
the value of the symbol.
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.
10591
10592
10593
10594
10595
|
# File 'lib/syntax_tree/node.rb', line 10591
def initialize(value:, location:)
@value = value
@location = location
@comments = []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
10589
10590
10591
|
# File 'lib/syntax_tree/node.rb', line 10589
def
@comments
end
|
#value ⇒ Object
- Backtick | Const | CVar | GVar | Ident | IVar | Kw | Op | TStringContent
-
the value of the symbol
10586
10587
10588
|
# File 'lib/syntax_tree/node.rb', line 10586
def value
@value
end
|
Instance Method Details
#===(other) ⇒ Object
10628
10629
10630
|
# File 'lib/syntax_tree/node.rb', line 10628
def ===(other)
other.is_a?(SymbolLiteral) && value === other.value
end
|
#accept(visitor) ⇒ Object
10597
10598
10599
|
# File 'lib/syntax_tree/node.rb', line 10597
def accept(visitor)
visitor.visit_symbol_literal(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
10601
10602
10603
|
# File 'lib/syntax_tree/node.rb', line 10601
def child_nodes
[value]
end
|
#copy(value: nil, location: nil) ⇒ Object
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
|
# File 'lib/syntax_tree/node.rb', line 10605
def copy(value: nil, location: nil)
node =
SymbolLiteral.new(
value: value || self.value,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
10618
10619
10620
|
# File 'lib/syntax_tree/node.rb', line 10618
def deconstruct_keys(_keys)
{ value: value, location: location, comments: }
end
|
10622
10623
10624
10625
10626
|
# File 'lib/syntax_tree/node.rb', line 10622
def format(q)
q.text(":")
q.text("\\") if value..any?
q.format(value)
end
|