Module: Mealy
- Defined in:
- lib/mealy.rb,
lib/mealy/dsl.rb,
lib/mealy/label.rb,
lib/mealy/runner.rb,
lib/mealy/helper_methods.rb
Overview
A Mealy finite state machine.
For usage information please read README.
Defined Under Namespace
Modules: DSL, HelperMethods Classes: AnyLabel, Executer, Label, Runner, UnexpectedTokenError
Constant Summary collapse
- ANY =
Wildcard for machine input tokens that match anything.
AnyLabel.instance
Class Method Summary collapse
-
.included(klass) ⇒ Object
Module.included hook.
Instance Method Summary collapse
-
#emit(token) ⇒ Object
emit tokens from the DSL blocks.
-
#execute(enum) ⇒ Object
Runs the Mealy machine on the given input.
-
#run(enum) {|emit| ... } ⇒ Enumerator
Runs the Mealy machine on the given input.
Class Method Details
.included(klass) ⇒ Object
Module.included hook. Resets the state transitions for a class
56 57 58 59 |
# File 'lib/mealy/dsl.rb', line 56 def self.included(klass) klass.class_eval { @transitions = Hash.new { Hash.new({}) } } klass.extend(DSL) end |
Instance Method Details
#emit(token) ⇒ Object
emit tokens from the DSL blocks
19 20 21 22 |
# File 'lib/mealy.rb', line 19 def emit(token) return unless @emit_runner @emit_runner.emit(token) end |
#execute(enum) ⇒ Object
Runs the Mealy machine on the given input.
40 41 42 |
# File 'lib/mealy.rb', line 40 def execute(enum) Executer.new(self).run(enum) end |
#run(enum) {|emit| ... } ⇒ Enumerator
Runs the Mealy machine on the given input. Outputs a stream of tokens by yielding each emitted token to the given block.
29 30 31 32 33 34 35 |
# File 'lib/mealy.rb', line 29 def run(enum, &block) return to_enum(:run, enum) unless block_given? @emit_runner = Runner.new(self) @emit_runner.run(enum, &block) @emit_runner = nil end |