Options
All
  • Public
  • Public/Protected
  • All
Menu

@thi.ng/fsm

@thi.ng/fsm

npm (scoped) npm downloads Twitter Follow

This project is part of the @thi.ng/umbrella monorepo.

About

Functional & composable primitives for building declarative, transducer based Finite-State machines and parsers for arbitrary input data streams (not necessarily string based).

See the minimal markdown parser example for a concrete use case.

Status

ALPHA. This package will be merged with and update the existing @thi.ng/transducers-fsm package.

Installation

yarn add @thi.ng/fsm

Dependencies

Usage examples

Checkout the minimal Markdown parser example:

Source code | Live demo

The parser itself is defined here: @thi.ng/hiccup-markdown

import * as fsm from "@thi.ng/fsm";

API

There're two key concepts provided by this package:

Matchers

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.

See docs strings in /src folder for now.

FSM transducer

The fsm() function is a Finite-state machine transducer w/ support for single lookahead value. It takes an object of states and their matchers, an arbitrary context object which will be uses as state container for the various matchers and an initial state ID.

The returned transducer consumes inputs of type T and produces results of type R. The results are produced by callbacks of the given state matchers. For each input consumed, the callbacks can produce any number of result values. If a callback returns a result wrapped w/ reduced(), the FSM causes early termination of the overall transducer pipeline.

Authors

  • Karsten Schmidt

License

© 2018 Karsten Schmidt // Apache Software License 2.0

Generated using TypeDoc