Class: RegularExpression::AST::Quantifier::AtLeast

Inherits:
Object
  • Object
show all
Defined in:
lib/regular_expression/ast.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ AtLeast

Returns a new instance of AtLeast.



318
319
320
# File 'lib/regular_expression/ast.rb', line 318

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Integer



316
317
318
# File 'lib/regular_expression/ast.rb', line 316

def value
  @value
end

Instance Method Details

#quantify(start, finish) ⇒ Object



326
327
328
329
330
331
332
333
334
# File 'lib/regular_expression/ast.rb', line 326

def quantify(start, finish)
  states = [start, *(value - 1).times.map { NFA::State.new }, finish]

  value.times do |index|
    yield states[index], states[index + 1]
  end

  states[-1].add_transition(NFA::Transition::Epsilon.new(states[-2]))
end

#to_dot(parent) ⇒ Object



322
323
324
# File 'lib/regular_expression/ast.rb', line 322

def to_dot(parent)
  parent.add_node(object_id, label: "{#{value},}", shape: "box")
end