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.
10527
10528
10529
10530
10531
|
# File 'lib/syntax_tree/node.rb', line 10527
def initialize(value:, location:)
@value = value
@location = location
@comments = []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
10525
10526
10527
|
# File 'lib/syntax_tree/node.rb', line 10525
def
@comments
end
|
#value ⇒ Object
- Backtick | Const | CVar | GVar | Ident | IVar | Kw | Op | TStringContent
-
the value of the symbol
10522
10523
10524
|
# File 'lib/syntax_tree/node.rb', line 10522
def value
@value
end
|
Instance Method Details
#===(other) ⇒ Object
10564
10565
10566
|
# File 'lib/syntax_tree/node.rb', line 10564
def ===(other)
other.is_a?(SymbolLiteral) && value === other.value
end
|
#accept(visitor) ⇒ Object
10533
10534
10535
|
# File 'lib/syntax_tree/node.rb', line 10533
def accept(visitor)
visitor.visit_symbol_literal(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
10537
10538
10539
|
# File 'lib/syntax_tree/node.rb', line 10537
def child_nodes
[value]
end
|
#copy(value: nil, location: nil) ⇒ Object
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
|
# File 'lib/syntax_tree/node.rb', line 10541
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
10554
10555
10556
|
# File 'lib/syntax_tree/node.rb', line 10554
def deconstruct_keys(_keys)
{ value: value, location: location, comments: }
end
|
10558
10559
10560
10561
10562
|
# File 'lib/syntax_tree/node.rb', line 10558
def format(q)
q.text(":")
q.text("\\") if value..any?
q.format(value)
end
|