Class: RegularExpression::AST::Quantifier::Exact

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Exact

Returns a new instance of Exact.



298
299
300
# File 'lib/regular_expression/ast.rb', line 298

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Integer



296
297
298
# File 'lib/regular_expression/ast.rb', line 296

def value
  @value
end

Instance Method Details

#quantify(start, finish) ⇒ Object



306
307
308
309
310
311
312
# File 'lib/regular_expression/ast.rb', line 306

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
end

#to_dot(parent) ⇒ Object



302
303
304
# File 'lib/regular_expression/ast.rb', line 302

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