diff --git a/README.md b/README.md index 0fea2e9..68a64c0 100644 --- a/README.md +++ b/README.md @@ -5,741 +5,33 @@ [![bower](https://img.shields.io/bower/v/pegjs.svg)](https://github.com/pegjs/bower) [![license](https://img.shields.io/badge/license-mit-blue.svg)](https://opensource.org/licenses/MIT) -PEG.js is a simple parser generator for JavaScript that produces fast parsers with excellent error reporting. You can use it to -process complex data or computer languages and build transformers, interpreters, compilers and other tools easily. +PEG.js is a simple parser generator for JavaScript that produces fast parsers with excellent error reporting. You can use it to process complex data or computer languages and build transformers, interpreters, compilers and other tools easily. > PEG.js is still very much work in progress. There are no compatibility guarantees until version 1.0 -Table of Contents ------------------ - -- [Features](#features) -- [Getting Started](#getting-Started) -- [Installation](#installation) - * [Node.js](#nodejs) - * [Browser](#browser) - * [Latest](#latest) -- [Generating a Parser](#generating-a-parser) - * [Command Line](#command-line) - * [JavaScript API](#javascript-api) -- [Using the Parser](#using-the-parser) -- [Grammar Syntax and Semantics](#grammar-syntax-and-semantics) - * [Case-insensitivity](#case-insensitivity) - * [Backtracking](#backtracking) - * [Parsing Expression Types](#parsing-expression-types) - * [Action Execution Environment](#action-execution-environment) - * [Balanced Braces](#balanced-braces) -- [Error Messages](#error-messages) -- [Compatibility](#compatibility) -- [Development](#development) - * [Useful Links](#useful-links) - * [Contribution](#contribution) - -Features --------- +## features * Simple and expressive grammar syntax * Integrates both lexical and syntactical analysis * Parsers have excellent error reporting out of the box - * Based on [parsing expression - grammar](http://en.wikipedia.org/wiki/Parsing_expression_grammar) formalism - — more powerful than traditional LL(*k*) and LR(*k*) parsers - * Usable [from your browser](https://pegjs.org/online), from the command line, - or via JavaScript API - -Getting Started ---------------- - -[Online version](https://pegjs.org/online) is the easiest way to generate a -parser. Just enter your grammar, try parsing few inputs, and download generated -parser code. - -Installation ------------- - -### Node.js - -To use the `pegjs` command, install PEG.js globally: - -```console -$ npm install -g pegjs -``` - -To use the JavaScript API, install PEG.js locally: - -```console -$ npm install pegjs -``` - -If you need both the `pegjs` command and the JavaScript API, install PEG.js both -ways. - -### Browser - -[Download](https://pegjs.org/#download) the PEG.js library (regular or minified -version) or install it using Bower: - -```console -$ bower install pegjs -``` - -### Latest - -To use the latest features, fixes and changes of PEG.js, install the packaged dev release: - -```console -$ npm install pegjs@dev -``` - -Alternatively, you can directly install from the repository (larger then the packaged dev release): - -```console -$ npm install pegjs/pegjs#master -``` - -Generating a Parser -------------------- - -PEG.js generates parser from a grammar that describes expected input and can -specify what the parser returns (using semantic actions on matched parts of the -input). Generated parser itself is a JavaScript object with a simple API. - -### Command Line - -To generate a parser from your grammar, use the `pegjs` command: - -```console -$ pegjs arithmetics.pegjs -``` - -This writes parser source code into a file with the same name as the grammar -file but with “.js” extension. You can also specify the output file explicitly: - -```console -$ pegjs -o arithmetics-parser.js arithmetics.pegjs -``` - -If you omit both input and output file, standard input and output are used. - -By default, the generated parser is in the Node.js module format. You can -override this using the `--format` option. - -You can tweak the generated parser with several options: - - * `-a`, `--allowed-start-rules` — comma-separated list of rules the parser will be allowed to start parsing from (default: the first rule in the grammar) - * `--cache` — makes the parser cache results, avoiding exponential parsing time in pathological cases but making the parser slower - * `-d`, `--dependency` — makes the parser require a specified dependency (can be specified multiple times) - * `-e`, `--export-var` — name of a global variable into which the parser object is assigned to when no module loader is detected - * `--extra-options` — additional options (in JSON format) to pass to `peg.generate` - * `-c`, `--config`, `--extra-options-file` — file with additional options (in JSON or JavaScript) to pass to `peg.generate` - * `-f`, `--format` — format of the generated parser: `amd`, `bare`, `commonjs`, `es`, `globals`, `umd` (default: `commonjs`) - * `-O`, `--optimize` — selects between optimizing the generated parser for parsing speed (`speed`) or code size (`size`) (default: `speed`) - * `-p`, `--plugin` — makes PEG.js use a specified plugin (can be specified multiple times) - * `--trace` — makes the parser trace its progress - -**NOTE:** On the command line, unless it's a repeatable option, any option on the right side will take priority over either the same option mentioned -before or it's counter part: - -- `pegjs -f es -f bare` will set `options.format` to `bare` -- `pegjs --no-trace --trace` will set `options.trace` to `true` -- `pegjs -a start,Rule -a Rule,Template` will set `options.allowedStartRules` to `[ "start", "Rule", "Template" ]` - -### JavaScript API - -In Node.js, require the PEG.js parser generator module: - -```js -var peg = require("pegjs"); -``` - -In browser, include the PEG.js library in your web page or application using the -`