Skip to content

Instantly share code, notes, and snippets.

@Skrylar
Created September 9, 2017 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Skrylar/fae89168d08e1351c21942917922fbfa to your computer and use it in GitHub Desktop.
Save Skrylar/fae89168d08e1351c21942917922fbfa to your computer and use it in GitHub Desktop.
Testing syntax for a fsm generator.
import macros
macro fsm*(name, definition: untyped): untyped =
echo treeRepr definition
fsm butt:
# default actions are taken when getting an input without that state
# knowing what to do about it
default:
message:
echo "Client said something, but it's not a valid state for that."
connecting:
entry:
echo "Sending auth request."
exit:
echo "Leaving connection state."
receivedAuthToken:
echo "We have a token."
goto authenticated
authenticated:
message(text: string):
echo "Client: ", text
# Can assign a superstate; if you are in this state, you are "also" in
# the super state, additionally calls default to the superstate (and
# so on upwards until default is reached.)
superuser {.super: authenticated.}:
reboot:
echo "Rebooting server."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment