Class: Strling::Core::IRGroup

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

Overview

Represents a capturing or non-capturing group in the IR.

Groups pattern elements together.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(capturing, body, name: nil, atomic: nil) ⇒ IRGroup

Returns a new instance of IRGroup.

Parameters:

  • capturing (Boolean)

    Whether the group is capturing

  • body (IROp)

    The body of the group

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

    The name of the group

  • atomic (Boolean, nil) (defaults to: nil)

    Whether the group is atomic



271
272
273
274
275
276
# File 'lib/strling/core/ir.rb', line 271

def initialize(capturing, body, name: nil, atomic: nil)
  @capturing = capturing
  @body = body
  @name = name
  @atomic = atomic
end

Instance Attribute Details

#atomicBoolean?

Returns Whether the group is atomic.

Returns:

  • (Boolean, nil)

    Whether the group is atomic



265
266
267
# File 'lib/strling/core/ir.rb', line 265

def atomic
  @atomic
end

#bodyIROp

Returns The body of the group.

Returns:

  • (IROp)

    The body of the group



259
260
261
# File 'lib/strling/core/ir.rb', line 259

def body
  @body
end

#capturingBoolean

Returns Whether the group is capturing.

Returns:

  • (Boolean)

    Whether the group is capturing



256
257
258
# File 'lib/strling/core/ir.rb', line 256

def capturing
  @capturing
end

#nameString?

Returns The name of the group (for named captures).

Returns:

  • (String, nil)

    The name of the group (for named captures)



262
263
264
# File 'lib/strling/core/ir.rb', line 262

def name
  @name
end

Instance Method Details

#to_dictObject



278
279
280
281
282
283
284
285
286
287
# File 'lib/strling/core/ir.rb', line 278

def to_dict
  data = {
    'ir' => 'Group',
    'capturing' => capturing,
    'body' => body.to_dict
  }
  data['name'] = name unless name.nil?
  data['atomic'] = atomic unless atomic.nil?
  data
end