Chevrotain is a very fast and feature rich Parser Building Toolkit for JavaScript. It can be used to build parsers/compilers/interpreters for various use cases ranging from simple configuration files, to full fledged programing languages.
A more in depth description of Chevrotain can be found in this great article on: Parsing in JavaScript: Tools and Libraries.
It is important to note that Chevrotain is NOT a parser generator. It solves the same kind of problems as a parser generator, just without any code generation. Chevrotain Grammars are pure code which can be created/debugged/edited as any other pure code without requiring any new tools or processes.
-
Parsing DSL.
- LL(k) grammars support.
- Useable from JavaScript / TypeScript / CoffeeScript.
- Separation of grammar and semantics.
- Customizable Error Reporting with full location information.
- Strong Error Recovery/Fault-Tolerance capabilities based on Antlr3's algorithms.
- Supports gates/predicates.
- Backtracking support.
- Grammar Inheritance.
- Multiple starting rules.
- Parameterized Rules.
- Syntactic Content Assist.
- No code generation.
- The DSL is just JavaScript, not an external language.
- The grammar is directly debuggable as plain JavaScript source.
- Short feedback loops.
- Allows great flexibility for inserting custom Parser actions.
- Custom APIs.
-
Lexer Engine
- Based on Regular Expressions.
- Full position information tracking (lines/columns/offsets).
- Token skipping (whitespace/comments/...).
- Prioritise longest match (Keywords vs Identifiers).
- Multiple Lexer Modes depending on the context.
- Tokens Grouping.
- Custom Token patterns(none RegExp) support
- No code generation The Lexer does not require any code generation phase.
-
Grammar Reflection/Introspection.
- The Grammar's structure is known and exposed at runtime.
- Can be used to implement advanced features such as dynamically generated syntax diagrams or Syntactic error recovery.
-
Well tested with ~100% code coverage, Unit & Integration tests
- npm:
npm install chevrotain
- Browser:
The npm package contains Chevrotain as concatenated and minified files ready for use in a browser.
These can also be accessed directly via UNPKG in a script tag.
- Latest:
https://unpkg.com/chevrotain/lib/chevrotain.js
https://unpkg.com/chevrotain/lib/chevrotain.min.js
- Explicit version number:
https://unpkg.com/[email protected]/lib/chevrotain.js
https://unpkg.com/[email protected]/lib/chevrotain.min.js
- Latest:
-
FAQ.
There is a single dependency to regexp-to-ast library. This dependency is included in the bundled artifacts, for ease of consumption in browsers.
Chevrotain runs on any modern JavaScript ES5.1 runtime.
-
The CI build runs the tests under:
- Node.js (6 / 8 / 10).
- Latest stable: Chrome, FireFox, Safari, IE Edge and IE 11.
-
Uses UMD to work with common module loaders (browser global / amd / commonjs).
Contributions are greatly appreciated. See CONTRIBUTING.md for details.
Some interesting samples: