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.
-
#value ⇒ Object
readonly
- String
-
the name of the global backreference variable.
Attributes inherited from Node
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.
1514 1515 1516 1517 1518 |
# File 'lib/syntax_tree/node.rb', line 1514 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
1512 1513 1514 |
# File 'lib/syntax_tree/node.rb', line 1512 def comments @comments end |
#value ⇒ Object (readonly)
- String
-
the name of the global backreference variable
1509 1510 1511 |
# File 'lib/syntax_tree/node.rb', line 1509 def value @value end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
1520 1521 1522 |
# File 'lib/syntax_tree/node.rb', line 1520 def child_nodes [] end |
#deconstruct_keys(keys) ⇒ Object
1526 1527 1528 |
# File 'lib/syntax_tree/node.rb', line 1526 def deconstruct_keys(keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
1530 1531 1532 |
# File 'lib/syntax_tree/node.rb', line 1530 def format(q) q.text(value) end |
#pretty_print(q) ⇒ Object
1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 |
# File 'lib/syntax_tree/node.rb', line 1534 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
1545 1546 1547 1548 1549 |
# File 'lib/syntax_tree/node.rb', line 1545 def to_json(*opts) { type: :backref, value: value, loc: location, cmts: comments }.to_json( *opts ) end |