Skip to content

Instantly share code, notes, and snippets.

@rgchris
Last active July 21, 2017 22:05
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 rgchris/67cd497c097d7ff768a15424057bbdea to your computer and use it in GitHub Desktop.
Save rgchris/67cd497c097d7ff768a15424057bbdea to your computer and use it in GitHub Desktop.
Contrived Parse-based FSM
#!/usr/local/bin/red
Red [
Title: "Contrived FSM Example"
Date: 21-Jul-2017
Author: "Christopher Ross-Gill"
]
state: mark: none
use: func ['target [word!]][
probe to tag! target
state: get in states target
]
states: make object! [
is-a: [
#"a" (print "A in A")
| #"b" (print "B in A" use is-b)
| end (print "End in A") fail
]
is-b: [
mark: #"a" (print "A in B" use is-a) :mark
| #"b" (print "B in B")
| end (print "End in B" use is-a)
]
]
parse-abba: func [series [string!]][
use is-a
parse series [while [state]]
]
parse-abba probe "aba"
print ""
parse-abba probe "bab"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment