nearley vs antlr4 vs pegjs vs jison
パーサー生成ライブラリ
nearleyantlr4pegjsjison
パーサー生成ライブラリ

パーサー生成ライブラリは、文法定義に基づいてソースコードやテキストを解析するためのツールを提供します。これらのライブラリは、コンパイラ、インタプリタ、データ変換ツールなどで使用され、入力データを構造化された形式に変換する役割を果たします。antlr4は強力なLL(*)パーサー生成ツールで、多言語対応のコード生成が可能です。jisonはJavaScript向けのLR(1)パーサー生成ツールで、Bisonに似た文法を使用します。nearleyは柔軟なEarleyパーサー生成ツールで、曖昧な文法や複雑な構造を扱うことができます。pegjsはPEG(Parsing Expression Grammar)に基づくパーサー生成ツールで、直感的な文法定義が可能です。

npmのダウンロードトレンド
3 年
GitHub Starsランキング
統計詳細
パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
nearley4,112,1933,729-1985年前MIT
antlr4859,66718,5563.09 MB1,0441年前BSD-3-Clause
pegjs698,1264,915-1179年前MIT
jison83,6834,387-1638年前MIT
機能比較: nearley vs antlr4 vs pegjs vs jison

文法タイプ

  • nearley:

    nearleyはEarleyアルゴリズムを使用し、曖昧な文法や非決定性の文法を解析できます。

  • antlr4:

    antlr4はLL(*)文法を使用し、複雑な文法や再帰的な構造を解析できます。

  • pegjs:

    pegjsはPEG(Parsing Expression Grammar)を使用し、直感的で競合の少ない文法を定義できます。

  • jison:

    jisonはLR(1)文法を使用し、決定性のある文法を効率的に解析します。

コード生成

  • nearley:

    nearleyはJavaScript向けのパーサーコードを生成します。

  • antlr4:

    antlr4は多言語(Java、C++、Python、JavaScriptなど)向けのコードを生成できます。

  • pegjs:

    pegjsはJavaScript向けのパーサーコードを生成します。

  • jison:

    jisonはJavaScript向けのパーサーコードを生成します。

文法定義の直感性

  • nearley:

    nearleyは柔軟な文法定義が可能ですが、曖昧な文法を扱うための理解が必要です。

  • antlr4:

    antlr4は複雑な文法定義が可能ですが、学習曲線がやや急です。

  • pegjs:

    pegjsは直感的でシンプルな文法定義が可能で、初心者にも扱いやすいです。

  • jison:

    jisonはBisonに似た文法定義を使用し、既存のBisonユーザーには馴染みやすいです。

パフォーマンス

  • nearley:

    nearleyはEarleyアルゴリズムを使用しているため、一般的には他のパーサーよりも遅いですが、曖昧な文法を扱う場合に有利です。

  • antlr4:

    antlr4は最適化されたパーサーを生成し、高速な解析が可能です。

  • pegjs:

    pegjsはPEGに基づく解析を行い、競合のない文法では高速に動作します。

  • jison:

    jisonはLR(1)パーサーとして効率的な解析を提供します。

Ease of Use: Code Examples

  • nearley:

    nearleyは柔軟な文法定義が可能ですが、曖昧な文法を扱うための理解が必要です。

  • antlr4:

    antlr4は複雑な文法定義が可能ですが、学習曲線がやや急です。

  • pegjs:

    pegjsは直感的でシンプルな文法定義が可能で、初心者にも扱いやすいです。

  • jison:

    jisonはBisonに似た文法定義を使用し、既存のBisonユーザーには馴染みやすいです。

選び方: nearley vs antlr4 vs pegjs vs jison
  • nearley:

    曖昧な文法や複雑な構造を扱う必要がある場合はnearleyを選択してください。Earleyアルゴリズムを使用しているため、任意の文法を解析できます。

  • antlr4:

    複雑な文法や多言語対応が必要な場合はantlr4を選択してください。特に、パフォーマンスと柔軟性が求められる大規模なプロジェクトに適しています。

  • pegjs:

    直感的な文法定義とシンプルなパーサーが必要な場合はpegjsを選択してください。PEGに基づいているため、文法の競合を避けやすく、読みやすい定義が可能です。

  • jison:

    JavaScript環境でLR(1)パーサーが必要な場合はjisonを選択してください。Bisonに似た文法を使用しているため、既存のBison文法を移植するのにも便利です。

nearley のREADME

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