Class: Strling::Core::Quant

Inherits:
Node
  • Object
show all
Defined in:
lib/strling/core/nodes.rb

Overview

Represents a quantifier (repetition operator).

Specifies how many times a pattern element should match (min to max times). Supports greedy, lazy, and possessive modes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(child, min, max, mode) ⇒ Quant

Returns a new instance of Quant.

Parameters:

  • child (Node)

    The child node being quantified

  • min (Integer)

    The minimum number of matches

  • max (Integer, String)

    The maximum number of matches

  • mode (String)

    The quantifier mode



328
329
330
331
332
333
# File 'lib/strling/core/nodes.rb', line 328

def initialize(child, min, max, mode)
  @child = child
  @min = min
  @max = max
  @mode = mode
end

Instance Attribute Details

#childNode

Returns The child node being quantified.

Returns:

  • (Node)

    The child node being quantified



313
314
315
# File 'lib/strling/core/nodes.rb', line 313

def child
  @child
end

#maxInteger, String

Returns The maximum number of matches (“Inf” for unbounded).

Returns:

  • (Integer, String)

    The maximum number of matches (“Inf” for unbounded)



319
320
321
# File 'lib/strling/core/nodes.rb', line 319

def max
  @max
end

#minInteger

Returns The minimum number of matches.

Returns:

  • (Integer)

    The minimum number of matches



316
317
318
# File 'lib/strling/core/nodes.rb', line 316

def min
  @min
end

#modeString

Returns The quantifier mode: “Greedy”, “Lazy”, or “Possessive”.

Returns:

  • (String)

    The quantifier mode: “Greedy”, “Lazy”, or “Possessive”



322
323
324
# File 'lib/strling/core/nodes.rb', line 322

def mode
  @mode
end

Instance Method Details

#to_dictObject



335
336
337
338
339
340
341
342
343
# File 'lib/strling/core/nodes.rb', line 335

def to_dict
  {
    'kind' => 'Quant',
    'child' => child.to_dict,
    'min' => min,
    'max' => max,
    'mode' => mode
  }
end