Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bnookala/fsm
A simple FSM implementation
https://github.com/bnookala/fsm
Last synced: about 2 months ago
JSON representation
A simple FSM implementation
- Host: GitHub
- URL: https://github.com/bnookala/fsm
- Owner: bnookala
- License: mit
- Created: 2013-11-29T01:33:24.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2013-11-30T19:11:44.000Z (about 11 years ago)
- Last Synced: 2024-10-26T00:30:30.636Z (about 2 months ago)
- Language: Python
- Size: 121 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FSM
A quick and dirty implementation of a deterministic finite state machine.
## Quick Example
from fsm import Machine
# Define states, alphabet, transitions, start, and end
machine = Machine.from_arguments(states, alphabet, transitions, start, end)
ret_value = machine.run(some_input)… or check out example.py in the root level directory.
## Documentation
### from_arguments
A **class method**, that returns a Machine instance. Use this to construct a Machine instance.##### Arguments:
- **states**: a list of possible states for the Machine. Each state is a unique string.
- **alphabet**: a list of possible "choices" for each state. Each "letter" is a unique string.
- **transitions** - a dict that maps to dicts. Each key is a state. The dict that the key maps to is keyed by an alphabet letter, and maps to the next state:transitions = {
'some_state': {
'a': 'next_state',
'b': 'previous_state'
},
}
- **start** - a state to start the machine at.
- **end** - a list of acceptable end states.##### Returns:
An instance of the state machine.### run
An **instance** method, that runs an input on the machine instance.##### Arguments:
**input** - a string input to run the Machine instance on.##### Keyword Arguments:
**console_output** - Set this to False if you do not want to print to the console. (Defaults to True).##### Returns:
A boolean indicating if the string passed or failed on the machine instance.