Class: SyntaxTree::Backref

Inherits:
Node
  • Object
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

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#pretty_print, #to_json

Constructor Details

#initialize(value:, location:, comments: []) ⇒ Backref

Returns a new instance of Backref.



1268
1269
1270
1271
1272
# File 'lib/syntax_tree/node.rb', line 1268

def initialize(value:, location:, comments: [])
  @value = value
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



1266
1267
1268
# File 'lib/syntax_tree/node.rb', line 1266

def comments
  @comments
end

#valueObject (readonly)

String

the name of the global backreference variable



1263
1264
1265
# File 'lib/syntax_tree/node.rb', line 1263

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



1274
1275
1276
# File 'lib/syntax_tree/node.rb', line 1274

def accept(visitor)
  visitor.visit_backref(self)
end

#child_nodesObject Also known as: deconstruct



1278
1279
1280
# File 'lib/syntax_tree/node.rb', line 1278

def child_nodes
  []
end

#deconstruct_keys(keys) ⇒ Object



1284
1285
1286
# File 'lib/syntax_tree/node.rb', line 1284

def deconstruct_keys(keys)
  { value: value, location: location, comments: comments }
end

#format(q) ⇒ Object



1288
1289
1290
# File 'lib/syntax_tree/node.rb', line 1288

def format(q)
  q.text(value)
end