From 2c2ddad8b5a2b1ac250d450477c84015053b7b88 Mon Sep 17 00:00:00 2001 From: Joe Hildebrand Date: Sun, 29 May 2022 07:34:53 -0600 Subject: [PATCH] Remove docs from README.md to make it easier to keep in sync, and so that people landing on GitHub will go to peggyjs.org, which is loaded from the docs branch --- README.md | 933 +----------------------------------- docs/development/index.html | 5 - docs/index.html | 4 + 3 files changed, 9 insertions(+), 933 deletions(-) diff --git a/README.md b/README.md index 204a7d84..acaf3d2d 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ with excellent error reporting. You can use it to process complex data or computer languages and build transformers, interpreters, compilers and other tools easily. -Peggy is the successor of [PEG.js](https://github.com/pegjs/pegjs) which had been abandoned by its maintainer. +Peggy is the successor of [PEG.js](https://github.com/pegjs/pegjs). ## Migrating from PEG.js @@ -39,932 +39,9 @@ Follow these steps to upgrade: parser. Just enter your grammar, try parsing few inputs, and download generated parser code. -## Installation +## Documentation -### Node.js - -To use the `peggy` command, install Peggy globally: - -```console -$ npm install -g peggy -``` - -To use the JavaScript API, install Peggy locally: - -```console -$ npm install peggy -``` - -If you need both the `peggy` command and the JavaScript API, install Peggy both -ways. - -### Browser - -The easiest way to use Peggy from the browser is to pull the latest version from a CDN. Either of these should work: - -```html - -``` - -```html - -``` - -When your document is done loading, there will be a global `peggy` object. - -## Generating a Parser - -Peggy 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 `peggy` command: - -```console -$ peggy arithmetics.peggy -``` - -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 -$ peggy -o arithmetics-parser.js arithmetics.peggy -``` - -If you omit both input and output file, standard input and standard 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: - -- `--allowed-start-rules ` — comma-separated list of rules the parser - will be allowed to start parsing from (default: only 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 <[name:]module>` — makes the parser require a specified - dependency (can be specified multiple times). A variable name for the - import/require/etc. may be given, followed by a colon. If no name is given, - the module name will also be used for the variable name. -- `-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, as an - object) to pass to `peg.generate` -- `-c`, `--extra-options-file ` — file with additional options (in JSON - or commonjs module format, as an object) to pass to `peg.generate` -- `--format ` — format of the generated parser: `amd`, `es`, `commonjs`, - `globals`, `umd` (default: `commonjs`) -- `-o`, `--output ` - file to send output to. Defaults to input file - name with extension changed to `.js`, or stdout if no input file is given. -- `--plugin ` — makes Peggy use a specified plugin (can be specified - multiple times) -- `-t`, `--test ` — Test the parser with the given text, outputting the - result of running the parser against this input. - If the input to be tested is not parsed, the CLI will exit with code 2 -- `-T`, `--test-file ` — Test the parser with the contents of the - given file, outputting the result of running the parser against this input. - If the input to be tested is not parsed, the CLI will exit with code 2 -- `--source-map` — generate a source map file with an optionally specified name -- `--trace` — makes the parser trace its progress -- `-v`, `--version` — output the version number -- `-h`, `--help` — display help for command - -If you specify options using `-c ` or `--extra-options-file `, you -will need to ensure you are using the correct types. In particular, you may -specify "plugin" as a string, or "plugins" as an array of objects that have a -`use` method. Always use the long (two-dash) form of the option. Options -that contain dashes should be specified in camel case. You may also specify an -"input" field instead of using the command line. - -For example: - -```js -// config.js or config.cjs -module.exports = { - allowedStartRules = ["foo", "bar"], - format: "umd", - exportVar: "foo", - input: "fooGrammar.peggy", - plugins: [require("./plugin.js")], - testFile: "myTestInput.foo", - trace: true -}; -``` - -You can test generated parser immediately if you specify the `-t/--test` or `-T/--test-file` -option. This option conflicts with the option `-m/--source-map` unless `-o/--output` is -also specified. - -The CLI will exit with the code: -- `0` if all was success -- `1` if you supply incorrect or conflicting parameters -- `2` if all parameters is correct, you specify the `-t/--test` or `-T/--test-file` option - and specified input does not parsed with the specified grammar - -Examples: - -```console -# - write test results to stdout (42) -# - exit with the code 0 -echo "foo = '1' { return 42 }" | peggy --test 1 - -# - write a parser error to stdout (Expected "1" but "2" found) -# - exit with the code 2 -echo "foo = '1' { return 42 }" | peggy --test 2 - -# - write an error to stdout (Generation of the source map is useless if you don't -# store a generated parser code, perhaps you forgot to add an `-o/--output` option?) -# - exit with the code 1 -echo "foo = '1' { return 42 }" | peggy --source-map --test 1 - -# - write an error to stdout (Generation of the source map is useless if you don't -# store a generated parser code, perhaps you forgot to add an `-o/--output` option?) -# - exit with the code 1 -echo "foo = '1' { return 42 }" | peggy --source-map --test 2 - -# - write an output to `parser.js`, -# - write a source map to `parser.js.map` -# - write test results to stdout (42) -# - exit with the code 0 -echo "foo = '1' { return 42 }" | peggy --output parser.js --source-map --test 1 - -# - write an output to `parser.js`, -# - write a source map to `parser.js.map` -# - write a parser error to stdout (Expected "1" but "2" found) -# - exit with the code 2 -echo "foo = '1' { return 42 }" | peggy --output parser.js --source-map --test 2 -``` - -### JavaScript API - -In Node.js, require the Peggy parser generator module: - -```javascript -const peggy = require("peggy"); -``` - -or - -```javascript -import * as peggy from "peggy"; -``` - -For use in browsers, include the Peggy library in your web page or application -using the `