Class: Flexr::Automaton::ByteClassSet

Inherits:
Object
  • Object
show all
Defined in:
lib/flexr/automaton/byte_class_set.rb

Instance Method Summary collapse

Constructor Details

#initializeByteClassSet

Returns a new instance of ByteClassSet.



6
7
8
9
# File 'lib/flexr/automaton/byte_class_set.rb', line 6

def initialize
  @boundaries = Array.new(257, false)
  @boundaries[0] = true
end

Instance Method Details

#add_range(lo, hi) ⇒ Object

Raises:

  • (ArgumentError)


11
12
13
14
15
16
# File 'lib/flexr/automaton/byte_class_set.rb', line 11

def add_range(lo, hi)
  raise ArgumentError, "invalid byte range" unless lo.between?(0, 255) && hi.between?(lo, 255)

  @boundaries[lo] = true
  @boundaries[hi + 1] = true if hi < 255
end

#buildObject



18
19
20
21
22
23
24
25
26
# File 'lib/flexr/automaton/byte_class_set.rb', line 18

def build
  ec = Array.new(256)
  class_id = -1
  256.times do |byte|
    class_id += 1 if @boundaries[byte]
    ec[byte] = class_id
  end
  [ec.freeze, class_id + 1]
end