CLI tool
Chevrotain/chevrotain avatar
Chevrotain/chevrotain

Chevrotain: a parser building toolkit for JavaScript without a code generation phase

Parser Building Toolkit for JavaScript

2,820 stars223 forksTypeScriptApache-2.0

At a glance

What is it?
Chevrotain lets you write LL(K) grammars as plain JavaScript and TypeScript functions instead of feeding a grammar file to a generator. It suits engineers who need a lexer and parser inside a JS runtime and are willing to learn its DSL-like API.
Who is it for?
Adopt Chevrotain if your grammar fits LL(K) or you can bring in the chevrotain-allstar plugin for LL(*), and you want the parser to live in the same language as the rest of your code. Do not adopt it if you need a parser generator with a separate grammar file, or if your target runtime is an old browser that the package engines field does not cover.
Can I use it commercially?
Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository received new commits within the last day.
What is it written in?
Mainly TypeScript, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 22, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • Chevrotain/chevrotain2,820 ★ · +16
Star history
Repository2026-09-282026-11-22
Chevrotain/chevrotain2.8k2.8k

16 Stars in the last 55 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

What Chevrotain solves, and who ends up using it

Most parser tools for JavaScript ask you to write a grammar in a separate file and run a generator that emits parser code. Chevrotain takes the other route. The README describes it as a Parser Building Toolkit for JavaScript with built-in support for LL(K), and states that grammars are written as pure JavaScript sources without a code generation phase. That single decision drives everything else about the project.

It is aimed at people who need to read a structured text format inside a JavaScript or TypeScript program: configuration files, query languages, formula syntax, domain specific languages, or a full programming language. The README lists HyperFormula, Langium, Prettier-Java, JHipster Domain Language and Argdown under Where used, which gives a sense of the range. Those are not toy grammars.

If you have ever wanted to debug a parser with the same breakpoints and stack traces you use for the rest of your application, that is the gap Chevrotain is filling.

Tokens, rules and the LL(K) lookahead model

A Chevrotain grammar has two layers. The lexer turns a string into tokens, and the parser turns tokens into a syntax tree. Both are declared as source code. Tokens are created with helpers such as createToken, and parser rules are methods that call sub-rules and token matchers in sequence.

The parser is LL(K). In practice that means the decision of which alternative to take is made by looking ahead at a bounded number of tokens before consuming anything. The README also points to a third party plugin, chevrotain-allstar, for LL(*) grammars, which matters when a fixed lookahead budget is not enough. That plugin is a separate project, not part of the core package.

The trade-off is real. LL parsing cannot handle left-recursive rules directly, so a grammar written the way a textbook would write it may need to be rewritten into a loop. In exchange you get a parser that is ordinary JavaScript, so error messages, stack traces and editor tooling all behave normally. The README links an online playground and a performance page, so the project does invite you to check its speed claims yourself rather than take them on faith.

Installing Chevrotain and parsing your first input

The README gives one npm command. Run it in the project where the parser will live.

bash
npm install chevrotain

For browsers, the README points at prebuilt ESM bundles on UNPKG, for example https://unpkg.com/chevrotain/lib/chevrotain.mjs, with an explicit-version form such as https://unpkg.com/[email protected]/lib/chevrotain.min.mjs. Those are drop-in modules rather than a script tag build.

Once installed, the README points to the Getting Started Tutorial and to sample grammars in examples/grammars for working code. The tutorial is the place to start, because the token and rule API is large enough that guessing at it from the package name alone will not get you far. The repository also ships an examples/tutorial directory and an examples/parser directory, so you can read a complete grammar next to its input.

The compatibility note in the README is worth reading before you write any code. Chevrotain supports the Node.js versions declared in the published package engines field and current evergreen browsers, and the README says legacy runtimes are not supported. It also says the project may rely on modern standard library APIs, so transpilation and polyfills may be needed for older browsers.

Where Chevrotain is the wrong choice

The LL(K) foundation is the first limit. If your language needs unbounded lookahead, the core package will not decide the alternative for you, and the README's answer is the chevrotain-allstar plugin rather than a change to the core. Adding a plugin is a dependency decision, not a configuration flag.

