Skip to content

didierdemoniere/langkit

Repository files navigation

langkit

A compact and expressive DSL and expression interpreter toolkit

Install

$ npm install langkit

Usage

import { createLexer, createParser } from 'langkit';

const calcLexer = createLexer({
  plus: /\+/,
  number: /\d+(?:\.\d+)?/,
  space: {
    pattern: /\s+/,
    skip: true,
  },
});

const calculate = createParser(calcLexer, (h) => {
  return h.fromTokens(['number', 'plus', 'number'], ([left, _, right]) => {
    return Number(left.value) + Number(right.value);
  });
});

console.log(calculate('5 + 45'));
// => 50

examples

About

DSL and expression interpreter toolkit

Resources

License

Stars

Watchers

Forks

Packages

No packages published