Class: RegularExpression::AST::Quantifier::Range
- Inherits:
-
Object
- Object
- RegularExpression::AST::Quantifier::Range
- Defined in:
- lib/regular_expression/ast.rb
Instance Attribute Summary collapse
-
#lower ⇒ Object
readonly
Integer.
-
#upper ⇒ Object
readonly
Integer.
Instance Method Summary collapse
-
#initialize(lower, upper) ⇒ Range
constructor
A new instance of Range.
- #quantify(start, finish) ⇒ Object
- #to_dot(parent) ⇒ Object
Constructor Details
#initialize(lower, upper) ⇒ Range
Returns a new instance of Range.
340 341 342 343 |
# File 'lib/regular_expression/ast.rb', line 340 def initialize(lower, upper) @lower = lower @upper = upper end |
Instance Attribute Details
#lower ⇒ Object (readonly)
Integer
338 339 340 |
# File 'lib/regular_expression/ast.rb', line 338 def lower @lower end |
#upper ⇒ Object (readonly)
Integer
338 339 340 |
# File 'lib/regular_expression/ast.rb', line 338 def upper @upper end |
Instance Method Details
#quantify(start, finish) ⇒ Object
349 350 351 352 353 354 355 356 357 358 359 360 |
# 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) ⇒ Object
345 346 347 |
# File 'lib/regular_expression/ast.rb', line 345 def to_dot(parent) parent.add_node(object_id, label: "{#{lower},#{upper}}", shape: "box") end |