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.



1371
1372
1373
1374
1375
# File 'lib/syntax_tree/node.rb', line 1371

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



1369
1370
1371
# File 'lib/syntax_tree/node.rb', line 1369

def comments
  @comments
end

#valueObject (readonly)

String

the name of the global backreference variable



1366
1367
1368
# File 'lib/syntax_tree/node.rb', line 1366

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



1377
1378
1379
# File 'lib/syntax_tree/node.rb', line 1377

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

#child_nodesObject Also known as: deconstruct



1381
1382
1383
# File 'lib/syntax_tree/node.rb', line 1381

def child_nodes
  []
end

#deconstruct_keys(_keys) ⇒ Object



1387
1388
1389
# File 'lib/syntax_tree/node.rb', line 1387

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

#format(q) ⇒ Object



1391
1392
1393
# File 'lib/syntax_tree/node.rb', line 1391

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