Class: SyntaxTree::Backref
- Inherits:
-
Object
- Object
- SyntaxTree::Backref
- Defined in:
- lib/syntax_tree.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.
-
#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
- #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.
2059 2060 2061 2062 2063 |
# File 'lib/syntax_tree.rb', line 2059 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
2057 2058 2059 |
# File 'lib/syntax_tree.rb', line 2057 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
2054 2055 2056 |
# File 'lib/syntax_tree.rb', line 2054 def location @location end |
#value ⇒ Object (readonly)
- String
-
the name of the global backreference variable
2051 2052 2053 |
# File 'lib/syntax_tree.rb', line 2051 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
2065 2066 2067 |
# File 'lib/syntax_tree.rb', line 2065 def child_nodes [] end |
#format(q) ⇒ Object
2069 2070 2071 |
# File 'lib/syntax_tree.rb', line 2069 def format(q) q.text(value) end |
#pretty_print(q) ⇒ Object
2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 |
# File 'lib/syntax_tree.rb', line 2073 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
2084 2085 2086 2087 2088 |
# File 'lib/syntax_tree.rb', line 2084 def to_json(*opts) { type: :backref, value: value, loc: location, cmts: comments }.to_json( *opts ) end |