---
title: Declaring State
references:
- https://www.uml-diagrams.org/state-machine-diagrams.html
- https://github.com/sverweij/state-machine-cat
- https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=cb3b16f55f4d6ad25fc54f5058c7dacf
status: **so far so good**
syntax:
- scdlang
- rust
---
- keyword: state
- symbol:
{
$declarations$ }
state P {...}
Read as: "state P have ..."
declaration are optional
- symbol: $current_state
->
$next_state
A -> B
Read as: "state A transition to state B" ✔
B <- A
Read as: "state B transition from state A" ✔
A,C,D -> B
Read as: "state A, C, and D transition to state B"
B <- A,C,D
Read as: "state B transition from either state A, C, or D"
B -> B
or
->> B
Read as: "state B transition to state B" ✔
A -> B
B -> B
or
A -> B
->> B
or
A ->> B
Read as: "state A transition to state B" then loop transition to itself ✔
- keyword: compund|composite
- symbol:
$keyword state {
$declarations$ }
compound state P {...}
Read as: "inside compound state P, ..."
This will force state B to be a compound state when transitioning from A
state B { ... }
A -> [B]
Read as: "state A transition to compound state B"
state B {
C -> A
}
A -> B[C]
or
compound state B {
C -> A
}
A -> B[C]
Read as: "state A transition to compound state B"
- keyword: parallel
parallel state P {
state P1 {...}
state P2 {...}
}
Read as: "inside state P, there is state P1 and P2 which run on parallel"
This will force state B to be a parallel state when transitioning from A
state B { ... }
A ->| B,C
Read as: "state A fork to state B and state C"
state B { ... }
B,C |-> A
Read as: "state B and state C join to state A"
examples
A ->| B,D,E
parallel { // 👈 is this really neccessary 🤔
{
B -> L1 @ C
L1 -> L2
L2 -> L
}
D -> G
E -> I
}
L,G |-> A
A,I |-> Z
no transitions should exist between parallel state block
default is shallow
- keyword: history or cache
history state P {...}
cache state P {...}
Read as: "inside state P which is cacheable, ..."
state P { ... }
A -> P[history]
Read as: "state A transition to pervious state of P*"
state P { ... }
P[cache] -> A
Read as: "cache the current state of P then transition to state A"
- keyword: shallow.
history[shallow] state P {...}
state[shallow.cache] B {...}
or
history state P {...}
state[cache] B {...}
Read as: "inside state P which is cacheable, ..."
- keyword: deep.
- symbol:
*
history[deep] state P {...}
state[deep.cache] B {...}
or
history[*] state P {...}
Read as: "inside state P and all state inside state P which is cacheable, ..."