Class: SyntaxTree::Backref
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.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#value ⇒ Object
readonly
- String
-
the name of the global backreference variable.
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ Backref
constructor
A new instance of Backref.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(value:, location:, comments: []) ⇒ Backref
Returns a new instance of Backref.
1565 1566 1567 1568 1569 |
# File 'lib/syntax_tree/node.rb', line 1565 def initialize(value:, location:, comments: []) @value = value @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
1563 1564 1565 |
# File 'lib/syntax_tree/node.rb', line 1563 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
1560 1561 1562 |
# File 'lib/syntax_tree/node.rb', line 1560 def location @location end |
#value ⇒ Object (readonly)
- String
-
the name of the global backreference variable
1557 1558 1559 |
# File 'lib/syntax_tree/node.rb', line 1557 def value @value end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
1571 1572 1573 |
# File 'lib/syntax_tree/node.rb', line 1571 def child_nodes [] end |
#deconstruct_keys(keys) ⇒ Object
1577 1578 1579 |
# File 'lib/syntax_tree/node.rb', line 1577 def deconstruct_keys(keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
1581 1582 1583 |
# File 'lib/syntax_tree/node.rb', line 1581 def format(q) q.text(value) end |
#pretty_print(q) ⇒ Object
1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 |
# File 'lib/syntax_tree/node.rb', line 1585 def pretty_print(q) q.group(2, "(", ")") do q.text("backref") q.breakable q.pp(value) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
1596 1597 1598 1599 1600 |
# File 'lib/syntax_tree/node.rb', line 1596 def to_json(*opts) { type: :backref, value: value, loc: location, cmts: comments }.to_json( *opts ) end |