[![npm version](https://badge.fury.io/js/chevrotain.svg)](http://badge.fury.io/js/chevrotain)
[![Bower version](https://badge.fury.io/bo/chevrotain.svg)](https://badge.fury.io/bo/chevrotain)
[![Build Status](https://travis-ci.org/SAP/chevrotain.svg?branch=master)](https://travis-ci.org/SAP/chevrotain)
[![Coverage Status](https://coveralls.io/repos/SAP/chevrotain/badge.svg?branch=master)](https://coveralls.io/r/SAP/chevrotain?branch=master)
[![Dependency status](https://img.shields.io/david/SAP/chevrotain.svg)](https://david-dm.org/SAP/chevrotain)
[![devDependency Status](https://img.shields.io/david/dev/SAP/chevrotain.svg)](https://david-dm.org/SAP/chevrotain#info=devDependencies)

# Chevrotain

Chevrotain is a **Javascript parsing DSL** for building [**high performance**][benchmark] **fault-tolerant** recursive decent parsers.

Chevrotain is **NOT** a parser generator. It solves the same kind of problems as a parser generator, just without
any code generation phase.

## [---> Try it online <---](http://sap.github.io/chevrotain/playground/)
   
## Features
  1. **Lexer Engine** based on Regular Expression.
    * Full Token position information.
    * Token skipping (whitespace/comments/...).
    * Prioritise shorter matches ([Keywords vs Identifiers][keywords_vs_idents]).
    * [Multiple Lexer Modes](https://github.com/SAP/Chevrotain/blob/master/examples/lexer/multi_mode_lexer.js) depending on the context.
    * [Tokens Grouping][lexer_groups]
    * **No code generation** The Lexer does not require any code generation phase. 
   
  2. **Parsing DSL** for defining the grammar.
    * **No code generation**.
      * The DSL is just Javascript, not an external language.
      * Easily debuggable.
      * Short feedback loops.
      * Allows great flexibility for inserting custom Parser actions.
    * **Error Reporting** with full location information. 
    * Strong **Error Recovery/Fault-Tolerance** capabilities based on Antlr3's algorithms.
    * Automatic lookahead calculation for LL(1) grammars.
    * Supports [Custom lookahead logic][custom_lookahead] for LL(k) grammars.
    * Backtracking support.

  3. [**High performance - (see on JSPerf)**][benchmark].

  4. **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.
  
  5. Well tested with **~100% code coverage**, Unit & Integration tests
  
  6. Generated [**Railroad Diagrams**](https://github.com/SAP/chevrotain/tree/master/diagrams).
   
## Installation
* **npm**: ```npm install chevrotain```
* **Bower** ```bower install chevrotain```

## Getting Started

**Online tutorial**
 * Step #1 - Building a Lexer: [online version](http://sap.github.io/chevrotain/playground/?example=tutorial%20lexer) / [written version](https://github.com/SAP/chevrotain/blob/master/docs/tutorial/step1_lexing.md).
 * Step #2 - Building a Parser: [online version](http://sap.github.io/chevrotain/playground/?example=tutorial%20grammar) / [written version](https://github.com/SAP/chevrotain/blob/master/docs/tutorial/step2_parsing.md).
 * Step #3 - Adding actions to the Parser: [online version](http://sap.github.io/chevrotain/playground/?example=tutorial%20actions) / [written version](https://github.com/SAP/chevrotain/blob/master/docs/tutorial/step3_adding_actions.md).
 * Step #4 - Fault tolerance and Error recovery: [online version](http://sap.github.io/chevrotain/playground/?example=tutorial%20fault%20tolerance) / [written version](https://github.com/SAP/chevrotain/blob/master/docs/tutorial/step4_fault_tolerance.md).

**[Examples Folder](https://github.com/SAP/chevrotain/blob/master/examples)**

## Documentation
* [Latest released version's HTML docs](http://sap.github.io/chevrotain/documentation)
   * [Parsing DSL](http://sap.github.io/chevrotain/documentation/0_8_1/classes/parser.html#at_least_one)
   
* Annotated source code (dev version):
   *  [tokens_public.ts](https://github.com/SAP/chevrotain/blob/master/src/scan/tokens_public.ts)
   *  [lexer_public.ts](https://github.com/SAP/chevrotain/blob/master/src/scan/lexer_public.ts)
   *  [parser_public.ts](https://github.com/SAP/chevrotain/blob/master/src/parse/parser_public.ts)
   *  [gast_public.ts](https://github.com/SAP/chevrotain/blob/master/src/parse/grammar/gast.ts)
   
*  The aggregated Typescript definitions :
   * [chevrotain.d.ts](https://github.com/SAP/chevrotain/blob/master/lib/chevrotain.d.ts) (latest version)

## Dependencies
None.

## Compatibility
Chevrotain should run on any modern Javascript ES5.1 runtime. 
* The CI build runs the tests under: 
  * Node.js (0.12 / 4 / 5).
  * latest stable Chrome.
  * latest stable Firefox.
* Additionally local testing is done on latest versions of Chrome/Firefox/IE.
* Uses [UMD](https://github.com/umdjs/umd) to work with common module loaders (browser global / amd / commonjs).
  
[benchmark]: http://jsperf.com/json-parsers-comparison/22
[lexer_groups]: https://github.com/SAP/chevrotain/blob/master/examples/lexer/token_groups.js
[keywords_vs_idents]: https://github.com/SAP/chevrotain/blob/master/examples/lexer/keywords_vs_identifiers.js
[custom_lookahead]: https://github.com/SAP/chevrotain/blob/master/examples/custom_lookahead/large_lookahead.js
