Skip to content

Latest commit

 

History

History
204 lines (173 loc) · 3.39 KB

state.md

File metadata and controls

204 lines (173 loc) · 3.39 KB
Error in user YAML: (<unknown>): did not find expected alphabetic or numeric character while scanning an alias at line 6 column 9
---
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
---

type state picture

atomic/simple

  • keyword: state
  • symbol: {$declarations$}
state P {...}

Read as: "state P have ..."

declaration are optional

transition
  • 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 ✔

compound/composite/nested

  • keyword: compund|composite
  • symbol: $keyword state {$declarations$}
compound state P {...}

Read as: "inside compound state P, ..."

typestatecasting

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"

transition to nested state
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"

parallel

  • keyword: parallel
parallel state P {
  state P1 {...}
  state P2 {...}
}

Read as: "inside state P, there is state P1 and P2 which run on parallel"

typestatecasting

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

history shallow & deep

default is shallow

  • keyword: history or cache
history state P {...}
cache state P {...}

Read as: "inside state P which is cacheable, ..."

typestatecasting
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"

shallow
  • 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, ..."

deep
  • 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, ..."