class RegularExpression::AST::Quantifier::Range

Attributes

lower[R]
upper[R]

Public Class Methods

new(lower, upper) click to toggle source
# File lib/regular_expression/ast.rb, line 340
def initialize(lower, upper)
  @lower = lower
  @upper = upper
end

Public Instance Methods

quantify(start, finish) { |states, states| ... } click to toggle source
# File lib/regular_expression/ast.rb, line 349
def quantify(start, finish)
  states = [start, *(upper - 1).times.map { NFA::State.new }, finish]

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

  (upper - lower).times do |index|
    transition = NFA::Transition::Epsilon.new(states[-1])
    states[lower + index].add_transition(transition)
  end
end
to_dot(parent) click to toggle source
# File lib/regular_expression/ast.rb, line 345
def to_dot(parent)
  parent.add_node(object_id, label: "{#{lower},#{upper}}", shape: "box")
end