Class: SyntaxTree::Backref
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::Backref
show all
- Defined in:
- lib/syntax_tree/node.rb
Overview
Backref represents a global variable referencing a matched value. It comes in the form of a $ followed by a positive integer.
$1
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#value ⇒ Object
readonly
- String
-
the name of the global backreference variable.
Attributes inherited from Node
#location
Instance Method Summary
collapse
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(value:, location:) ⇒ Backref
Returns a new instance of Backref.
1620
1621
1622
1623
1624
|
# File 'lib/syntax_tree/node.rb', line 1620
def initialize(value:, location:)
@value = value
@location = location
@comments = []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
1618
1619
1620
|
# File 'lib/syntax_tree/node.rb', line 1618
def
@comments
end
|
#value ⇒ Object
- String
-
the name of the global backreference variable
1615
1616
1617
|
# File 'lib/syntax_tree/node.rb', line 1615
def value
@value
end
|
Instance Method Details
#===(other) ⇒ Object
1655
1656
1657
|
# File 'lib/syntax_tree/node.rb', line 1655
def ===(other)
other.is_a?(Backref) && value === other.value
end
|
#accept(visitor) ⇒ Object
1626
1627
1628
|
# File 'lib/syntax_tree/node.rb', line 1626
def accept(visitor)
visitor.visit_backref(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
1630
1631
1632
|
# File 'lib/syntax_tree/node.rb', line 1630
def child_nodes
[]
end
|
#copy(value: nil, location: nil) ⇒ Object
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
|
# File 'lib/syntax_tree/node.rb', line 1634
def copy(value: nil, location: nil)
node =
Backref.new(
value: value || self.value,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
1647
1648
1649
|
# File 'lib/syntax_tree/node.rb', line 1647
def deconstruct_keys(_keys)
{ value: value, location: location, comments: }
end
|
1651
1652
1653
|
# File 'lib/syntax_tree/node.rb', line 1651
def format(q)
q.text(value)
end
|