Created
September 9, 2017 19:43
-
-
Save Skrylar/fae89168d08e1351c21942917922fbfa to your computer and use it in GitHub Desktop.
Testing syntax for a fsm generator.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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