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

#construct_keys, #pretty_print, #to_json

Constructor Details

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

Returns a new instance of Backref.



1325
1326
1327
1328
1329
# File 'lib/syntax_tree/node.rb', line 1325

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



1323
1324
1325
# File 'lib/syntax_tree/node.rb', line 1323

def comments
  @comments
end

#valueObject (readonly)

String

the name of the global backreference variable



1320
1321
1322
# File 'lib/syntax_tree/node.rb', line 1320

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



1331
1332
1333
# File 'lib/syntax_tree/node.rb', line 1331

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

#child_nodesObject Also known as: deconstruct



1335
1336
1337
# File 'lib/syntax_tree/node.rb', line 1335

def child_nodes
  []
end

#deconstruct_keys(_keys) ⇒ Object



1341
1342
1343
# File 'lib/syntax_tree/node.rb', line 1341

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

#format(q) ⇒ Object



1345
1346
1347
# File 'lib/syntax_tree/node.rb', line 1345

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