I need help building a data structure for a state diagram

Kay Schluehr kay at fiber-space.de
Sun May 24 15:42:01 EDT 2009


On 24 Mai, 20:16, Matthew Wilson <m... at tplus1.com> wrote:
> I'm working on a really simple workflow for my bug tracker.  I want
> filed bugs to start in an UNSTARTED status.  From there, they can go to
> STARTED.
>
> From STARTED, bugs can go to FINISHED or ABANDONED.
>
> I know I can easily hard-code this stuff into some if-clauses, but I
> expect to need to add a lot more statuses over time and a lot more
> relationships.
>
> This seems like a crude state diagram.  So, has anyone on this list done
> similar work?
>
> How should I design this so that users can add arbitrary new statuses
> and then define how to get to and from those statuses?
>
> TIA
>
> MAtt

General answer: you can encode finite state machines as grammars.
States as non-terminals and transition labels as terminals:

UNSTARTED: 'start' STARTED
STARTED: 'ok' FINISHED | 'cancel' ABANDONED
ABANDONED: 'done'
FINISHED: 'done'

In some sense each state-machine is also a little language.



More information about the Python-list mailing list