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

JavaScript parsing libraries are tools that facilitate the creation of parsers for interpreting and processing structured text, such as programming languages or data formats. These libraries provide developers with the ability to define grammars and generate parsers that can analyze and transform input text into a more manageable format, such as Abstract Syntax Trees (ASTs). This is particularly useful in scenarios like building compilers, interpreters, or domain-specific languages (DSLs). Each library has its unique features, strengths, and weaknesses, making them suitable for different use cases in web development.

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

Grammar Definition

  • nearley:

    Nearley uses a more expressive grammar definition that supports ambiguous grammars and can handle a wider range of parsing scenarios. Its syntax is flexible, allowing for more complex constructs and patterns.

  • pegjs:

    PEG.js employs Parsing Expression Grammar (PEG), which provides a clear and concise way to define grammars. It allows for recursive definitions and supports features like lookahead and backtracking, making it powerful for complex parsing.

  • jison:

    Jison allows you to define grammars using a BNF-like syntax, which is straightforward and easy to understand. It supports basic features like operators and precedence, making it suitable for simple parsing tasks.

Performance

  • nearley:

    Nearley is optimized for performance and can handle large grammars efficiently. Its ability to manage ambiguity and complex constructs makes it suitable for performance-critical applications.

  • pegjs:

    PEG.js offers good performance for most use cases, but its backtracking capabilities can lead to slower parsing times in certain scenarios, especially with highly ambiguous grammars.

  • jison:

    Jison is generally fast for small to medium-sized grammars but may struggle with performance for more complex parsing tasks due to its simpler parsing techniques.

Error Handling

  • nearley:

    Nearley has robust error handling features, enabling detailed error reporting and recovery options. This is particularly useful for complex grammars where understanding parsing failures is crucial.

  • pegjs:

    PEG.js offers clear error reporting that indicates where parsing failed, making it easier for developers to debug issues. However, handling errors in a user-friendly manner may require additional implementation.

  • jison:

    Jison provides basic error handling capabilities, allowing developers to define custom error messages and recovery strategies, but it may require additional work for more complex error scenarios.

Community and Ecosystem

  • nearley:

    Nearley has a growing community and is gaining popularity for its flexibility and power. It has a range of plugins and extensions available, enhancing its capabilities.

  • pegjs:

    PEG.js has a well-established community with numerous resources, tutorials, and examples available. Its popularity ensures that developers can find support and guidance easily.

  • jison:

    Jison has a smaller community compared to the others, which may result in fewer resources and examples available for developers. However, it is still widely used for simpler projects.

Learning Curve

  • nearley:

    Nearley has a moderate learning curve due to its advanced features and flexibility. While it is powerful, developers may need time to fully understand its capabilities and best practices.

  • pegjs:

    PEG.js is also beginner-friendly, but its unique grammar definition style may take some time to learn. Once understood, it provides a powerful toolset for complex parsing tasks.

  • jison:

    Jison has a relatively low learning curve, making it accessible for beginners who want to get started with parsing quickly. Its straightforward syntax is easy to grasp.

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

    Opt for Nearley if you require a powerful and flexible parser that supports complex grammars and advanced features like ambiguity resolution. It is suitable for larger projects where you might need to handle intricate parsing scenarios or where performance is a critical concern.

  • pegjs:

    Select PEG.js if you prefer a parser generator that uses Parsing Expression Grammar (PEG) and offers a clean and intuitive syntax for defining grammars. It is ideal for projects that need a balance between simplicity and the ability to handle complex parsing tasks.

  • jison:

    Choose Jison if you need a simple and straightforward parser generator that is easy to integrate into existing projects. It is particularly useful for small to medium-sized projects where you want to quickly define a grammar and generate a parser without extensive configuration.

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