Skip to main content
Tim Disney

Announcing ParserLang

I'm excited to announce a new project I've been working on called ParserLang!

🎉🎉🎉

ParserLang is a parser combinator library for JavaScript with declarative superpowers. In addition to defining parsers in JavaScript, ParserLang allows you to use declarative syntax via template literals:

import { lang } from "parser-lang";

let { calc } = lang`
  num = /[0-9]+/ > ${ch => parseInt(ch, 10)};

  addExpr = num '+' multExpr > ${([left, op, right]) => left + right}
          | num ;

  multExpr = addExpr '*' multExpr > ${([left, op, right]) => left * right}
           | addExpr ;
  
  calc = multExpr ;
`;

calc.tryParse("1+1*2");
// 3

A thing that has surprised me about JavaScript in the post-ES2015 era is how few projects have made use of tagged template literals even though they are incredibly powerful. This is my attempt to rectify that situation.

More details in the documentation.