Class: Strling::Core::IRBackref

Inherits:
IROp
  • Object
show all
Defined in:
lib/strling/core/ir.rb

Overview

Represents a backreference in the IR.

Matches the same text as previously captured by a group.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(by_index: nil, by_name: nil) ⇒ IRBackref

Returns a new instance of IRBackref.

Parameters:

  • by_index (Integer, nil) (defaults to: nil)

    The group index to reference

  • by_name (String, nil) (defaults to: nil)

    The group name to reference



302
303
304
305
# File 'lib/strling/core/ir.rb', line 302

def initialize(by_index: nil, by_name: nil)
  @by_index = by_index
  @by_name = by_name
end

Instance Attribute Details

#by_indexInteger?

Returns The group index to reference.

Returns:

  • (Integer, nil)

    The group index to reference



295
296
297
# File 'lib/strling/core/ir.rb', line 295

def by_index
  @by_index
end

#by_nameString?

Returns The group name to reference.

Returns:

  • (String, nil)

    The group name to reference



298
299
300
# File 'lib/strling/core/ir.rb', line 298

def by_name
  @by_name
end

Instance Method Details

#to_dictObject



307
308
309
310
311
312
# File 'lib/strling/core/ir.rb', line 307

def to_dict
  data = { 'ir' => 'Backref' }
  data['byIndex'] = by_index unless by_index.nil?
  data['byName'] = by_name unless by_name.nil?
  data
end