nearley vs chevrotain vs pegjs vs jison
JavaScript Parsing Libraries Comparison
1 Year
nearleychevrotainpegjsjisonSimilar Packages:
What's JavaScript Parsing Libraries?

JavaScript parsing libraries are tools that help developers create parsers for interpreting and transforming text data, such as programming languages or domain-specific languages (DSLs). These libraries provide the necessary functionality to define grammars, tokenize input, and generate abstract syntax trees (ASTs) that can be manipulated or analyzed. They are essential for building compilers, interpreters, and other tools that require understanding structured text. Each library has its own strengths, design principles, and use cases, making it important to choose the right one based on project requirements.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
nearley3,135,7383,658-1984 years agoMIT
chevrotain1,569,1482,5661.35 MB482 years agoApache-2.0
pegjs382,7684,851-1169 years agoMIT
jison55,5964,364-1618 years agoMIT
Feature Comparison: nearley vs chevrotain vs pegjs vs jison

Performance

  • nearley:

    Nearley is designed for ease of use and flexibility, but its performance may not match that of Chevrotain in high-performance scenarios. It is well-suited for rapid development and prototyping rather than production-level performance.

  • chevrotain:

    Chevrotain is optimized for speed and can handle large inputs with minimal overhead. It uses a lexer and parser that are designed to work together efficiently, making it one of the fastest parsing libraries available.

  • pegjs:

    PEG.js generates parsers based on Parsing Expression Grammar (PEG), which can be slower than other options for large inputs. However, it excels in creating simple and readable grammars, making it a good choice for smaller projects.

  • jison:

    Jison generates parsers from a BNF grammar, which can be efficient but may not be as fast as Chevrotain for certain use cases. Its performance is generally good, but it may struggle with very large inputs or complex grammars.

Grammar Definition

  • nearley:

    Nearley supports a more expressive grammar definition syntax, allowing for the use of multiple grammar files and a wide range of parsing techniques. This flexibility is beneficial for complex parsing scenarios but may introduce a steeper learning curve.

  • chevrotain:

    Chevrotain allows for the definition of grammars using a JavaScript-based syntax, providing a high level of flexibility and control. It supports complex grammars and can handle ambiguities effectively, making it suitable for advanced parsing tasks.

  • pegjs:

    PEG.js uses Parsing Expression Grammar (PEG) for grammar definitions, which is intuitive and allows for clear and concise grammar specifications. However, it may be less flexible than other libraries when dealing with complex grammars.

  • jison:

    Jison uses a BNF-like syntax for grammar definitions, which is familiar to many developers. It is straightforward to use but may require additional effort to manage complex grammars or handle ambiguities.

Error Handling

  • nearley:

    Nearley includes built-in error reporting and recovery options, making it easier to manage parsing errors. Its flexibility allows developers to customize error handling to suit their specific needs.

  • chevrotain:

    Chevrotain provides robust error handling capabilities, allowing developers to define custom error messages and recovery strategies. This is crucial for building user-friendly parsers that can gracefully handle unexpected input.

  • pegjs:

    PEG.js offers error handling features, but they may not be as extensive as those in Chevrotain. Developers can implement custom error messages, but the library may require additional effort to achieve comprehensive error management.

  • jison:

    Jison has basic error handling features, but it may not provide the level of detail or customization that Chevrotain offers. Developers may need to implement additional logic for comprehensive error handling.

Community and Ecosystem

  • nearley:

    Nearley has an active community and is often used in academic and experimental projects. Its flexibility and expressive grammar definitions make it appealing for innovative parsing solutions.

  • chevrotain:

    Chevrotain has a growing community and a rich ecosystem of plugins and extensions. Its performance and flexibility have garnered attention, making it a popular choice for modern parsing tasks.

  • pegjs:

    PEG.js has a dedicated community and is well-documented, making it accessible for new users. However, its ecosystem may not be as extensive as that of Chevrotain or Nearley.

  • jison:

    Jison has been around for a while and has a stable user base, but its community is smaller compared to newer libraries. It is still a reliable choice for many parsing needs, especially for those familiar with its syntax.

Learning Curve

  • nearley:

    Nearley has a steeper learning curve due to its expressive grammar definitions and flexibility. It may require more time to master, especially for complex parsing tasks.

  • chevrotain:

    Chevrotain has a moderate learning curve due to its flexibility and the need to understand its API. However, once grasped, it allows for powerful parsing capabilities.

  • pegjs:

    PEG.js is considered user-friendly, especially for those new to parsing. Its clear grammar syntax makes it easier to get started, but mastering advanced features may take time.

  • jison:

    Jison is relatively easy to learn for those familiar with BNF grammar, making it accessible for developers who want to quickly implement a parser without extensive background knowledge.

How to Choose: nearley vs chevrotain vs pegjs vs jison
  • chevrotain:

    Choose Chevrotain if you need a fast and efficient parser that supports complex grammars and offers a high degree of flexibility. It is particularly well-suited for applications requiring performance and is designed to handle large inputs efficiently.

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}
}