Simple Yet Versatile Tool for Combined Lexical Analysis and Grammar Parser -- i.e. making language interpreters/compilers

Lexiparse is a JavaScript toolkit for building business domain-specific languages. You describe a grammar as plain JavaScript objects — terminal rules as regular expressions, compound rules as token sequences with optional callbacks — and Lexiparse hands you an interpreter that lexes, parses, and executes source in one pass. It's built so domain experts can write readable business rules while IT keeps control of how those rules run.

Highlights

  • Grammar as data. Define a language with a JavaScript object: regex terminal rules, sequence rules, and callbacks that compute values as the parse proceeds.
  • Operator precedence. Configure precedence per operator so expressions like rate * amount + tax evaluate correctly without hand-built rules.
  • Business-friendly errors. Multi-error collection with line and column, surrounding context, a caret pointer, and suggestions — find many problems in a single pass.
  • Developer tooling. Interactive debugging with breakpoints and watch variables, a testing framework with assertions and scenarios, a documentation generator (Markdown/HTML/JSON), and a live REPL.
  • Module system. A standard library of business modules (core, finance, healthcare, insurance, analytics, business) with import/export and dependency management.
  • Runs everywhere. Deploy the same engine in the browser, on Node.js, or compiled to a standalone executable with QuickJS.

A taste

const Lexiparse = require('lexiparse');

const grammar = {
    'expr': [
        ['(', ':expr', ')'],
        [':expr', '*', ':expr', multiply],
        [':expr', '+', ':expr', add],
        ':number'
    ],
    'number': [/^[+-]?\d+(\.\d+)?/, function(detail) {
        detail.type = 'number';
        detail.value = Number(detail.found[0]);
    }]
};

const interpreter = new Lexiparse(grammar, {
    caseful: false,
    ignore: [' ', '\t', '\n'],
    precedence: { '+': 5, '*': 6 }
});

interpreter.run("output 5.5 * 100 + 0.08 * 1000");

Installation

Install from npm:

npm install lexiparse

Or clone the source and run the examples:

git clone https://github.com/Solifugus/lexiparse.git
cd lexiparse
npm install
npm test
node examples/coreds.js

Downloads & installation

Builds are coming soon. Grab the source from GitHub for now.