nearley vs pegjs vs jison
Choose a grammar and parser-generation model
nearleypegjsjisonSimilar Packages:

Choose a grammar and parser-generation model

Compare bottom-up generation, Earley parsing and ordered-choice PEG grammars.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
nearley13,994,9573,738-1986 years agoMIT
pegjs647,2144,902-11710 years agoMIT
jison101,1454,376-1629 years agoMIT

Choose the grammar semantics first

Jison generates bottom-up parsers from its supported grammar forms. Nearley uses an Earley-based workflow and can expose multiple parses for an ambiguous grammar. PEG.js generates parsers from PEG notation, where ordered choice has different semantics from collecting every valid interpretation. These are not three interchangeable runners for the same grammar file.

Separate generation from use

A grammar is compiled or processed through the chosen tool's workflow before the resulting parser is used according to its module/runtime contract. Jison's generated output, Nearley's compiled grammar/runtime setup and PEG.js generation API require different integration. Do not use a repository's unpublished example as proof that an installed release has the same API.

Define the result and error contract

Semantic actions, parse trees and error handling are part of the language tool. Successful tokenization is not a completed parse, and a parsed tree does not establish that a domain value satisfies application rules. Include representative ambiguous, incremental and ordinary grammar cases when evaluating the choice.

Choose by the language and intended authoring workflow rather than an absolute speed ranking or the age of a package. Migrating means adapting grammar rules, actions and runtime integration, not only replacing a generator command.

How to Choose: nearley vs pegjs vs jison

  • nearley:

    Choose its Earley-based grammar/runtime workflow when incremental input and multiple parses are useful.

  • pegjs:

    Choose the installed PEG.js grammar and generator interface when ordered-choice PEG behavior matches the language.

  • jison:

    Choose a Bison-style grammar and generated bottom-up parser when that grammar format and its supported algorithms fit.

README for nearley

nearley ↗️

JS.ORG npm version

nearley is a simple, fast and powerful parsing toolkit. It consists of:

  1. A powerful, modular DSL for describing languages
  2. An efficient, lightweight Earley parser
  3. Loads of tools, editor plug-ins, and other goodies!

nearley is a streaming parser with support for catching errors gracefully and providing all parsings for ambiguous grammars. It is compatible with a variety of lexers (we recommend moo). It comes with tools for creating tests, railroad diagrams and fuzzers from your grammars, and has support for a variety of editors and platforms. It works in both node and the browser.

Unlike most other parser generators, nearley can handle any grammar you can define in BNF (and more!). In particular, while most existing JS parsers such as PEGjs and Jison choke on certain grammars (e.g. left recursive ones), nearley handles them easily and efficiently by using the Earley parsing algorithm.

nearley is used by a wide variety of projects:

nearley is an npm staff pick.

Documentation

Please visit our website https://nearley.js.org to get started! You will find a tutorial, detailed reference documents, and links to several real-world examples to get inspired.

Contributing

Please read this document before working on nearley. If you are interested in contributing but unsure where to start, take a look at the issues labeled "up for grabs" on the issue tracker, or message a maintainer (@kach or @tjvr on Github).

nearley is MIT licensed.

A big thanks to Nathan Dinsmore for teaching me how to Earley, Aria Stewart for helping structure nearley into a mature module, and Robin Windels for bootstrapping the grammar. Additionally, Jacob Edelman wrote an experimental JavaScript parser with nearley and contributed ideas for EBNF support. Joshua T. Corbin refactored the compiler to be much, much prettier. Bojidar Marinov implemented postprocessors-in-other-languages. Shachar Itzhaky fixed a subtle bug with nullables.

Citing nearley

If you are citing nearley in academic work, please use the following BibTeX entry.

@misc{nearley,
    author = "Kartik Chandra and Tim Radvan",
    title  = "{nearley}: a parsing toolkit for {JavaScript}",
    year   = {2014},
    doi    = {10.5281/zenodo.3897993},
    url    = {https://github.com/kach/nearley}
}