This project is part of the @thi.ng/umbrella monorepo.
Functional & composable primitives for building declarative, transducer based Finite-State machines and parsers for arbitrary input data streams (not necessarily string based).
ALPHA. This package will be merged with and update the existing @thi.ng/transducers-fsm package.
yarn add @thi.ng/fsm
Checkout the minimal Markdown parser example:
The parser itself is defined here: @thi.ng/hiccup-markdown
import * as fsm from "@thi.ng/fsm";
There're two key concepts provided by this package:
Matchers are composable functions which receive a single input value and attempt to match it to their configured criteria / patterns. Matchers also support optional user callbacks, which are executed when a match was made and are responsible for state transitions, state update and production of any result values.
range()(plus multiple presets)
See docs strings in
/src folder for now.
function is a Finite-state machine transducer / iterator with support
for single lookahead values. Takes an object of
states and their
matchers, an arbitrary context object and an
initial state ID.
The returned transducer consumes inputs of type
T and produces results
R. The results are produced by callbacks of the given state
matchers. Each can produce any number of values. If a callback returns a
result wrapped w/
reduced(), the FSM causes early termination of the
overall transducer pipeline. Failed state callbacks too can produce
outputs, but will afterwards terminate the FSM.
IllegalStateError will be thrown if a transition to an undefined
state ID occurs.
update function will be invoked for each input prior to
executing the currently active state matcher. It is intended to update
the context object (e.g. to update input location info for generating
If the optional
src iterable is given, the function returns a
transforming iterator of the FSM results.
© 2018 Karsten Schmidt // Apache Software License 2.0
Generated using TypeDoc