Class: Flexr::Automaton::Compiler

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

Instance Method Summary collapse

Constructor Details

#initialize(spec) ⇒ Compiler

Returns a new instance of Compiler.



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

def initialize(spec)
  @spec = spec
end

Instance Method Details

#compileObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/flexr/automaton/compiler.rb', line 10

def compile
  started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  validate_rules
  state_names = effective_states
  machines = state_names.to_h do |state_name|
    rules = rules_for(state_name)
    [state_name, Machine.new(dfa: compile_machine(rules), state_name: state_name)]
  end
  stats = machines.transform_values { |machine| machine.dfa.stats }
  compiled = CompiledSpec.new(machines: machines, rules: @spec.rules, states: state_names, stats: stats)
  compiled.diagnostics = diagnostics_for(compiled, Process.clock_gettime(Process::CLOCK_MONOTONIC) - started_at)
  compiled
end