https://github.com/customcommander/xmachina
A small DSL that compiles to XState.
https://github.com/customcommander/xmachina
dsl finite-state-machine state-machine tagged-template xstate
Last synced: 11 months ago
JSON representation
A small DSL that compiles to XState.
- Host: GitHub
- URL: https://github.com/customcommander/xmachina
- Owner: customcommander
- Created: 2023-09-14T23:00:37.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-11-08T21:49:26.000Z (over 2 years ago)
- Last Synced: 2025-04-09T17:47:40.035Z (about 1 year ago)
- Topics: dsl, finite-state-machine, state-machine, tagged-template, xstate
- Language: JavaScript
- Homepage:
- Size: 58.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
Awesome Lists containing this project
README
[[https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg]]
* XMachina
The goal of this project is to provide a concise yet
declarative language for state machines and to augment
the experience of working with [[https://github.com/statelyai/xstate][XState]].
At this stage this is an educational project only and
I make no commitments to deliver anything useful
at any time.
** TL; DR
#+begin_src javascript
import {interpret} from 'xstate';
import {xmachina} from '@customcommander/xmachina';
const service =
interpret(xmachina`
machine question {
is_valid = ${(ctx, ev) => ev.answer === 42}
initial state searching {
[ON_ANSWER]: is_valid? found
}
final state found {}
}`);
service.start();
service.send({type: 'ON_ANSWER', answer: 10});
// still searching
service.send({type: 'ON_ANSWER', answer: 42});
// found answer!
#+end_src
** Acknowledgment
When I initially set out to write this DSL, I didn't look
around for similar projects. However it didn't take long
until I came across [[https://github.com/lucydsl/liblucy][Lucy]].
I suspect that XMachina will look similar to Lucy in many
ways, but it will also be different as I make my own design
decisions.
I should also mention [[https://github.com/StoneCypher/jssm][JSSM]] and [[https://fsl.tools/][FSL]] for completeness
even though their goals are somewhat different than mine.
Nonetheless people will eventually notice the similarities
and I just wanted to take this opportunity to thank and
give credit to the people who were on this journey
before me.
Thank you!