Analysis updated 2026-07-03
Build a parser for a custom file format or mini programming language by writing a grammar file and compiling it with nearley
Handle left-recursive grammar rules that popular JavaScript parser generators like PEG.js cannot process
Parse streaming input that arrives incrementally without waiting for the full text to be available
Generate railroad diagrams and fuzz tests from your grammar file to document and stress-test your parser automatically
| kach/nearley | webrtchacks/adapter | zhblue/hustoj | |
|---|---|---|---|
| Stars | 3,738 | 3,738 | 3,738 |
| Language | JavaScript | JavaScript | JavaScript |
| Setup difficulty | moderate | easy | hard |
| Complexity | 3/5 | 2/5 | 4/5 |
| Audience | developer | developer | developer |
Figures from each repo's GitHub metadata at analysis time.
Requires Node.js, grammar compilation adds a build step that needs to be integrated into your project workflow.
Nearley is a JavaScript library for building parsers. A parser is a program that reads text written in a specific format and turns it into structured data your code can work with. If you have ever needed to interpret a custom file format, a mini programming language, or a structured command syntax, a parser is what you would build, and nearley is a toolkit that makes that job much easier. The library is built around the Earley parsing algorithm, which is a technique known for being able to handle a very wide range of grammar definitions, including some patterns that trip up other popular JavaScript parser tools. Most other parsers in the JavaScript ecosystem have restrictions on the kinds of grammars they accept, such as struggling with left-recursive rules (where a grammar rule refers back to itself on the left side). Nearley handles these without issue. You describe your language using a purpose-built grammar syntax, write those rules in a .ne file, and nearley compiles that into a parser you can use in Node.js or in the browser. The library also includes a set of supporting tools: you can generate railroad diagrams (visual flowcharts of your grammar), create fuzz testers to throw random inputs at your parser, and write grammar-aware tests. It integrates with several editors and works with external lexers, with moo being the recommended option. Nearley supports streaming input, meaning it can parse data that arrives incrementally rather than all at once. It also handles ambiguous grammars, cases where a single input can be interpreted in more than one valid way, by returning all possible parsings. The README notes real-world uses including university AI and linguistics courses, file format parsers, markup language compilers, and compilers for real programming languages. The nearley compiler itself is built with nearley.
A JavaScript parser toolkit that lets you define a grammar in a .ne file and compile it into a parser that handles left-recursive and ambiguous grammars where other JS parser tools fall short.
Mainly JavaScript. The stack also includes JavaScript, Node.js.
Setup difficulty is rated moderate, with roughly 30min to a first successful run.
Mainly developer.
This repo across BitVibe Labs
Verify against the repo before relying on details.