Language Reference
June 12, 2022 · View on GitHub
This document is still underway.
If you're new to state machines, please read {@page WhatAreStateMachines.md What Are State Machines} instead. This document is a tutorial for the language, at high speed, for people who are already familiar with state machines; a full tutorial on state machines is over there, instead.
Quick start
FSL generally has states, transitions, actions, data, and hooks,
plus the various minor concepts.
Write states by their names, separated by arrows. Chains are valid. Finish with a semicolon.
The basic traffic light example looks like this:
Red -> Green -> Yellow -> Red;
With actions:
Red 'next' -> Green 'next' -> Yellow 'next' -> Red;
Writing three links to an off state using a list:
Red 'next' -> Green 'next' -> Yellow 'next' -> Red;
[Red Yellow Green] 'shut down' -> Off 'start' -> Red;
Hooking an edge, a state, and an action:
const TL = sm`
Red 'next' -> Green 'next' -> Yellow 'next' -> Red;
[Red Yellow Green] 'shut down' -> Off 'start' -> Red;
`;
TL.hook('Red', 'Green', () =>
console.log('Go go go!'));
TL.hook_entry('Off', () =>
console.log('Where did the power go?'));
TL.hook_global_action('next', () =>
console.log('next color now'));
It's honestly actually that easy. Let's get into the details.
Terminology
FSL is a string-based domain-specific language for finite state machines.
It's oriented towards brevity, readability, and expressive power.
jssm is a parser and executing machine for FSL language machines. It's
oriented towards heavy testing, speed, and ease of installation.
This document expresses the FSL language in its current state.