Class: Flexr::Automaton::Compiler
- Inherits:
-
Object
- Object
- Flexr::Automaton::Compiler
- Defined in:
- lib/flexr/automaton/compiler.rb
Instance Method Summary collapse
- #compile ⇒ Object
-
#initialize(spec) ⇒ Compiler
constructor
A new instance of Compiler.
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
#compile ⇒ Object
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 |