The second limit is runtime support. The README is explicit that legacy runtimes are not supported and that older browsers may need transpilation and polyfills. If you ship to an environment you cannot transpile for, this is a poor fit regardless of how the grammar looks.

The third is the absence of a grammar file. That is a feature for people who want the parser in their application code, and a cost for people who want the grammar to be reviewed, versioned and edited by someone who does not write JavaScript. A generated parser also tends to be easier to hand to a team that treats the grammar as data. Chevrotain's README states the no-code-generation design as a benefit; it is equally a constraint on how your team organizes the work.

How Chevrotain differs from a parser generator

The obvious comparison is a generator such as ANTLR or PEG.js style tools, where you write a grammar in its own syntax and a build step produces parser source. The difference is not cosmetic. With a generator, the grammar is an artifact you can diff and hand to a language designer, and the generated parser is code you generally do not edit. With Chevrotain, the grammar is the code, and there is no generated artifact to keep in sync.

That changes the failure modes. There is no build step that can drift from the grammar, and no generated file to regenerate after an upgrade. On the other side, there is no separate grammar file for a reviewer to read, and the parser is subject to the same refactoring pressure as the rest of your application.

The README links a third party article, Parsing in JavaScript: Tools and Libraries, for a broader survey. That is the right place to look if you are choosing between several JavaScript parser tools rather than deciding whether to use Chevrotain at all.

Maintenance, release cadence and the Apache-2.0 licence

The repository is not archived, and the last push was on 2026-09-24, which is recent. The root package.json shows a monorepo managed with bun workspaces and turbo, with lerna for versioning and publishing, prettier for formatting, husky and commitlint for commit hygiene, and a CI script that runs format validation plus per-subpackage checks. That is a maintained build, not a parked repository.

One thing to note: the recent releases shown are all from 2016, while the README references version 13.2.0 in its UNPKG examples. The release list you can see and the version the README documents do not line up, so check the npm registry for the version you actually intend to install rather than trusting either number alone.

The licence is Apache-2.0, and the repository carries both LICENSE.txt and NOTICE.txt at the top level. Apache-2.0 includes an explicit patent grant and requires that notices be preserved when you redistribute. If you vendor the library or ship it inside a product, the NOTICE.txt file is the thing to read before you do. That is a description of the licence terms, not legal advice.

Editorial conclusion

Adopt Chevrotain if your grammar fits LL(K) or you can bring in the chevrotain-allstar plugin for LL(*), and you want the parser to live in the same language as the rest of your code. Do not adopt it if you need a parser generator with a separate grammar file, or if your target runtime is an old browser that the package engines field does not cover. Before committing, verify three things: that the published package engines field matches your Node.js version, that your grammar has no left recursion, and that the examples in examples/grammars match the shape of your language.

Frequently asked questions

How do I install Chevrotain?

The README gives npm install chevrotain for Node.js projects. For browsers it points at prebuilt ESM bundles on UNPKG, including a minified build with an explicit version number in the URL.

Does Chevrotain need a code generation step?

No. The README states that grammars are written as pure JavaScript sources without a code generation phase, so the grammar and the parser live in the same source files.

What kind of grammars does Chevrotain support?

The core package has built-in support for LL(K) grammars, and the README links a third party plugin, chevrotain-allstar, for LL(*) grammars.

Which runtimes can run Chevrotain?

The README says it supports the Node.js versions declared in the published package engines field and current evergreen browsers, and that legacy runtimes are not supported. Older browsers may need transpilation and polyfills.

Where can I find Chevrotain grammar examples?

The README links sample grammars in the examples/grammars directory on GitHub, and the repository also contains examples/tutorial and examples/parser directories.

Official sources

  1. Chevrotain/chevrotain on GitHub
  2. License: Apache-2.0
  3. Project website
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/chevrotain-chevrotain.svg)](https://hysenlabs.com/projects/chevrotain-chevrotain)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/chevrotain-chevrotain.svg)](https://hysenlabs.com/projects/chevrotain-chevrotain)

Was this useful?