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.
1666
1667
1668
1669
1670
|
# File 'lib/syntax_tree/node.rb', line 1666
def initialize(value:, location:)
@value = value
@location = location
@comments = []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
1664
1665
1666
|
# File 'lib/syntax_tree/node.rb', line 1664
def
@comments
end
|
#value ⇒ Object
- String
-
the name of the global backreference variable
1661
1662
1663
|
# File 'lib/syntax_tree/node.rb', line 1661
def value
@value
end
|
Instance Method Details
#===(other) ⇒ Object
1701
1702
1703
|
# File 'lib/syntax_tree/node.rb', line 1701
def ===(other)
other.is_a?(Backref) && value === other.value
end
|
#accept(visitor) ⇒ Object
1672
1673
1674
|
# File 'lib/syntax_tree/node.rb', line 1672
def accept(visitor)
visitor.visit_backref(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
1676
1677
1678
|
# File 'lib/syntax_tree/node.rb', line 1676
def child_nodes
[]
end
|
#copy(value: nil, location: nil) ⇒ Object
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
|
# File 'lib/syntax_tree/node.rb', line 1680
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
1693
1694
1695
|
# File 'lib/syntax_tree/node.rb', line 1693
def deconstruct_keys(_keys)
{ value: value, location: location, comments: }
end
|
1697
1698
1699
|
# File 'lib/syntax_tree/node.rb', line 1697
def format(q)
q.text(value)
end
|