-
-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Nested states (compound / parallel) #329
Conversation
86efa27
to
ba50602
Compare
0a548c1
to
cf2cc43
Compare
I like the idea of compound states, as they tend to make my life a lot easier. I will have a look at it when I find some time. |
c28a40c
to
64e9bc8
Compare
3fef20a
to
c1fc3bd
Compare
8315afd
to
4abd2ab
Compare
4abd2ab
to
a447f6f
Compare
93fd520
to
db6aa0d
Compare
Wow looking for this feat, required in my project. |
d98ebff
to
a8a139a
Compare
a8a139a
to
c765228
Compare
65536cd
to
2c427cd
Compare
2aa8336
to
0e363ce
Compare
|
On example
The automata-like behavior this library took over the last 5 years pleases me. Thanks for the contribution to community. |
Closing in favor of #501 |
Experimental branch to play with compound and parallel states.
On this PR, I'm trying to implement a "simple" example from SCXML called "microwave", that has parallel and compound states.
Microwave
SCXML
From the MicrowaveParallel example spec.
Using python-statemachine
** Experimental syntax **
Note that I'm using a
class
as a namespace for constructing aState
instance. Not a traditional choice, but I like the syntax so far.Diagram is already rendering nested states:
If you're reading this, feedback is welcome. Please let me know what you think.
I am trying to handle nested states in the lib (it works well for simple machines), but I have been reading quite a bit about statecharts (https://www.w3.org/TR/scxml/), and they solve a common problem with state machines: state explosion. More complex use cases become infeasible to express with a simple machine.
These nested states work in two ways:
The example I am trying to implement coming from SCXML documentation is a "microwave", in it, the "oven" and the "door" are two parallel states, as they work independently. The oven and the door are also compound states, as they have substates.
The syntax I am trying to validate is "how to express in a pythonic way" this hierarchy. The best syntax I came up with is the one in the PR, where I made "creative use" of the block context generated by a class to capture the variables created inside the context as substates of the parent state, and I use the class name and optional metaclass attributes to parameterize the parent state. The result is an instance of a 'State' already filled with the substrates.
So this:
Works like syntactic sugar for this (but keeping the parent namespace clean):
TODO