Class: LexerKit::DFA::ByteClassBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/lexer_kit/dfa/byte_class_builder.rb

Overview

ByteClassBuilder compresses DFA transitions by grouping bytes with identical behavior into equivalence classes.

Instance Method Summary collapse

Constructor Details

#initialize(dfa_states:, dfa_transitions:, state_count:) ⇒ ByteClassBuilder

Returns a new instance of ByteClassBuilder.

Parameters:

  • dfa_states (Hash)

    NFA state set → DFA state ID mapping

  • dfa_transitions (Hash)
    state, byte

    → target state mapping

  • state_count (Integer)

    number of DFA states



11
12
13
14
15
# File 'lib/lexer_kit/dfa/byte_class_builder.rb', line 11

def initialize(dfa_states:, dfa_transitions:, state_count:)
  @dfa_states = dfa_states
  @dfa_transitions = dfa_transitions
  @state_count = state_count
end

Instance Method Details

#buildHash

Build byte classes and transition table

Returns:

  • (Hash)

    { byte_class:, class_count:, transitions: }



19
20
21
22
23
24
25
26
27
28
# File 'lib/lexer_kit/dfa/byte_class_builder.rb', line 19

def build
  byte_class, class_count = build_byte_classes
  transitions = build_transition_table(byte_class, class_count)

  {
    byte_class: byte_class,
    class_count: class_count,
    transitions: transitions
  }
end