Compare commits

..

10 Commits

@ -1,13 +0,0 @@
codecov:
ci:
- github.com
ignore:
- "**/*/dist/*.js"
- "**/*.{spec,test}.js"
- "**/*.eslintrc.js"
- "{public,website}/**/*.js"
parsers:
javascript:
enable_partials: yes

@ -1,8 +1,3 @@
!.eslintrc.js
/.idea
/.nyc_output
/public
/packages/pegjs/dist
/coverage
node_modules
/website/assets
lib/parser.js
test/vendor/**/*
benchmark/vendor/**/*

@ -1,37 +0,0 @@
"use strict";
module.exports = {
"extends": [
"@futagoza/node/8",
],
"rules": {
"no-duplicate-imports": [ "error", { "includeExports": false } ],
"no-eval": 0,
},
"overrides": [ {
"files": [
"test/unit/compiler/passes/helpers.js",
"*.spec.js",
"*.test.js",
],
"extends": "@futagoza/dev/test",
"rules": {
"func-names": 0,
"no-mixed-operators": 0,
},
} ],
"root": true,
};

@ -0,0 +1,3 @@
{
"extends": "@joepie91/eslint-config"
}

@ -1,46 +0,0 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at futagoza.ryuu+pegjs@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/

@ -1,54 +0,0 @@
### Issue type
<!-- What type of issue is this (choose _yes_ or _no_): -->
- **Bug Report:**
- **Feature Request:**
- **Question:**
- **Not an issue:**
### Prerequisites
<!-- Have you done the following (choose _yes_ or _no_): -->
- **Can you reproduce the issue?:**
- **Did you search the repository issues?:**
- **Did you check the forums?:**
- **Did you perform a web search (google, yahoo, etc)?:**
<!-- For more information, see the CONTRIBUTING document. -->
### Description
<!-- A description of the bug, feature or question -->
### Steps to Reproduce
1. <!-- First Step -->
2. <!-- Second Step -->
3. <!-- and so on... -->
**Example code:**
```js
// An example of code related to this issue
```
**Expected behavior:**
<!-- What you expected to happen -->
**Actual behavior:**
<!-- What actually happened -->
### Software
<!-- Having more details about your software might help pinpoint the source of a bug: -->
- **PEG.js:**
- **Node.js:**
- **NPM or Yarn:**
- **Browser:**
- **OS:**
- **Editor:**

@ -1,20 +0,0 @@
### PR type
<!--- What types of changes does your code introduce? (choose _yes_ or _no_): -->
- **Bug fix (non-breaking change which fixes an issue):**
- **New feature (non-breaking change which adds functionality):**
- **Breaking change (fix or feature that would cause existing functionality to change):**
- **Documentation change:**
### Prerequisites
<!-- Have you done the following (choose _yes_ or _no_): -->
- **I have read the [CONTRIBUTING.md](CONTRIBUTING.md) document:**
- **I have updated the documentation accordingly:**
- **I have added tests to cover my changes:**
### Description
<!-- A description of the PR and commits included -->

@ -1,87 +0,0 @@
name: Github Actions
on: [ push, pull_request ]
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Install Node.js
uses: actions/setup-node@master
with:
node-version: 10.x
- name: Install Yarn
run: npm install --global yarn
- name: Install dependencies
run: yarn --ignore-engines
- name: Lint JavaScript files using ESLint
run: yarn lint
ci:
name: Test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: [ 8.x, 10.x, 12.x ]
steps:
- uses: actions/checkout@master
- name: Install Node.js
uses: actions/setup-node@master
with:
node-version: ${{ matrix.node-version }}
- name: Install Yarn
run: npm install --global yarn
- name: Install dependencies
run: yarn --ignore-engines
- name: Run tests
run: yarn test
- name: Publish code coverage results
run: yarn coverage
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
cd:
name: Publish
needs: [ lint, ci ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Install Node.js
uses: actions/setup-node@master
with:
node-version: 10.x
- name: Install Yarn
run: npm install --global yarn
- name: Install dependencies
run: yarn --ignore-engines
- name: 'Build "pegjs/dist/*.js" files'
run: yarn build-dist
- name: Publish pegjs@dev to NPM
run: node tools/publish-dev
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

12
.gitignore vendored

@ -1,11 +1,3 @@
/.idea
/packages/pegjs/dist
/packages/pegjs/.npmrc
/public
/examples/*.js
browser
examples/*.js
node_modules
/coverage
/.nyc_output
/*.log
/sh.exe.stackdump
/test/junit-results.xml

@ -1,12 +0,0 @@
/.github
/.idea
/.nyc_output
/coverage
node_modules
/public
/.codecov.yml
/.eslint*
/.nycrc
/CHANGELOG.md
/tsconfig.json
/README.md

@ -1,7 +0,0 @@
{
"include": [ "packages/**" ],
"reporter": [
"lcov",
"text-summary"
]
}

@ -0,0 +1,16 @@
sudo: false
language: node_js
node_js:
- "4.0"
- "5.0"
- "6.0"
- "7.0"
before_script:
- npm install -g gulp
cache:
directories:
- node_modules

@ -1,95 +1,618 @@
* Commit history: https://github.com/pegjs/pegjs/commits/master
* Previous changelogs: https://github.com/pegjs/pegjs/tree/master/docs/changelogs
* Contributors this release: https://github.com/pegjs/pegjs/graphs/contributors?from=2016-08-20
Change Log
==========
> This is a work in progress changelog for the next release _(currently v0.11)_.
This file documents all notable changes to PEG.js. The releases follow [semantic
versioning](http://semver.org/).
0.10.0
------
Released: August 19, 2016
### Major Changes
* **Parsers can be generated in multiple module formats.** The available
formats are: CommonJS (the default), AMD, UMD, globals, and bare (not
available from the command-line).
The format can be specified using the `format` option of the `peg.generate`
function or the `--format` option on the command-line.
It is also possible to specify parser dependencies using the `dependencies`
option of the `peg.generate` function or the `--dependency`/`-d` option on
the command-line. This is mainly useful for the UMD format, where the
dependencies are translated into both AMD dependencies and CommonJS
`require` calls.
* **Browser version of PEG.js is now in the UMD format.** This means it will try
to detect AMD or Node.js/CommonJS module loader and define itself as a
module. If no loader is found, it will export itself using a global
variable.
* **API polishing.** The `peg.buildParser` function was renamed to
`peg.generate`. The global variable the browser version of PEG.js is
available in when no loader is detected was renamed from `PEG` to `peg`.
* **CLI improvements.** There is new `--output`/`-o` command-line option which
allows to specify the output file. The old way of specifying the output file
using a second argument was removed. To make room for the new `-o` option
the old one (a shortcut for `--optimize`) was renamed to `-O`. All these
changes make PEG.js conform to traditional compiler command-line interface.
It is now also possible to use `-` as a file name on the command-line (with
the usual meaning of standard input/output).
* **Improved error messages.** Both messages produced by PEG.js and generated
parsers were improved.
* **Duplicate rule definitions are reported as errors.**
* **Duplicate labels are reported as errors.**
### Minor Changes
* Exposed the AST node visitor builder as `peg.compiler.visitor`. This is
useful mainly for plugins which manipulate the AST.
* Exposed the function which builds messages of exceptions produced by
generated parsers as `SyntaxError.buildMessage`. This is useful mainly for
customizing these error messages.
* The `error` and `expected` functions now accept an optional `location`
parameter. This allows to customize the location in which the resulting
syntax error is reported.
* Refactored expectations reported in the `expected` property of exceptions
produced by generated parsers. They are no longer de-duplicated and sorted,
their format changed to be more machine-readable, and they no longer contain
human-readable descriptions.
* The `found` property of exceptions produced by the `error` function is now
set to `null`.
* Removed access to the parser object in parser code via the `parser`
variable.
* Made handling of optional parameters consistent with ES 2015. Specifically,
passing `undefined` as a parameter value is now equivalent to not passing
the parameter at all.
* Renamed several compiler passes.
* Generated parsers no longer consider `\r`, `\u2028`, and `\u2029` as
newlines (only `\n` and `\r\n`).
* Simplified the arithmetics example grammar.
* Switched from `first`/`rest` to `head`/`tail` in PEG.js grammar and example
grammars.
* Started using ESLint instead of JSHint and fixed various problems it found.
* Added [contribution
guidelines](https://github.com/pegjs/pegjs/blob/master/CONTRIBUTING.md).
* Removed support for io.js.
### Bug Fixes
* Fixed `bin/pegjs` so that invoking it with one non-option argument which is
an extension-less file doesnt cause that file to be overwritten.
* Fixed label scoping so that labels in expressions like `(a:"a")` or `(a:"a"
b:"b" c:"c")` arent visible from the outside.
* Fixed escaping of generated JavaScript strings & regexps to also escape DEL
(U+007F).
* Fixed the JSON example grammar to correctly handle characters with code
points above U+10FF in strings.
* Fixed multiple compatibility issues of `tools/impact` on OS X.
* Fixed slow deduplication of expectation descriptions.
[Complete set of changes](https://github.com/pegjs/pegjs/compare/v0.9.0...v0.10.0)
0.9.0
-----
Released: August 30, 2015
### Major Changes
* [Implemented value plucking](https://github.com/pegjs/pegjs/commit/460f0cc5bc9e7b12e7830a13a9afa5026a5f20f4): e.g. When `grammar = "-" @$[a-z]i* "-"` is given `-PEGjs-`, it returns `PEGjs`
* Upgraded JavaScript support:
- Parser's are generated in ES5
- Source code for PEG.js and scripts in the repository are written in ES2015, for Node 8+
- The browser release is in ES5, generated using [Rollup](https://rollupjs.org/) and [Babel](https://babeljs.io/)
- Dropped support for Node versions _0.x_, _4_, _6_ and _non-LTS_ versions (e.g. `7`, `9`, etc)
- Dropped support for IE versions _8_, _9_ and _10_
* Updated documentation:
- extracted to separate markdown files in the [docs folder](https://github.com/pegjs/pegjs/tree/master/docs)
- better explanation about error messages
- added documentation for case-insensitivity in grammar
- added documentation for backtracking in grammar
- clarify details for the execution environment for actions ([#531](https://github.com/pegjs/pegjs/pull/531))
- added a clear explanation of balanced braces ([#533](https://github.com/pegjs/pegjs/pull/533))
- updated documentation for the JavaScript API
- added a guide for plugins
- added documentation for tracer usage
- added a guide for the CLI
* Rewrote command line tool:
- added 2 aliases for `--extra-options-file`: `-c` and `--config`
- options can accept their values via the assignment operator (e.g. `pegjs -c=config.js`)
- all arguments after `--` are passed to `options["--"]`
- added aliases for some CLI options; Check them out using `pegjs -h`
- added "bare" to accepted module formats
* Updated the helpers providable to the generated parsers:
- reintroduced `offset()` which was removed in a previous release ([#528](https://github.com/pegjs/pegjs/pull/528))
- added `range()`; returns `[starting offset, current offset]`
- `location()` also returns a `filename` property if one was passed to the generated parser as an option ([#421](https://github.com/pegjs/pegjs/issues/421))
- helpers can be disabled via the new `features` option (e.g. `{ text: false }` will remove the `text()` helper)
* Parser returns an instance of the new Grammar class instead of a plain JavaScript object
* Added the ASTVisitor class ([#451](https://github.com/pegjs/pegjs/issues/451))
* Moved all code generation from the `generateBytecode` pass to the `generateJs` pass ([#459](https://github.com/pegjs/pegjs/pull/459))
* Use `.js` files with the `--extra-options-file` (aliased by `-c` and `--config`) option on CLI
* Added the Session API (`peg.compiler.Session`); this should simplify extending PEG.js using plugins
* Implemented warning and error emitters: `session.warn`, `session.error` and `session.fatal` ([#327](https://github.com/pegjs/pegjs/issues/327), [#430](https://github.com/pegjs/pegjs/issues/430), [#431](https://github.com/pegjs/pegjs/issues/431))
* **Tracing support.** Parsers can be compiled with support for tracing their
progress, which can help debugging complex grammars. This feature is
experimental and is expected to evolve over time as experience is gained.
[More details](https://github.com/pegjs/pegjs/commit/da57118a43a904f753d44d407994cf0b36358adc)
* **Infinite loop detection.** Grammar constructs that could cause infinite
loops in generated parsers are detected during compilation and cause errors.
* **Improved location information API.** The `line`, `column`, and `offset`
functions available in parser code were replaced by a single `location`
function which returns an object describing the current location. Similarly,
the `line`, `column`, and `offset` properties of exceptions were replaced by
a single `location` property. The location is no longer a single point but a
character range, which is meaningful mainly in actions where the range
covers actions expression.
[More details](https://github.com/pegjs/pegjs/compare/e75f21dc8f0e66b3d87c4c19b3fcb8f89d9c3acd...eaca5f0acf97b66ef141fed84aa95d4e72e33757)
* **Improved error reporting.** All exceptions thrown when generating a parser
have associated location information. And all exceptions thrown by generated
parser and PEG.js itself have a stack trace (the `stack` property) in
environments that support `Error.captureStackTrace`.
* **Strict mode code**. All PEG.js and generated parser code is written using
[JavaScript strict mode](https://developer.mozilla.org/cs/docs/Web/JavaScript/Reference/Strict_mode).
### Minor Changes
* Omit PEG.js version from the browser release's filename
* Added support for generating the parser as a ES module using `"format": "es"`
* Added [bundled](https://www.npmjs.com/package/pegjs) TypeScript declaration files for
- the PEG.js API: `pegjs/typings/api.d.ts`
- the PEG.js modules: `pegjs/typings/modules.d.ts`
- generated parsers: `pegjs/typings/generated-parser.d.ts`
* Updated bytecode generator; Generated parsers look slightly better
- optimize silent fails ([#399](https://github.com/pegjs/pegjs/issues/399))
- optimize redundant fail checks ([#400](https://github.com/pegjs/pegjs/issues/400))
- remove unnecessary opcode ([#509](https://github.com/pegjs/pegjs/pull/509))
* Added `ASTVisitor.on.{property,children}`; these are helper's to create visitor's for use with the new ASTVisitor class
* Merged ast utility functions into the new Grammar class; faster and simpler to use now.
* Pass `options.parser` from `peg.generate` to the PEG.js parser (`peg.parser`, or a custom parser)
* Added a pass for the compiler to warn when unused rules are found ([#200](https://github.com/pegjs/pegjs/issues/200))
* Added a `header` option to the compiler; Adds custom comments to the header of the generated parser
* CLI restores original output file (if it already exists) when parser generation fails
* Added the option `extractComments` to the PEG.js parser which if _true_ will extract comments from the grammar ([#511](https://github.com/pegjs/pegjs/pull/511))
* Made the default tracer optional (disabled like so `peg.generate(grammar, { features: { DefaultTracer: false } })`)
* Pass variables to generated parsers through the `context` option when `output: "parser"` ([#517](https://github.com/pegjs/pegjs/issues/517))
* On the CLI added the use of `input` and `output` from the _config file_ instead of passing them as arguments
* Updated examples
* Upgraded support for Unicode (from _v8_ to _v11_)
* Forward location to `SyntaxError.buildMessage` ([#608](https://github.com/pegjs/pegjs/pull/608))
### Bugfixes
* Report consistent errors on look ahead + cached results (fix's [#452](https://github.com/pegjs/pegjs/issues/452) via [#555](https://github.com/pegjs/pegjs/issues/555))
* Improve error messages ([#194](https://github.com/pegjs/pegjs/issues/194), [#475](https://github.com/pegjs/pegjs/pull/475), [#534](https://github.com/pegjs/pegjs/pull/534), [#547](https://github.com/pegjs/pegjs/pull/547), [#552](https://github.com/pegjs/pegjs/pull/552))
* Do not indent backtick quoted strings in code blocks ([#492](https://github.com/pegjs/pegjs/pull/492))
* Fix shadowing issue for UMD generated parsers ([#499](https://github.com/pegjs/pegjs/issues/499))
* Check rules from `options.allowedStartRules` exist within the grammar ([#524](https://github.com/pegjs/pegjs/issues/524))
### Internal
* Use ESLint to enforce code style
* Switch from Jasmine to Mocha & Chai ([#409](https://github.com/pegjs/pegjs/issues/409))
* Removed Makefile (Had switched to Gulp, but removed that as well); Using the _scripts_ field of `package.json` instead
* Rewrote `tools/impact`; previously a bash script that required external programs, it's now a cross-platform Node script
* Added coverage via [Istanbul](https://www.npmjs.com/package/nyc) ([#546](https://github.com/pegjs/pegjs/pull/546))
* Test coverage reports are now submitted to [https://codecov.io/gh/pegjs/pegjs](https://codecov.io/gh/pegjs/pegjs)
* Updated existing spec tests
* Switched to Yarn for workspace based development (_NOTE:_ Yarn is not be required for production use)
* Updated keywords for the [NPM package](https://www.npmjs.com/package/pegjs)
* Archived the website's repository; it is now built from the docs and deployed every time the main repository is updated
* Added the [spec](https://pegjs.org/development/test) and [benchmark](https://pegjs.org/development/benchmark) tests to the website
* Switch from [Browserify](https://github.com/browserify/browserify) to [Webpack](https://webpack.js.org/)
* Export's PEG.js version from `require("pegjs/package.json").version`
* Added https://pegjs.org/development/try; an editor that uses the latest source files for PEG.js
* Replaced [Travis CI support](https://travis-ci.org/pegjs/pegjs/builds) with GitHub Actions
* Labels behave like block-scoped variables. This means parser code can see
labels defined outside expressions containing code.
* Empty sequences are no longer allowed.
* Label names cant be JavaScript reserved words.
* Rule and label names can contain Unicode characters like in JavaScript.
* Rules have to be separated either by `;` or a newline (until now, any
whitespace was enough).
* The PEG.js grammar and all the example grammars were completely rewritten.
This rewrite included a number of cleanups, formatting changes, naming
changes, and bug fixes.
* The parser object can now be accessed as `parser` in parser code.
* Location information computation is faster.
* Added support for Node.js >= 0.10.x, io.js, and Edge. Removed support for
Node.js < 0.10.x.
### Bug Fixes
* Fixed left recursion detector which missed many cases.
* Fixed escaping of U+0100—U+107F and U+1000—U+107F in generated code and
error messages.
* Renamed `parse` and `SyntaxError` to `peg$parse` and `peg$SyntaxError` to
mark them as internal identifiers.
[Complete set of changes](https://github.com/pegjs/pegjs/compare/v0.8.0...v0.9.0)
0.8.0
-----
Released: December 24, 2013
### Big Changes
* Completely rewrote the code generator. Among other things, it allows
optimizing generated parsers for parsing speed or code size using the
`optimize` option of the `PEG.buildParser` method or the `--optimize`/`-o`
option on the command-line. All internal identifiers in generated code now
also have a `peg$` prefix to discourage their use and avoid conflicts.
[[#35](https://github.com/dmajda/pegjs/issues/35),
[#92](https://github.com/dmajda/pegjs/issues/92)]
* Completely redesigned error handling. Instead of returning `null` inside
actions to indicate match failure, new `expected` and `error` functions can
be called to trigger an error. Also, expectation inside the `SyntaxError`
exceptions are now structured to allow easier machine processing.
[[#198](https://github.com/dmajda/pegjs/issues/198)]
* Implemented a plugin API. The list of plugins to use can be specified using
the `plugins` option of the `PEG.buildParser` method or the `--plugin`
option on the command-line. Also implemented the `--extra-options` and
`--extra-options-file` command-line options, which are mainly useful to pass
additional options to plugins.
[[#106](https://github.com/dmajda/pegjs/issues/106)]
* Made `offset`, `line` and `column` functions, not variables. They are now
available in all parsers and return lazily-computed position data. Removed
now useless `trackLineAndColumn` option of the `PEG.buildParser` method and
the `--track-line-and-column` option on the command-line.
* Added a new `text` function. When called inside an action, it returns the
text matched by action's expression.
[[#131](https://github.com/dmajda/pegjs/issues/131)]
* Added a new `$` operator. It extracts matched strings from expressions.
* The `?` operator now returns `null` on unsuccessful match.
* Predicates now always return `undefined`.
* Replaced the `startRule` parameter of the `parse` method in generated
parsers with more generic `options` parameter. The start rule can now be
specified as the `startRule` option. The `options` parameter can be also
used to pass custom options to the parser because it is visible as the
`options` variable inside parser code.
[[#37](https://github.com/dmajda/pegjs/issues/37)]
* The list of allowed start rules of a generated parser now has to be
specified explicitly using the `allowedStartRules` option of the
`PEG.buildParser` method or the `--allowed-start-rule` option on the
command-line. This will make certain optimizations like rule inlining easier
in the future.
* Removed the `toSource` method of generated parsers and introduced a new
`output` option of the `PEG.buildParser` method. It allows callers to
specify whether they want to get back the parser object or its source code.
* The source code is now a valid npm package. This makes using development
versions easier.
[[#32](https://github.com/dmajda/pegjs/issues/32)]
* Generated parsers are now ~25% faster and ~62%/~3% smaller (when optimized
for size/speed) than those generated by 0.7.0.
* Requires Node.js 0.8.0+.
### Small Changes
* `bin/pegjs` now outputs just the parser source if the value of the
`--export-var` option is empty. This makes embedding generated parsers into
other files easier.
[[#143](https://github.com/dmajda/pegjs/issues/143)]
* Changed the value of the `name` property of `PEG.GrammarError` instances
from “PEG.GrammarError” to just “GrammarError”. This better reflects the
fact that PEG.js can get required with different variable name than `PEG`.
* Setup prototype chain for `PEG.GrammarError` correctly.
* Setup prototype chain for `SyntaxError` in generated parsers correctly.
* Fixed error messages in certain cases with trailing input
[[#119](https://github.com/dmajda/pegjs/issues/119)]
* Fixed code generated for classes starting with `\^`.
[[#125](https://github.com/dmajda/pegjs/issues/125)]
* Fixed too eager proxy rules removal.
[[#137](https://github.com/dmajda/pegjs/issues/137)]
* Added a license to all vendored libraries.
[[#207](https://github.com/dmajda/pegjs/issues/207)]
* Converted the test suite from QUnit to Jasmine, cleaning it up on the way.
* Travis CI integration.
* Various internal code improvements and fixes.
* Various generated code improvements and fixes.
* Various example grammar improvements and fixes.
* Improved `README.md`.
* Converted `CHANGELOG` to Markdown.
0.7.0
-----
Released: April 18, 2012
### Big Changes
* Added ability to pass options to `PEG.buildParser`.
* Implemented the `trackLineAndColumn` option for `PEG.buildParser` (together
with the `--track-line-and-column` command-line option). It makes the
generated parser track line and column during parsing. These are made
available inside actions and predicates as `line` and `column` variables.
* Implemented the `cache` option for `PEG.buildParser` (together with the
`--cache` command-line option). This option enables/disables the results
cache in generated parsers, resulting in dramatic speedup when the cache is
disabled (the default now). The cost is breaking the linear parsing time
guarantee.
* The current parse position is visible inside actions and predicates as the
`offset` variable.
* Exceptions thrown by the parser have `offset`, `expected` and `found`
properties containing machine-readable information about the parse failure
(based on a patch by Marcin Stefaniuk).
* Semantic predicates have access to preceding labels.
[[GH-69](https://github.com/dmajda/pegjs/issues/69)]
* Implemented case-insensitive literal and class matching.
[[GH-34](https://github.com/dmajda/pegjs/issues/34)]
* Rewrote the code generator — split some computations into separate passes
and based it on a proper templating system (Codie).
* Rewrote variable handling in generated parsers in a stack-like fashion,
simplifying the code and making the parsers smaller and faster.
* Adapted to Node.js 0.6.6+ (no longer supported in older versions).
* Dropped support for IE < 8.
* As a result of several optimizations, parsers generated by 0.7.0 are ~6.4
times faster and ~19% smaller than those generated by 0.6.2 (as reported by
`/tools/impact`).
### Small Changes
* Fixed reported error position when part of the input is not consumed.
[[GH-48](https://github.com/dmajda/pegjs/issues/48)]
* Fixed incorrect disjunction operator in `computeErrorPosition` (original
patch by Wolfgang Kluge).
* Fixed regexp for detecting command-line options in `/bin/pegjs`.
[[GH-51](https://github.com/dmajda/pegjs/issues/51)]
* Generate more efficient code for empty literals (original patch by Wolfgang
Kluge).
* Fixed comment typos (patches by Wolfgang Kluge and Jason Davies).
[[GH-59](https://github.com/dmajda/pegjs/issues/59)]
* Fixed a typo in JavaScript example grammar.
[[GH-62](https://github.com/dmajda/pegjs/issues/62)]
* Made copy & paste inclusion of the PEG.js library into another code easier
by changing how the library is exported.
* Improved the copyright comment and the “Generated by...” header.
* Replaced `Jakefile` with `Makefile`.
* Added `make hint` task that checks all JavaScript files using JSHint and
resolved all issues it reported. All JavaScript files and also generated
parsers are JSHint-clean now.
* Fixed output printed during test failures (expected value was being printed
instead of the actual one). Original patch by Wolfgang Kluge.
* Added a `/tools/impact` script to measure speed and size impact of commits.
* Various generated code improvements and fixes.
* Various internal code improvements and fixes.
* Improved `README.md`.
0.6.2
-----
Released: August 20, 2011
### Small Changes
* Reset parser position when action returns `null`.
* Fixed typo in JavaScript example grammar.
0.6.1
-----
Released: April 14, 2011
### Small Changes
* Use `--ascii` option when generating a minified version.
0.6.0
-----
Released: April 14, 2011
### Big Changes
* Rewrote the command-line mode to be based on Node.js instead of Rhino — no
more Java dependency. This also means that PEG.js is available as a Node.js
package and can be required as a module.
* Version for the browser is built separately from the command-line one in two
flavors (normal and minified).
* Parser variable name is no longer required argument of `bin/pegjs` — it is
`module.exports` by default and can be set using the `-e`/`--export-var`
option. This makes parsers generated by `/bin/pegjs` Node.js modules by
default.
* Added ability to start parsing from any grammar rule.
* Added several compiler optimizations — 0.6 is ~12% faster than 0.5.1 in the
benchmark on V8.
### Small Changes
* Split the source code into multiple files combined together using a build
system.
* Jake is now used instead of Rake for build scripts — no more Ruby
dependency.
* Test suite can be run from the command-line.
* Benchmark suite can be run from the command-line.
* Benchmark browser runner improvements (users can specify number of runs,
benchmarks are run using `setTimeout`, table is centered and fixed-width).
* Added PEG.js version to “Generated by...” line in generated parsers.
* Added PEG.js version information and homepage header to `peg.js`.
* Generated code improvements and fixes.
* Internal code improvements and fixes.
* Rewrote `README.md`.
0.5.1
-----
Released: November 28, 2010
### Small Changes
* Fixed a problem where “SyntaxError: Invalid range in character class.” error
appeared when using command-line version on Widnows
([GH-13](https://github.com/dmajda/pegjs/issues/13)).
* Fixed wrong version reported by `bin/pegjs --version`.
* Removed two unused variables in the code.
* Fixed incorrect variable name on two places.
0.5
---
Released: June 10, 2010
### Big Changes
* Syntax change: Use labeled expressions and variables instead of `$1`, `$2`,
etc.
* Syntax change: Replaced `:` after a rule name with `=`.
* Syntax change: Allow trailing semicolon (`;`) for rules
* Semantic change: Start rule of the grammar is now implicitly its first rule.
* Implemented semantic predicates.
* Implemented initializers.
* Removed ability to change the start rule when generating the parser.
* Added several compiler optimizations — 0.5 is ~11% faster than 0.4 in the
benchmark on V8.
### Small Changes
* `PEG.buildParser` now accepts grammars only in string format.
* Added “Generated by ...” message to the generated parsers.
* Formatted all grammars more consistently and transparently.
* Added notes about ECMA-262, 5th ed. compatibility to the JSON example
grammar.
* Guarded against redefinition of `undefined`.
* Made `bin/pegjs` work when called via a symlink
([issue #1](https://github.com/dmajda/pegjs/issues/1)).
* Fixed bug causing incorrect error messages
([issue #2](https://github.com/dmajda/pegjs/issues/2)).
* Fixed error message for invalid character range.
* Fixed string literal parsing in the JavaScript grammar.
* Generated code improvements and fixes.
* Internal code improvements and fixes.
* Improved `README.md`.
0.4
---
Released: April 17, 2010
### Big Changes
* Improved IE compatibility — IE6+ is now fully supported.
* Generated parsers are now standalone (no runtime is required).
* Added example grammars for JavaScript, CSS and JSON.
* Added a benchmark suite.
* Implemented negative character classes (e.g. `[^a-z]`).
* Project moved from BitBucket to GitHub.
### Small Changes
* Code generated for the character classes is now regexp-based (= simpler and
more scalable).
* Added `\uFEFF` (BOM) to the definition of whitespace in the metagrammar.
* When building a parser, left-recursive rules (both direct and indirect) are
reported as errors.
* When building a parser, missing rules are reported as errors.
* Expected items in the error messages do not contain duplicates and they are
sorted.
* Fixed several bugs in the example arithmetics grammar.
* Converted `README` to GitHub Flavored Markdown and improved it.
* Added `CHANGELOG`.
* Internal code improvements.
0.3
---
Released: March 14, 2010
* Wrote `README`.
* Bootstrapped the grammar parser.
* Metagrammar recognizes JavaScript-like comments.
* Changed standard grammar extension from `.peg` to `.pegjs` (it is more
specific).
* Simplified the example arithmetics grammar + added comment.
* Fixed a bug with reporting of invalid ranges such as `[b-a]` in the
metagrammar.
* Fixed `--start` vs. `--start-rule` inconsistency between help and actual
option processing code.
* Avoided ugliness in QUnit output.
* Fixed typo in help: `parserVar``parser_var`.
* Internal code improvements.
0.2.1
-----
Released: March 8, 2010
* Added `pegjs-` prefix to the name of the minified runtime file.
0.2
---
Released: March 8, 2010
* Added `Rakefile` that builds minified runtime using Google Closure Compiler
API.
* Removed trailing commas in object initializers (Google Closure does not like
them).
0.1
---
Released: March 8, 2010
* Initial release.

@ -1,7 +1,7 @@
# Contribution Guidelines
The best way to contribute to PEG.js is by using it and giving back useful
feedback, reporting discovered bugs or requesting missing features.
feedback reporting discovered bugs or requesting missing features.
You can also contribute code, but be advised that many patches end up being
rejected, usually because the change doesnt fit the project or because of
@ -26,8 +26,8 @@ input) reproducing the problem.
## Requesting Features
Request features using [GitHub issues][issues]. Before submitting a feature
request, please [search existing requests][issues-search-enhancements] to see
if the feature wasnt requested already.
request, please [search existing requests][issues-search-enhancements] to see if
the feature wasnt requested already.
In the request, please describe:
@ -46,8 +46,8 @@ see good examples.
When appropriate, add documentation and tests.
Before submitting, make sure your change passes the tests (`yarn test`) and
ESLint checks (`yarn lint`).
Before submitting, make sure your change passes the tests (`gulp test`) and
ESLint checks (`gulp lint`).
[issues]: https://github.com/pegjs/pegjs/issues
[issues-search-bugs]: https://github.com/pegjs/pegjs/issues?q=is%3Aopen+is%3Aissue+label%3ABug

@ -1,7 +1,6 @@
MIT License
Copyright (c) 2010-2016 David Majda
Copyright (c) 2017+ Futago-za Ryuu
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

@ -1,64 +1,503 @@
![GitHub Actions](https://github.com/pegjs/pegjs/workflows/Github%20Actions/badge.svg)
[![Codecov](https://codecov.io/gh/pegjs/pegjs/branch/master/graph/badge.svg)](https://codecov.io/gh/pegjs/pegjs)
[![CodeFactor](https://www.codefactor.io/repository/github/pegjs/pegjs/badge)](https://www.codefactor.io/repository/github/pegjs/pegjs)
[![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 still very much work in progress. There are no compatibility guarantees until version 1.0
### public packages
| package | version | dependency status |
| ------- | ------- | ----------------- |
| [pegjs][P001] | [![release][P002]][P003] [![dev][P004]][P005] | [![dependencies][P006]][P007] |
### local packages
| package | dependency status |
| ------- | ----------------- |
| [~/][L013] | [![dependencies][L014]][L015] |
| [~/test][L001] | [![dependencies][L002]][L003] |
| [~/tools/benchmark][L004] | [![dependencies][L005]][L006] |
| [~/tools/bundler][L007] | [![dependencies][L008]][L009] |
| [~/tools/impact][L010] | [![dependencies][L011]][L012] |
| [~/tools/publish-dev][L016] | [![dependencies][L017]][L018] |
<!-- packages/pegjs -->
[P001]: https://github.com/pegjs/pegjs/tree/master/packages/pegjs
[P002]: https://img.shields.io/npm/v/pegjs.svg
[P003]: https://www.npmjs.com/package/pegjs
[P004]: https://img.shields.io/npm/v/pegjs/dev.svg
[P005]: https://github.com/pegjs/pegjs
[P006]: https://img.shields.io/david/pegjs/pegjs.svg?path=packages/pegjs
[P007]: https://david-dm.org/pegjs/pegjs?path=packages/pegjs
<!-- https://github.com/pegjs/pegjs/ -->
[L013]: https://github.com/pegjs/pegjs/tree/master/
[L014]: https://img.shields.io/david/pegjs/pegjs.svg
[L015]: https://david-dm.org/pegjs/pegjs
<!-- test -->
[L001]: https://github.com/pegjs/pegjs/tree/master/test
[L002]: https://img.shields.io/david/pegjs/pegjs.svg?path=test
[L003]: https://david-dm.org/pegjs/pegjs?path=test
<!-- tools/benchmark -->
[L004]: https://github.com/pegjs/pegjs/tree/master/tools/benchmark
[L005]: https://img.shields.io/david/pegjs/pegjs.svg?path=tools/benchmark
[L006]: https://david-dm.org/pegjs/pegjs?path=tools/benchmark
<!-- tools/bundler -->
[L007]: https://github.com/pegjs/pegjs/tree/master/tools/bundler
[L008]: https://img.shields.io/david/pegjs/pegjs.svg?path=tools/bundler
[L009]: https://david-dm.org/pegjs/pegjs?path=tools/bundler
<!-- tools/impact -->
[L010]: https://github.com/pegjs/pegjs/tree/master/tools/impact
[L011]: https://img.shields.io/david/pegjs/pegjs.svg?path=tools/impact
[L012]: https://david-dm.org/pegjs/pegjs?path=tools/impact
<!-- tools/publish-dev -->
[L016]: https://github.com/pegjs/pegjs/tree/master/tools/publish-dev
[L017]: https://img.shields.io/david/pegjs/pegjs.svg?path=tools/publish-dev
[L018]: https://david-dm.org/pegjs/pegjs?path=tools/publish-dev
[![License](https://img.shields.io/badge/license-mit-blue.svg)](https://opensource.org/licenses/MIT)
PEG-Redux
======
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-Redux is a __work-in-progress__ fork of PEG.js, with the aim of continuing
maintenance on the PEG.js project, while adding support for modern features
such as modules.
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, from the command line, or via JavaScript API
Differences from the original PEG.js
--------
* The plugin API has been dropped for now, as it was underspecified and not very commonly used. A new, more robust and extensive plugin API may come to exist in the future, if it turns out that there is a high demand for customizations that wouldn't fit into the PEG-Redux project itself.
* Bower and stand-alone browser builds have been discontinued. Please use a bundler (see below) instead.
* AMD, UMD and globals support have been discontinued. The generated parsers now only support CommonJS.
* Module support. Both for importing other PEGRedux files, and for `require()`ing JS modules.
Installation
------------
### Node.js
To use the `pegjs` command, install PEG-Redux globally:
```console
$ npm install -g peg-redux
```
To use the JavaScript API, install PEG-Redux locally:
```console
$ npm install peg-redux
```
If you need both the `pegjs` command and the JavaScript API, install PEG-Redux
both ways.
### Browser
PEG-Redux works with bundlers such as [Browserify](http://browserify.org/), [Parcel](https://parceljs.org/) and [Webpack](https://webpack.js.org/).
Simply `require()` and use the module like you would in Node.js. The one exception is that modules (either PEG-Redux or Javascript modules) are not currently supported in browser environments.
Bower and standalone builds have been discontinued in this fork. Getting started with Browserify will only take a few minutes, and give you a better developer experience.
Generating a Parser
-------------------
PEG-Redux 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:
* `--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
* `--dependency` — makes the parser require a specified dependency (can be
specified multiple times)
* `--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`
* `--extra-options-file` — file with additional options (in JSON format) to
pass to `peg.generate`
* `--optimize` — selects between optimizing the generated parser for parsing
speed (`speed`) or code size (`size`) (default: `speed`)
* `--plugin` — makes PEG-Redux use a specified plugin (can be specified multiple
times)
* `--trace` — makes the parser trace its progress
### JavaScript API
Require the PEG-Redux parser generator module:
```javascript
var peg = require("peg-redux");
```
To generate a parser, call the `peg.generate` method and pass your grammar as a
parameter:
```javascript
var parser = peg.generate("start = ('a' / 'b')+");
```
The method will return generated parser object or its source code as a string
(depending on the value of the `output` option — see below). It will throw an
exception if the grammar is invalid. The exception will contain `message`
property with more details about the error.
You can tweak the generated parser by passing a second parameter with an options
object to `peg.generate`. The following options are supported:
* `allowedStartRules` — rules the parser will be allowed to start parsing from
(default: the first rule in the grammar)
* `cache` — if `true`, makes the parser cache results, avoiding exponential
parsing time in pathological cases but making the parser slower (default:
`false`)
* `dependencies` — parser dependencies, the value is an object which maps
variables used to access the dependencies in the parser to module IDs used
to load them.
* `optimize`— selects between optimizing the generated parser for parsing
speed (`"speed"`) or code size (`"size"`) (default: `"speed"`)
* `output` — if set to `"parser"`, the method will return generated parser
object; if set to `"source"`, it will return parser source code as a string
(default: `"parser"`)
* `plugins` — plugins to use
* `trace` — makes the parser trace its progress (default: `false`)
Using the Parser
----------------
Using the generated parser is simple — just call its `parse` method and pass an
input string as a parameter. The method will return a parse result (the exact
value depends on the grammar used to generate the parser) or throw an exception
if the input is invalid. The exception will contain `location`, `expected`,
`found`, and `message` properties with more details about the error.
```javascript
parser.parse("abba"); // returns ["a", "b", "b", "a"]
parser.parse("abcd"); // throws an exception
```
You can tweak parser behavior by passing a second parameter with an options
object to the `parse` method. The following options are supported:
* `startRule` — name of the rule to start parsing from
* `tracer` — tracer to use
Parsers can also support their own custom options.
Grammar Syntax and Semantics
----------------------------
The grammar syntax is similar to JavaScript in that it is not line-oriented and
ignores whitespace between tokens. You can also use JavaScript-style comments
(`// ...` and `/* ... */`).
Let's look at example grammar that recognizes simple arithmetic expressions like
`2*(3+4)`. A parser generated from this grammar computes their values.
```pegjs
start
= additive
additive
= left:multiplicative "+" right:additive { return left + right; }
/ multiplicative
multiplicative
= left:primary "*" right:multiplicative { return left * right; }
/ primary
primary
= integer
/ "(" additive:additive ")" { return additive; }
integer "integer"
= digits:[0-9]+ { return parseInt(digits.join(""), 10); }
```
On the top level, the grammar consists of *rules* (in our example, there are
five of them). Each rule has a *name* (e.g. `integer`) that identifies the rule,
and a *parsing expression* (e.g. `digits:[0-9]+ { return
parseInt(digits.join(""), 10); }`) that defines a pattern to match against the
input text and possibly contains some JavaScript code that determines what
happens when the pattern matches successfully. A rule can also contain
*human-readable name* that is used in error messages (in our example, only the
`integer` rule has a human-readable name). The parsing starts at the first rule,
which is also called the *start rule*.
A rule name must be a JavaScript identifier. It is followed by an equality sign
(“=”) and a parsing expression. If the rule has a human-readable name, it is
written as a JavaScript string between the name and separating equality sign.
Rules need to be separated only by whitespace (their beginning is easily
recognizable), but a semicolon (“;”) after the parsing expression is allowed.
The first rule can be preceded by an *initializer* — a piece of JavaScript code
in curly braces (“{” and “}”). This code is executed before the generated parser
starts parsing. All variables and functions defined in the initializer are
accessible in rule actions and semantic predicates. The code inside the
initializer can access options passed to the parser using the `options`
variable. Curly braces in the initializer code must be balanced. Let's look at
the example grammar from above using a simple initializer.
```pegjs
{
function makeInteger(o) {
return parseInt(o.join(""), 10);
}
}
start
= additive
additive
= left:multiplicative "+" right:additive { return left + right; }
/ multiplicative
multiplicative
= left:primary "*" right:multiplicative { return left * right; }
/ primary
primary
= integer
/ "(" additive:additive ")" { return additive; }
integer "integer"
= digits:[0-9]+ { return makeInteger(digits); }
```
The parsing expressions of the rules are used to match the input text to the
grammar. There are various types of expressions — matching characters or
character classes, indicating optional parts and repetition, etc. Expressions
can also contain references to other rules. See detailed description below.
If an expression successfully matches a part of the text when running the
generated parser, it produces a *match result*, which is a JavaScript value. For
example:
* An expression matching a literal string produces a JavaScript string
containing matched text.
* An expression matching repeated occurrence of some subexpression produces a
JavaScript array with all the matches.
The match results propagate through the rules when the rule names are used in
expressions, up to the start rule. The generated parser returns start rule's
match result when parsing is successful.
One special case of parser expression is a *parser action* — a piece of
JavaScript code inside curly braces (“{” and “}”) that takes match results of
some of the the preceding expressions and returns a JavaScript value. This value
is considered match result of the preceding expression (in other words, the
parser action is a match result transformer).
In our arithmetics example, there are many parser actions. Consider the action
in expression `digits:[0-9]+ { return parseInt(digits.join(""), 10); }`. It
takes the match result of the expression [0-9]+, which is an array of strings
containing digits, as its parameter. It joins the digits together to form a
number and converts it to a JavaScript `number` object.
### Parsing Expression Types
There are several types of parsing expressions, some of them containing
subexpressions and thus forming a recursive structure:
#### "*literal*"<br>'*literal*'
Match exact literal string and return it. The string syntax is the same as in
JavaScript. Appending `i` right after the literal makes the match
case-insensitive.
#### .
Match exactly one character and return it as a string.
#### [*characters*]
Match one character from a set and return it as a string. The characters in the
list can be escaped in exactly the same way as in JavaScript string. The list of
characters can also contain ranges (e.g. `[a-z]` means “all lowercase letters”).
Preceding the characters with `^` inverts the matched set (e.g. `[^a-z]` means
“all character but lowercase letters”). Appending `i` right after the right
bracket makes the match case-insensitive.
#### *rule*
Match a parsing expression of a rule recursively and return its match result.
#### ( *expression* )
Match a subexpression and return its match result.
#### *expression* \*
Match zero or more repetitions of the expression and return their match results
in an array. The matching is greedy, i.e. the parser tries to match the
expression as many times as possible. Unlike in regular expressions, there is no
backtracking.
#### *expression* +
Match one or more repetitions of the expression and return their match results
in an array. The matching is greedy, i.e. the parser tries to match the
expression as many times as possible. Unlike in regular expressions, there is no
backtracking.
#### *expression* ?
Try to match the expression. If the match succeeds, return its match result,
otherwise return `null`. Unlike in regular expressions, there is no
backtracking.
#### & *expression*
Try to match the expression. If the match succeeds, just return `undefined` and
do not consume any input, otherwise consider the match failed.
#### ! *expression*
Try to match the expression. If the match does not succeed, just return
`undefined` and do not consume any input, otherwise consider the match failed.
#### & { *predicate* }
The predicate is a piece of JavaScript code that is executed as if it was inside
a function. It gets the match results of labeled expressions in preceding
expression as its arguments. It should return some JavaScript value using the
`return` statement. If the returned value evaluates to `true` in boolean
context, just return `undefined` and do not consume any input; otherwise
consider the match failed.
The code inside the predicate can access all variables and functions defined in
the initializer at the beginning of the grammar.
The code inside the predicate can also access location information using the
`location` function. It returns an object like this:
```javascript
{
start: { offset: 23, line: 5, column: 6 },
end: { offset: 23, line: 5, column: 6 }
}
```
The `start` and `end` properties both refer to the current parse position. The
`offset` property contains an offset as a zero-based index and `line` and
`column` properties contain a line and a column as one-based indices.
The code inside the predicate can also access options passed to the parser using
the `options` variable.
Note that curly braces in the predicate code must be balanced.
#### ! { *predicate* }
The predicate is a piece of JavaScript code that is executed as if it was inside
a function. It gets the match results of labeled expressions in preceding
expression as its arguments. It should return some JavaScript value using the
`return` statement. If the returned value evaluates to `false` in boolean
context, just return `undefined` and do not consume any input; otherwise
consider the match failed.
The code inside the predicate can access all variables and functions defined in
the initializer at the beginning of the grammar.
The code inside the predicate can also access location information using the
`location` function. It returns an object like this:
```javascript
{
start: { offset: 23, line: 5, column: 6 },
end: { offset: 23, line: 5, column: 6 }
}
```
The `start` and `end` properties both refer to the current parse position. The
`offset` property contains an offset as a zero-based index and `line` and
`column` properties contain a line and a column as one-based indices.
The code inside the predicate can also access options passed to the parser using
the `options` variable.
Note that curly braces in the predicate code must be balanced.
#### $ *expression*
Try to match the expression. If the match succeeds, return the matched text
instead of the match result.
#### *label* : *expression*
Match the expression and remember its match result under given label. The label
must be a JavaScript identifier.
Labeled expressions are useful together with actions, where saved match results
can be accessed by action's JavaScript code.
#### *expression<sub>1</sub>* *expression<sub>2</sub>* ... *expression<sub>n</sub>*
Match a sequence of expressions and return their match results in an array.
#### *expression* { *action* }
Match the expression. If the match is successful, run the action, otherwise
consider the match failed.
The action is a piece of JavaScript code that is executed as if it was inside a
function. It gets the match results of labeled expressions in preceding
expression as its arguments. The action should return some JavaScript value
using the `return` statement. This value is considered match result of the
preceding expression.
To indicate an error, the code inside the action can invoke the `expected`
function, which makes the parser throw an exception. The function takes two
parameters — a description of what was expected at the current position and
optional location information (the default is what `location` would return — see
below). The description will be used as part of a message of the thrown
exception.
The code inside an action can also invoke the `error` function, which also makes
the parser throw an exception. The function takes two parameters — an error
message and optional location information (the default is what `location` would
return — see below). The message will be used by the thrown exception.
The code inside the action can access all variables and functions defined in the
initializer at the beginning of the grammar. Curly braces in the action code
must be balanced.
The code inside the action can also access the text matched by the expression
using the `text` function.
The code inside the action can also access location information using the
`location` function. It returns an object like this:
```javascript
{
start: { offset: 23, line: 5, column: 6 },
end: { offset: 25, line: 5, column: 8 }
}
```
The `start` property refers to the position at the beginning of the expression,
the `end` property refers to position after the end of the expression. The
`offset` property contains an offset as a zero-based index and `line` and
`column` properties contain a line and a column as one-based indices.
The code inside the action can also access options passed to the parser using
the `options` variable.
Note that curly braces in the action code must be balanced.
#### *expression<sub>1</sub>* / *expression<sub>2</sub>* / ... / *expression<sub>n</sub>*
Try to match the first expression, if it does not succeed, try the second one,
etc. Return the match result of the first successfully matched expression. If no
expression matches, consider the match failed.
Compatibility
-------------
Both the parser generator and generated parsers should run well in the following
environments:
* Node.js 4+
* Internet Explorer 9+
* Edge
* Firefox
* Chrome
* Safari
* Opera
However, please note that it is currently only actively tested in Node.js and Firefox. This will likely change in the future.
Development
-----------
PEG-Redux is maintained by [Sven Slootweg (joepie91)](http://cryto.net/~joepie91).
The original PEG.js was developed by [David Majda](http://majda.cz/) ([@dmajda](http://twitter.com/dmajda)).
You are welcome to contribute code. Unless your contribution is really trivial
you should get in touch with me first — this can prevent wasted effort on both
sides. You can send code both as a patch or a pull request.

@ -0,0 +1,5 @@
{
"env": {
"commonjs": true
}
}

@ -0,0 +1,50 @@
PEG.js Benchmark Suite
======================
This is the PEG.js benchmark suite. It measures speed of the parsers generated
by PEG.js on various inputs. Its main goal is to provide data for code generator
optimizations.
Running in Node.js
------------------
All commands in the following steps need to be executed in PEG.js root directory
(one level up from this one).
1. Install all PEG.js dependencies, including development ones:
```console
$ npm install
```
2. Execute the benchmark suite:
```console
$ gulp benchmark
```
3. Wait for results.
Running in the Browser
----------------------
All commands in the following steps need to be executed in PEG.js root directory
(one level up from this one).
1. Make sure you have Node.js installed.
2. Install all PEG.js dependencies, including development ones:
```console
$ npm install
```
3. Serve the benchmark suite using a web server:
```console
$ benchmark/server
```
4. Point your browser to the [benchmark suite](http://localhost:8000/).
5. Click the **Run** button and wait for results.

@ -0,0 +1,42 @@
"use strict";
let benchmarks = [
{
id: "json",
title: "JSON",
tests: [
{ file: "example1.json", title: "Example 1" },
{ file: "example2.json", title: "Example 2" },
{ file: "example3.json", title: "Example 3" },
{ file: "example4.json", title: "Example 4" },
{ file: "example5.json", title: "Example 5" }
]
},
{
id: "css",
title: "CSS",
tests: [
{ file: "blueprint/src/reset.css", title: "Blueprint - reset.css (source)" },
{ file: "blueprint/src/typography.css", title: "Blueprint - typography.css (source)" },
{ file: "blueprint/src/forms.css", title: "Blueprint - forms.css (source)" },
{ file: "blueprint/src/grid.css", title: "Blueprint - grid.css (source)" },
{ file: "blueprint/src/print.css", title: "Blueprint - print.css (source)" },
// Contains syntax errors.
// { file: "blueprint/src/ie.css", title: "Blueprint - ie.css (source)" },
{ file: "blueprint/min/screen.css", title: "Blueprint - screen.css (minified)" },
{ file: "blueprint/min/print.css", title: "Blueprint - print.css (minified)" },
// Contains syntax errors.
// { file: "blueprint/min/ie.css", title: "Blueprint - ie.css (minified)" },
{ file: "960.gs/src/reset.css", title: "960.gs - reset.css (source)" },
{ file: "960.gs/src/text.css", title: "960.gs - text.css (source)" },
{ file: "960.gs/src/960.css", title: "960.gs - 960.css (source)" },
{ file: "960.gs/src/960_24_col.css", title: "960.gs - 960_24_col.css (source)" },
{ file: "960.gs/min/reset.css", title: "960.gs - reset.css (minified)" },
{ file: "960.gs/min/text.css", title: "960.gs - text.css (minified)" },
{ file: "960.gs/min/960.css", title: "960.gs - 960.css (minified)" },
{ file: "960.gs/min/960_24_col.css", title: "960.gs - 960_24_col.css (minified)" }
]
}
];
module.exports = benchmarks;

@ -0,0 +1,35 @@
/* -----------------------------------------------------------------------
Blueprint CSS Framework 0.9
http://blueprintcss.org
* Copyright (c) 2007-Present. See LICENSE for more info.
* See README for instructions on how to use Blueprint.
* For credits and origins, see AUTHORS.
* This is a compressed file. See the sources in the 'src' directory.
----------------------------------------------------------------------- */
/* ie.css */
body {text-align:center;}
.container {text-align:left;}
* html .column, * html .span-1, * html .span-2, * html .span-3, * html .span-4, * html .span-5, * html .span-6, * html .span-7, * html .span-8, * html .span-9, * html .span-10, * html .span-11, * html .span-12, * html .span-13, * html .span-14, * html .span-15, * html .span-16, * html .span-17, * html .span-18, * html .span-19, * html .span-20, * html .span-21, * html .span-22, * html .span-23, * html .span-24 {display:inline;overflow-x:hidden;}
* html legend {margin:0px -8px 16px 0;padding:0;}
sup {vertical-align:text-top;}
sub {vertical-align:text-bottom;}
html>body p code {*white-space:normal;}
hr {margin:-8px auto 11px;}
img {-ms-interpolation-mode:bicubic;}
.clearfix, .container {display:inline-block;}
* html .clearfix, * html .container {height:1%;}
fieldset {padding-top:0;}
textarea {overflow:auto;}
input.text, input.title, textarea {background-color:#fff;border:1px solid #bbb;}
input.text:focus, input.title:focus {border-color:#666;}
input.text, input.title, textarea, select {margin:0.5em 0;}
input.checkbox, input.radio {position:relative;top:.25em;}
form.inline div, form.inline p {vertical-align:middle;}
form.inline label {position:relative;top:-0.25em;}
form.inline input.checkbox, form.inline input.radio, form.inline input.button, form.inline button {margin:0.5em 0;}
button, input.button {position:relative;top:0.25em;}

@ -0,0 +1,76 @@
/* --------------------------------------------------------------
ie.css
Contains every hack for Internet Explorer,
so that our core files stay sweet and nimble.
-------------------------------------------------------------- */
/* Make sure the layout is centered in IE5 */
body { text-align: center; }
.container { text-align: left; }
/* Fixes IE margin bugs */
* html .column, * html .span-1, * html .span-2,
* html .span-3, * html .span-4, * html .span-5,
* html .span-6, * html .span-7, * html .span-8,
* html .span-9, * html .span-10, * html .span-11,
* html .span-12, * html .span-13, * html .span-14,
* html .span-15, * html .span-16, * html .span-17,
* html .span-18, * html .span-19, * html .span-20,
* html .span-21, * html .span-22, * html .span-23,
* html .span-24 { display:inline; overflow-x: hidden; }
/* Elements
-------------------------------------------------------------- */
/* Fixes incorrect styling of legend in IE6. */
* html legend { margin:0px -8px 16px 0; padding:0; }
/* Fixes wrong line-height on sup/sub in IE. */
sup { vertical-align:text-top; }
sub { vertical-align:text-bottom; }
/* Fixes IE7 missing wrapping of code elements. */
html>body p code { *white-space: normal; }
/* IE 6&7 has problems with setting proper <hr> margins. */
hr { margin:-8px auto 11px; }
/* Explicitly set interpolation, allowing dynamically resized images to not look horrible */
img { -ms-interpolation-mode:bicubic; }
/* Clearing
-------------------------------------------------------------- */
/* Makes clearfix actually work in IE */
.clearfix, .container { display:inline-block; }
* html .clearfix,
* html .container { height:1%; }
/* Forms
-------------------------------------------------------------- */
/* Fixes padding on fieldset */
fieldset { padding-top:0; }
/* Makes classic textareas in IE 6 resemble other browsers */
textarea { overflow:auto; }
/* Fixes rule that IE 6 ignores */
input.text, input.title, textarea { background-color:#fff; border:1px solid #bbb; }
input.text:focus, input.title:focus { border-color:#666; }
input.text, input.title, textarea, select { margin:0.5em 0; }
input.checkbox, input.radio { position:relative; top:.25em; }
/* Fixes alignment of inline form elements */
form.inline div, form.inline p { vertical-align:middle; }
form.inline label { position:relative;top:-0.25em; }
form.inline input.checkbox, form.inline input.radio,
form.inline input.button, form.inline button {
margin:0.5em 0;
}
button, input.button { position:relative;top:0.25em; }

@ -0,0 +1,40 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>PEG.js Benchmark Suite</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
<h1>PEG.js Benchmark Suite</h1>
<div id="options">
<label for="run-count">Run each test</label>
<input type="text" id="run-count" value="10"> times
<input type="checkbox" id="cache">
<label for="cache">Use results cache</label>
<label for="optimize">Optimize:</label>
<select id="optimize">
<option value="speed">Speed</option>
<option value="size">Size</option>
</select>
<input type="button" id="run" value="Run">
</div>
<table id="results-table">
<tr class="columns">
<th>Test</th>
<th>Input Size</th>
<th>Average Parse Time</th>
<th>Average Parse Speed</th>
</tr>
<tr>
<td class="no-results" colspan="4">No results available yet.</td>
</tr>
</table>
<script src="vendor/jquery/jquery.js"></script>
<script src="vendor/jquery.scrollto/jquery.scrollTo.js"></script>
<script src="bundle.js"></script>
</body>
</html>

@ -0,0 +1,139 @@
"use strict";
/* eslint-env browser, jquery */
let Runner = require("./runner.js");
let benchmarks = require("./benchmarks.js");
$("#run").click(() => {
// Results Table Manipulation
let resultsTable = $("#results-table");
function appendHeading(heading) {
resultsTable.append(
"<tr class='heading'><th colspan='4'>" + heading + "</th></tr>"
);
}
function appendResult(klass, title, url, inputSize, parseTime) {
const KB = 1024;
const MS_IN_S = 1000;
resultsTable.append(
"<tr class='" + klass + "'>"
+ "<td class='title'>"
+ (url !== null ? "<a href='" + url + "'>" : "")
+ title
+ (url !== null ? "</a>" : "")
+ "</td>"
+ "<td class='input-size'>"
+ "<span class='value'>"
+ (inputSize / KB).toFixed(2)
+ "</span>"
+ "&nbsp;<span class='unit'>kB</span>"
+ "</td>"
+ "<td class='parse-time'>"
+ "<span class='value'>"
+ parseTime.toFixed(2)
+ "</span>"
+ "&nbsp;<span class='unit'>ms</span>"
+ "</td>"
+ "<td class='parse-speed'>"
+ "<span class='value'>"
+ ((inputSize / KB) / (parseTime / MS_IN_S)).toFixed(2)
+ "</span>"
+ "&nbsp;<span class='unit'>kB/s</span>"
+ "</td>"
+ "</tr>"
);
}
// Main
// Each input is parsed multiple times and the results are averaged. We
// do this for two reasons:
//
// 1. To warm up the interpreter (PEG.js-generated parsers will be
// most likely used repeatedly, so it makes sense to measure
// performance after warming up).
//
// 2. To minimize random errors.
let runCount = parseInt($("#run-count").val(), 10);
let options = {
cache: $("#cache").is(":checked"),
optimize: $("#optimize").val()
};
if (isNaN(runCount) || runCount <= 0) {
// eslint-disable-next-line no-alert
alert("Number of runs must be a positive integer.");
return;
}
Runner.run(benchmarks, runCount, options, {
readFile(file) {
return $.ajax({
type: "GET",
url: file,
dataType: "text",
async: false
}).responseText;
},
testStart() {
// Nothing to do.
},
testFinish(benchmark, test, inputSize, parseTime) {
appendResult(
"individual",
test.title,
benchmark.id + "/" + test.file,
inputSize,
parseTime
);
},
benchmarkStart(benchmark) {
appendHeading(benchmark.title);
},
benchmarkFinish(benchmark, inputSize, parseTime) {
appendResult(
"benchmark-total",
benchmark.title + " total",
null,
inputSize,
parseTime
);
},
start() {
$("#run-count, #cache, #run").attr("disabled", "disabled");
resultsTable.show();
$("#results-table tr").slice(1).remove();
},
finish(inputSize, parseTime) {
appendResult(
"total",
"Total",
null,
inputSize,
parseTime
);
$.scrollTo("max", { axis: "y", duration: 500 });
$("#run-count, #cache, #run").removeAttr("disabled");
}
});
});
$(document).ready(() => {
$("#run").focus();
});

@ -0,0 +1,198 @@
#!/usr/bin/env node
"use strict";
/* eslint-env node */
let Runner = require("./runner.js");
let benchmarks = require("./benchmarks.js");
let fs = require("fs");
// Results Table Manipulation
function dup(text, count) {
let result = "";
for (let i = 1; i <= count; i++) {
result += text;
}
return result;
}
function padLeft(text, length) {
return dup(" ", length - text.length) + text;
}
function padRight(text, length) {
return text + dup(" ", length - text.length);
}
function center(text, length) {
let padLength = (length - text.length) / 2;
return dup(" ", Math.floor(padLength))
+ text
+ dup(" ", Math.ceil(padLength));
}
function writeTableHeader() {
console.log("┌─────────────────────────────────────┬───────────┬────────────┬──────────────┐");
console.log("│ Test │ Inp. size │ Avg. time │ Avg. speed │");
}
function writeHeading(heading) {
console.log("├─────────────────────────────────────┴───────────┴────────────┴──────────────┤");
console.log("│ " + center(heading, 75) + " │");
console.log("├─────────────────────────────────────┬───────────┬────────────┬──────────────┤");
}
function writeResult(title, inputSize, parseTime) {
const KB = 1024;
const MS_IN_S = 1000;
console.log("│ "
+ padRight(title, 35)
+ " │ "
+ padLeft((inputSize / KB).toFixed(2), 6)
+ " kB │ "
+ padLeft(parseTime.toFixed(2), 7)
+ " ms │ "
+ padLeft(((inputSize / KB) / (parseTime / MS_IN_S)).toFixed(2), 7)
+ " kB/s │"
);
}
function writeSeparator() {
console.log("├─────────────────────────────────────┼───────────┼────────────┼──────────────┤");
}
function writeTableFooter() {
console.log("└─────────────────────────────────────┴───────────┴────────────┴──────────────┘");
}
// Helpers
function printHelp() {
console.log("Usage: run [options]");
console.log("");
console.log("Runs PEG.js benchmark suite.");
console.log("");
console.log("Options:");
console.log(" -n, --run-count <n> number of runs (default: 10)");
console.log(" --cache make tested parsers cache results");
console.log(" -o, --optimize <goal> select optimization for speed or size (default:");
console.log(" speed)");
}
function exitSuccess() {
process.exit(0);
}
function exitFailure() {
process.exit(1);
}
function abort(message) {
console.error(message);
exitFailure();
}
// Arguments
let args = process.argv.slice(2); // Trim "node" and the script path.
function isOption(arg) {
return (/^-/).test(arg);
}
function nextArg() {
args.shift();
}
// Main
let runCount = 10;
let options = {
cache: false,
optimize: "speed"
};
while (args.length > 0 && isOption(args[0])) {
switch (args[0]) {
case "-n":
case "--run-count":
nextArg();
if (args.length === 0) {
abort("Missing parameter of the -n/--run-count option.");
}
runCount = parseInt(args[0], 10);
if (isNaN(runCount) || runCount <= 0) {
abort("Number of runs must be a positive integer.");
}
break;
case "--cache":
options.cache = true;
break;
case "-o":
case "--optimize":
nextArg();
if (args.length === 0) {
abort("Missing parameter of the -o/--optimize option.");
}
if (args[0] !== "speed" && args[0] !== "size") {
abort("Optimization goal must be either \"speed\" or \"size\".");
}
options.optimize = args[0];
break;
case "-h":
case "--help":
printHelp();
exitSuccess();
break;
default:
abort("Unknown option: " + args[0] + ".");
}
nextArg();
}
if (args.length > 0) {
abort("No arguments are allowed.");
}
Runner.run(benchmarks, runCount, options, {
readFile(file) {
return fs.readFileSync(__dirname + "/" + file, "utf8");
},
testStart() {
// Nothing to do.
},
testFinish(benchmark, test, inputSize, parseTime) {
writeResult(test.title, inputSize, parseTime);
},
benchmarkStart(benchmark) {
writeHeading(benchmark.title);
},
benchmarkFinish(benchmark, inputSize, parseTime) {
writeSeparator();
writeResult(benchmark.title + " total", inputSize, parseTime);
},
start() {
writeTableHeader();
},
finish(inputSize, parseTime) {
writeSeparator();
writeResult("Total", inputSize, parseTime);
writeTableFooter();
}
});

@ -0,0 +1,116 @@
"use strict";
let peg = require("../lib/peg");
let Runner = {
run(benchmarks, runCount, options, callbacks) {
// Queue
let Q = {
functions: [],
add(f) {
this.functions.push(f);
},
run() {
if (this.functions.length > 0) {
this.functions.shift()();
// We can't use |arguments.callee| here because |this| would get
// messed-up in that case.
setTimeout(() => { Q.run(); }, 0);
}
}
};
// The benchmark itself is factored out into several functions (some of them
// generated), which are enqueued and run one by one using |setTimeout|. We
// do this for two reasons:
//
// 1. To avoid bowser mechanism for interrupting long-running scripts to
// kick-in (or at least to not kick-in that often).
//
// 2. To ensure progressive rendering of results in the browser (some
// browsers do not render at all when running JavaScript code).
//
// The enqueued functions share state, which is all stored in the properties
// of the |state| object.
let state = {};
function initialize() {
callbacks.start();
state.totalInputSize = 0;
state.totalParseTime = 0;
}
function benchmarkInitializer(benchmark) {
return function() {
callbacks.benchmarkStart(benchmark);
state.parser = peg.generate(
callbacks.readFile("../examples/" + benchmark.id + ".pegjs"),
options
);
state.benchmarkInputSize = 0;
state.benchmarkParseTime = 0;
};
}
function testRunner(benchmark, test) {
return function() {
callbacks.testStart(benchmark, test);
let input = callbacks.readFile(benchmark.id + "/" + test.file);
let parseTime = 0;
for (let i = 0; i < runCount; i++) {
let t = (new Date()).getTime();
state.parser.parse(input);
parseTime += (new Date()).getTime() - t;
}
let averageParseTime = parseTime / runCount;
callbacks.testFinish(benchmark, test, input.length, averageParseTime);
state.benchmarkInputSize += input.length;
state.benchmarkParseTime += averageParseTime;
};
}
function benchmarkFinalizer(benchmark) {
return function() {
callbacks.benchmarkFinish(
benchmark,
state.benchmarkInputSize,
state.benchmarkParseTime
);
state.totalInputSize += state.benchmarkInputSize;
state.totalParseTime += state.benchmarkParseTime;
};
}
function finalize() {
callbacks.finish(state.totalInputSize, state.totalParseTime);
}
// Main
Q.add(initialize);
benchmarks.forEach(benchmark => {
Q.add(benchmarkInitializer(benchmark));
benchmark.tests.forEach(test => {
Q.add(testRunner(benchmark, test));
});
Q.add(benchmarkFinalizer(benchmark));
});
Q.add(finalize);
Q.run();
}
};
module.exports = Runner;

@ -0,0 +1,37 @@
#!/usr/bin/env node
"use strict";
/* eslint-env node */
// Small server whose main purpose is to ensure that both the benchmarked code
// and the benchmark get passed through Babel & Browserify before they are
// served to the browser.
let babelify = require("babelify");
let browserify = require("browserify");
let express = require("express");
let glob = require("glob");
let logger = require("morgan");
let app = express();
app.use(logger("dev"));
app.use(express.static(__dirname));
app.use("/examples", express.static(`${__dirname}/../examples`));
app.get("/bundle.js", (req, res) => {
let files = glob.sync(`${__dirname}/**/*.js`, {
ignore: `${__dirname}/vendor/**/*`
});
browserify(files)
.transform(babelify, { presets: "env", compact: false })
.bundle()
.pipe(res);
});
app.listen(8000, () => {
// eslint-disable-next-line no-console
console.log("Benchmark server running at http://localhost:8000...");
});

@ -0,0 +1,22 @@
(The MIT License)
Copyright (c) 2007-2015 Ariel Flesler <aflesler@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@ -0,0 +1,7 @@
/**
* Copyright (c) 2007-2015 Ariel Flesler - aflesler<a>gmail<d>com | http://flesler.blogspot.com
* Licensed under MIT
* @author Ariel Flesler
* @version 2.1.2
*/
;(function(f){"use strict";"function"===typeof define&&define.amd?define(["jquery"],f):"undefined"!==typeof module&&module.exports?module.exports=f(require("jquery")):f(jQuery)})(function($){"use strict";function n(a){return!a.nodeName||-1!==$.inArray(a.nodeName.toLowerCase(),["iframe","#document","html","body"])}function h(a){return $.isFunction(a)||$.isPlainObject(a)?a:{top:a,left:a}}var p=$.scrollTo=function(a,d,b){return $(window).scrollTo(a,d,b)};p.defaults={axis:"xy",duration:0,limit:!0};$.fn.scrollTo=function(a,d,b){"object"=== typeof d&&(b=d,d=0);"function"===typeof b&&(b={onAfter:b});"max"===a&&(a=9E9);b=$.extend({},p.defaults,b);d=d||b.duration;var u=b.queue&&1<b.axis.length;u&&(d/=2);b.offset=h(b.offset);b.over=h(b.over);return this.each(function(){function k(a){var k=$.extend({},b,{queue:!0,duration:d,complete:a&&function(){a.call(q,e,b)}});r.animate(f,k)}if(null!==a){var l=n(this),q=l?this.contentWindow||window:this,r=$(q),e=a,f={},t;switch(typeof e){case "number":case "string":if(/^([+-]=?)?\d+(\.\d+)?(px|%)?$/.test(e)){e= h(e);break}e=l?$(e):$(e,q);case "object":if(e.length===0)return;if(e.is||e.style)t=(e=$(e)).offset()}var v=$.isFunction(b.offset)&&b.offset(q,e)||b.offset;$.each(b.axis.split(""),function(a,c){var d="x"===c?"Left":"Top",m=d.toLowerCase(),g="scroll"+d,h=r[g](),n=p.max(q,c);t?(f[g]=t[m]+(l?0:h-r.offset()[m]),b.margin&&(f[g]-=parseInt(e.css("margin"+d),10)||0,f[g]-=parseInt(e.css("border"+d+"Width"),10)||0),f[g]+=v[m]||0,b.over[m]&&(f[g]+=e["x"===c?"width":"height"]()*b.over[m])):(d=e[m],f[g]=d.slice&& "%"===d.slice(-1)?parseFloat(d)/100*n:d);b.limit&&/^\d+$/.test(f[g])&&(f[g]=0>=f[g]?0:Math.min(f[g],n));!a&&1<b.axis.length&&(h===f[g]?f={}:u&&(k(b.onAfterFirst),f={}))});k(b.onAfter)}})};p.max=function(a,d){var b="x"===d?"Width":"Height",h="scroll"+b;if(!n(a))return a[h]-$(a)[b.toLowerCase()]();var b="client"+b,k=a.ownerDocument||a.document,l=k.documentElement,k=k.body;return Math.max(l[h],k[h])-Math.min(l[b],k[b])};$.Tween.propHooks.scrollLeft=$.Tween.propHooks.scrollTop={get:function(a){return $(a.elem)[a.prop]()}, set:function(a){var d=this.get(a);if(a.options.interrupt&&a._last&&a._last!==d)return $(a.elem).stop();var b=Math.round(a.now);d!==b&&($(a.elem)[a.prop](b),a._last=this.get(a))}};return p});

@ -0,0 +1,36 @@
Copyright jQuery Foundation and other contributors, https://jquery.org/
This software consists of voluntary contributions made by many
individuals. For exact contribution history, see the revision history
available at https://github.com/jquery/jquery
The following license applies to all parts of this software except as
documented below:
====
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
====
All files located in the node_modules and external directories are
externally maintained libraries used by this software which have their
own licenses; we recommend you read them, as their terms may differ from
the terms above.

File diff suppressed because one or more lines are too long

@ -0,0 +1,8 @@
{
"env": {
"node": true
},
"rules": {
"no-console": 0
}
}

@ -0,0 +1,326 @@
#!/usr/bin/env node
"use strict";
let fs = require("fs");
let path = require("path");
let peg = require("../lib/peg");
// Helpers
function printVersion() {
console.log("PEG.js " + peg.VERSION);
}
function printHelp() {
console.log("Usage: pegjs [options] [--] [<input_file>]");
console.log("");
console.log("Options:");
console.log(" --allowed-start-rules <rules> comma-separated list of rules the generated");
console.log(" parser will be allowed to start parsing");
console.log(" from (default: the first rule in the");
console.log(" grammar)");
console.log(" --cache make generated parser cache results");
console.log(" -d, --dependency <dependency> use specified dependency (can be specified");
console.log(" multiple times)");
console.log(" -e, --export-var <variable> name of a global variable into which the");
console.log(" parser object is assigned to when no module");
console.log(" loader is detected");
console.log(" --extra-options <options> additional options (in JSON format) to pass");
console.log(" to peg.generate");
console.log(" --extra-options-file <file> file with additional options (in JSON");
console.log(" format) to pass to peg.generate");
console.log(" --format <format> format of the generated parser: amd,");
console.log(" commonjs, globals, umd (default: commonjs)");
console.log(" -h, --help print help and exit");
console.log(" -O, --optimize <goal> select optimization for speed or size");
console.log(" (default: speed)");
console.log(" -o, --output <file> output file");
console.log(" --plugin <plugin> use a specified plugin (can be specified");
console.log(" multiple times)");
console.log(" --trace enable tracing in generated parser");
console.log(" -v, --version print version information and exit");
}
function exitSuccess() {
process.exit(0);
}
function exitFailure() {
process.exit(1);
}
function abort(message) {
console.error(message);
exitFailure();
}
function addExtraOptions(options, json) {
let extraOptions;
try {
extraOptions = JSON.parse(json);
} catch (e) {
if (!(e instanceof SyntaxError)) { throw e; }
abort("Error parsing JSON: " + e.message);
}
if (typeof extraOptions !== "object") {
abort("The JSON with extra options has to represent an object.");
}
Object.keys(extraOptions).forEach(key => {
options[key] = extraOptions[key];
});
}
// Extracted into a function just to silence JSHint complaining about creating
// functions in a loop.
function trim(s) {
return s.trim();
}
// Arguments
let args = process.argv.slice(2); // Trim "node" and the script path.
function isOption(arg) {
return (/^-.+/).test(arg);
}
function nextArg() {
args.shift();
}
// Files
function readStream(inputStream, callback) {
let input = "";
inputStream.on("data", data => { input += data; });
inputStream.on("end", () => { callback(input); });
}
// Main
let inputFile = null;
let outputFile = null;
let options = {
cache: false,
dependencies: {},
exportVar: null,
format: "commonjs",
optimize: "speed",
output: "source",
plugins: [],
trace: false
};
while (args.length > 0 && isOption(args[0])) {
let json, id, mod;
switch (args[0]) {
case "--allowed-start-rules":
nextArg();
if (args.length === 0) {
abort("Missing parameter of the -e/--allowed-start-rules option.");
}
options.allowedStartRules = args[0]
.split(",")
.map(trim);
break;
case "--cache":
options.cache = true;
break;
case "-d":
case "--dependency":
nextArg();
if (args.length === 0) {
abort("Missing parameter of the -d/--dependency option.");
}
if (args[0].indexOf(":") !== -1) {
let parts = args[0].split(":");
options.dependencies[parts[0]] = parts[1];
} else {
options.dependencies[args[0]] = args[0];
}
break;
case "-e":
case "--export-var":
nextArg();
if (args.length === 0) {
abort("Missing parameter of the -e/--export-var option.");
}
options.exportVar = args[0];
break;
case "--extra-options":
nextArg();
if (args.length === 0) {
abort("Missing parameter of the --extra-options option.");
}
addExtraOptions(options, args[0]);
break;
case "--extra-options-file":
nextArg();
if (args.length === 0) {
abort("Missing parameter of the --extra-options-file option.");
}
try {
json = fs.readFileSync(args[0]);
} catch (e) {
abort("Can't read from file \"" + args[0] + "\".");
}
addExtraOptions(options, json);
break;
case "--format":
nextArg();
if (args.length === 0) {
abort("Missing parameter of the --format option.");
}
if (args[0] !== "amd" && args[0] !== "commonjs" && args[0] !== "globals" && args[0] !== "umd") {
abort("Module format must be one of \"amd\", \"commonjs\", \"globals\", and \"umd\".");
}
options.format = args[0];
break;
case "-h":
case "--help":
printHelp();
exitSuccess();
break;
case "-O":
case "--optimize":
nextArg();
if (args.length === 0) {
abort("Missing parameter of the -O/--optimize option.");
}
if (args[0] !== "speed" && args[0] !== "size") {
abort("Optimization goal must be either \"speed\" or \"size\".");
}
options.optimize = args[0];
break;
case "-o":
case "--output":
nextArg();
if (args.length === 0) {
abort("Missing parameter of the -o/--output option.");
}
outputFile = args[0];
break;
case "--plugin":
nextArg();
if (args.length === 0) {
abort("Missing parameter of the --plugin option.");
}
id = /^(\.\/|\.\.\/)/.test(args[0]) ? path.resolve(args[0]) : args[0];
try {
mod = require(id);
} catch (e) {
if (e.code !== "MODULE_NOT_FOUND") { throw e; }
abort("Can't load module \"" + id + "\".");
}
options.plugins.push(mod);
break;
case "--trace":
options.trace = true;
break;
case "-v":
case "--version":
printVersion();
exitSuccess();
break;
case "--":
nextArg();
break;
default:
abort("Unknown option: " + args[0] + ".");
}
nextArg();
}
if (Object.keys(options.dependencies).length > 0) {
if (options.format !== "amd" && options.format !== "commonjs" && options.format !== "umd") {
abort("Can't use the -d/--dependency option with the \"" + options.format + "\" module format.");
}
}
if (options.exportVar !== null) {
if (options.format !== "globals" && options.format !== "umd") {
abort("Can't use the -e/--export-var option with the \"" + options.format + "\" module format.");
}
}
let inputStream, outputStream;
switch (args.length) {
case 0:
inputFile = "-";
break;
case 1:
inputFile = args[0];
break;
default:
abort("Too many arguments.");
}
if (outputFile === null) {
if (inputFile === "-") {
outputFile = "-";
} else {
outputFile = inputFile.substr(0, inputFile.length - path.extname(inputFile).length) + ".js";
}
}
if (inputFile === "-") {
process.stdin.resume();
inputStream = process.stdin;
inputStream.on("error", () => {
abort("Can't read from file \"" + inputFile + "\".");
});
} else {
inputStream = fs.createReadStream(inputFile);
}
if (outputFile === "-") {
outputStream = process.stdout;
} else {
outputStream = fs.createWriteStream(outputFile);
outputStream.on("error", () => {
abort("Can't write to file \"" + outputFile + "\".");
});
}
readStream(inputStream, input => {
let source;
try {
source = peg.generate(input, options);
} catch (e) {
if (e.location !== undefined) {
abort(e.location.start.line + ":" + e.location.start.column + ": " + e.message);
} else {
abort(e.message);
}
}
outputStream.write(source);
if (outputStream !== process.stdout) {
outputStream.end();
}
});

@ -1,14 +0,0 @@
* [v0.10](./v0.10.md) _(August 19, 2016)_
* [v0.9](./v0.9.md) _(August 30, 2015)_
* [v0.8](./v0.8.md) _(December 24, 2013)_
* [v0.7](./v0.7.md) _(April 18, 2012)_
* [v0.6.2](./v0.6.md) _(April 20, 2011)_
* [v0.6.1](./v0.6.md) _(April 14, 2011)_
* [v0.6](./v0.6.md) _(April 14, 2011)_
* [v0.5.1](./v0.5.md) _(November 28, 2010)_
* [v0.5](./v0.5.md) _(June 10, 2010)_
* [v0.4](./v0.4.md) _(April 17, 2010)_
* [v0.3](./v0.3.md) _(March 14, 2010)_
* [v0.2.1](./v0.2.md) _(March 8, 2010)_
* [v0.2](./v0.2.md) _(March 8, 2010)_
* [v0.1](./v0.1.md) _(March 8, 2010)_

@ -1,5 +0,0 @@
> See [commit history](https://github.com/pegjs/pegjs/commits/0.1) for a full list of changes.
## v0.1 _(March 8, 2010)_
* Initial release.

@ -1,60 +0,0 @@
> See [commit history](https://github.com/pegjs/pegjs/compare/v0.9.0...v0.10.0) for a full list of changes.
## v0.10.0 _(August 19, 2016)_
### Major Changes
* **Parsers can be generated in multiple module formats.**
The available formats are: CommonJS (the default), AMD, UMD, globals, and bare (not available from the command-line).
The format can be specified using the `format` option of the `peg.generate` function or the `--format` option on the command-line.
It is also possible to specify parser dependencies using the `dependencies` option of the `peg.generate` function or the `--dependency`/`-d` option on the command-line. This is mainly useful for the UMD format, where the dependencies are translated into both AMD dependencies and CommonJS `require` calls.
* **Browser version of PEG.js is now in the UMD format.**
This means it will try to detect AMD or Node.js/CommonJS module loader and define itself as a module. If no loader is found, it will export itself using a global variable.
* **API polishing.**
The `peg.buildParser` function was renamed to `peg.generate`. The global variable the browser version of PEG.js is available in when no loader is detected was renamed from `PEG` to `peg`.
* **CLI improvements.**
There is new `--output`/`-o` command-line option which allows to specify the output file. The old way of specifying the output file using a second argument was removed. To make room for the new `-o` option the old one (a shortcut for `--optimize`) was renamed to `-O`. All these changes make PEG.js conform to traditional compiler command-line interface.
It is now also possible to use `-` as a file name on the command-line (with the usual meaning of standard input/output).
* **Improved error messages.**
Both messages produced by PEG.js and generated parsers were improved.
* **Duplicate rule definitions are reported as errors.**
* **Duplicate labels are reported as errors.**
### Minor Changes
* Exposed the AST node visitor builder as `peg.compiler.visitor`. This is useful mainly for plugins which manipulate the AST.
* Exposed the function which builds messages of exceptions produced by generated parsers as `SyntaxError.buildMessage`. This is useful mainly for customizing these error messages.
* The `error` and `expected` functions now accept an optional `location` parameter. This allows to customize the location in which the resulting syntax error is reported.
* Refactored expectations reported in the `expected` property of exceptions produced by generated parsers. They are no longer de-duplicated and sorted, their format changed to be more machine-readable, and they no longer contain human-readable descriptions.
* The `found` property of exceptions produced by the `error` function is now set to `null`.
* Removed access to the parser object in parser code via the `parser` variable.
* Made handling of optional parameters consistent with ES 2015. Specifically, passing `undefined` as a parameter value is now equivalent to not passing the parameter at all.
* Renamed several compiler passes.
* Generated parsers no longer consider `\r`, `\u2028`, and `\u2029` as newlines (only `\n` and `\r\n`).
* Simplified the arithmetic's example grammar.
* Switched from `first`/`rest` to `head`/`tail` in PEG.js grammar and example grammars.
* Started using ESLint instead of JSHint and fixed various problems it found.
* Added [contribution guidelines](https://github.com/pegjs/pegjs/blob/master/CONTRIBUTING.md).
* Removed support for io.js.
### Bug Fixes
* Fixed `bin/pegjs` so that invoking it with one non-option argument which is an extension-less file doesnt cause that file to be overwritten.
* Fixed label scoping so that labels in expressions like `(a:"a")` or `(a:"a" b:"b" c:"c")` arent visible from the outside.
* Fixed escaping of generated JavaScript strings & regexps to also escape DEL (U+007F).
* Fixed the JSON example grammar to correctly handle characters with code points above U+10FF in strings.
* Fixed multiple compatibility issues of `tools/impact` on OS X.
* Fixed slow deduplication of expectation descriptions.

@ -1,10 +0,0 @@
> See [commit history](https://github.com/pegjs/pegjs/compare/0.1...0.2.1) for a full list of changes.
## v0.2.1 _(March 8, 2010)_
* Added `pegjs-` prefix to the name of the minified runtime file.
## v0.2 _(March 8, 2010)_
* Added `Rakefile` that builds minified runtime using Google Closure Compiler API.
* Removed trailing commas in object initializers (Google Closure does not like them).

@ -1,14 +0,0 @@
> See [commit history](https://github.com/pegjs/pegjs/compare/0.2.1...0.3) for a full list of changes.
### v0.3 _(March 14, 2010)_
* Wrote `README`.
* Bootstrapped the grammar parser.
* Metagrammar recognizes JavaScript-like comments.
* Changed standard grammar extension from `.peg` to `.pegjs` (it is more specific).
* Simplified the example arithmetic's grammar + added comment.
* Fixed a bug with reporting of invalid ranges such as `[b-a]` in the metagrammar.
* Fixed `--start` vs. `--start-rule` inconsistency between help and actual option processing code.
* Avoided ugliness in QUnit output.
* Fixed typo in help: `parserVar``parser_var`.
* Internal code improvements.

@ -1,24 +0,0 @@
> See [commit history](https://github.com/pegjs/pegjs/compare/0.3...0.4) for a full list of changes.
## v0.4 _(April 17, 2010)_
### Big Changes
* Improved IE compatibility — IE6+ is now fully supported.
* Generated parsers are now standalone (no runtime is required).
* Added example grammars for JavaScript, CSS and JSON.
* Added a benchmark suite.
* Implemented negative character classes (e.g. `[^a-z]`).
* Project moved from BitBucket to GitHub.
### Small Changes
* Code generated for the character classes is now regexp-based (= simpler and more scalable).
* Added `\uFEFF` (BOM) to the definition of whitespace in the metagrammar.
* When building a parser, left-recursive rules (both direct and indirect) are reported as errors.
* When building a parser, missing rules are reported as errors.
* Expected items in the error messages do not contain duplicates and they are sorted.
* Fixed several bugs in the example arithmetic's grammar.
* Converted `README` to GitHub Flavored Markdown and improved it.
* Added `CHANGELOG`.
* Internal code improvements.

@ -1,38 +0,0 @@
> See [commit history](https://github.com/pegjs/pegjs/compare/0.4...0.5.1) for a full list of changes.
## v0.5.1 _(November 28, 2010)_
### Small Changes
* Fixed a problem where “SyntaxError: Invalid range in character class.” error appeared when using command-line version on Windows ([GH-13](https://github.com/dmajda/pegjs/issues/13)).
* Fixed wrong version reported by `bin/pegjs --version`.
* Removed two unused variables in the code.
* Fixed incorrect variable name on two places.
## v0.5 _(June 10, 2010)_
### Big Changes
* Syntax change: Use labeled expressions and variables instead of `$1`, `$2`, etc.
* Syntax change: Replaced `:` after a rule name with `=`.
* Syntax change: Allow trailing semicolon (`;`) for rules
* Semantic change: Start rule of the grammar is now implicitly its first rule.
* Implemented semantic predicates.
* Implemented initializers.
* Removed ability to change the start rule when generating the parser.
* Added several compiler optimizations — 0.5 is ~11% faster than 0.4 in the benchmark on V8.
### Small Changes
* `PEG.buildParser` now accepts grammars only in string format.
* Added “Generated by ...” message to the generated parsers.
* Formatted all grammars more consistently and transparently.
* Added notes about ECMA-262, 5th ed. compatibility to the JSON example grammar.
* Guarded against redefinition of `undefined`.
* Made `bin/pegjs` work when called via a symlink ([issue #1](https://github.com/dmajda/pegjs/issues/1)).
* Fixed bug causing incorrect error messages ([issue #2](https://github.com/dmajda/pegjs/issues/2)).
* Fixed error message for invalid character range.
* Fixed string literal parsing in the JavaScript grammar.
* Generated code improvements and fixes.
* Internal code improvements and fixes.
* Improved `README.md`.

@ -1,37 +0,0 @@
> See [commit history](https://github.com/pegjs/pegjs/compare/0.5.1...0.6.2) for a full list of changes.
## v0.6.2 _(April 20, 2011)_
### Small Changes
* Reset parser position when action returns `null`.
* Fixed typo in JavaScript example grammar.
## v0.6.1 _(April 14, 2011)_
### Small Changes
* Use `--ascii` option when generating a minified version.
## v0.6.0 _(April 14, 2011)_
### Big Changes
* Rewrote the command-line mode to be based on Node.js instead of Rhino — no more Java dependency. This also means that PEG.js is available as a Node.js package and can be required as a module.
* Version for the browser is built separately from the command-line one in two flavors (normal and minified).
* Parser variable name is no longer required argument of `bin/pegjs` — it is `module.exports` by default and can be set using the `-e`/`--export-var` option. This makes parsers generated by `/bin/pegjs` Node.js modules by default.
* Added ability to start parsing from any grammar rule.
* Added several compiler optimizations — 0.6 is ~12% faster than 0.5.1 in the benchmark on V8.
### Small Changes
* Split the source code into multiple files combined together using a build system.
* Jake is now used instead of Rake for build scripts — no more Ruby dependency.
* Test suite can be run from the command-line.
* Benchmark suite can be run from the command-line.
* Benchmark browser runner improvements (users can specify number of runs, benchmarks are run using `setTimeout`, table is centered and fixed-width).
* Added PEG.js version to “Generated by...” line in generated parsers.
* Added PEG.js version information and homepage header to `peg.js`.
* Generated code improvements and fixes.
* Internal code improvements and fixes.
* Rewrote `README.md`.

@ -1,36 +0,0 @@
> See [commit history](https://github.com/pegjs/pegjs/compare/0.6.2...v0.7.0) for a full list of changes.
## v0.7.0 _(April 18, 2012)_
### Big Changes
* Added ability to pass options to `PEG.buildParser`.
* Implemented the `trackLineAndColumn` option for `PEG.buildParser` (together with the `--track-line-and-column` command-line option). It makes the generated parser track line and column during parsing. These are made available inside actions and predicates as `line` and `column` variables.
* Implemented the `cache` option for `PEG.buildParser` (together with the `--cache` command-line option). This option enables/disables the results cache in generated parsers, resulting in dramatic speedup when the cache is disabled (the default now). The cost is breaking the linear parsing time guarantee.
* The current parse position is visible inside actions and predicates as the `offset` variable.
* Exceptions thrown by the parser have `offset`, `expected` and `found` properties containing machine-readable information about the parse failure (based on a patch by Marcin Stefaniuk).
* Semantic predicates have access to preceding labels. [[GH-69](https://github.com/dmajda/pegjs/issues/69)]
* Implemented case-insensitive literal and class matching. [[GH-34](https://github.com/dmajda/pegjs/issues/34)]
* Rewrote the code generator — split some computations into separate passes and based it on a proper templating system (Codie).
* Rewrote variable handling in generated parsers in a stack-like fashion, simplifying the code and making the parsers smaller and faster.
* Adapted to Node.js 0.6.6+ (no longer supported in older versions).
* Dropped support for IE < 8.
* As a result of several optimizations, parsers generated by 0.7.0 are ~6.4 times faster and ~19% smaller than those generated by 0.6.2 (as reported by `/tools/impact`).
### Small Changes
* Fixed reported error position when part of the input is not consumed. [[GH-48](https://github.com/dmajda/pegjs/issues/48)]
* Fixed incorrect disjunction operator in `computeErrorPosition` (original patch by Wolfgang Kluge).
* Fixed regexp for detecting command-line options in `/bin/pegjs`. [[GH-51](https://github.com/dmajda/pegjs/issues/51)]
* Generate more efficient code for empty literals (original patch by Wolfgang Kluge).
* Fixed comment typos (patches by Wolfgang Kluge and Jason Davies). [[GH-59](https://github.com/dmajda/pegjs/issues/59)]
* Fixed a typo in JavaScript example grammar. [[GH-62](https://github.com/dmajda/pegjs/issues/62)]
* Made copy & paste inclusion of the PEG.js library into another code easier by changing how the library is exported.
* Improved the copyright comment and the “Generated by...” header.
* Replaced `Jakefile` with `Makefile`.
* Added `make hint` task that checks all JavaScript files using JSHint and resolved all issues it reported. All JavaScript files and also generated parsers are JSHint-clean now.
* Fixed output printed during test failures (expected value was being printed instead of the actual one). Original patch by Wolfgang Kluge.
* Added a `/tools/impact` script to measure speed and size impact of commits.
* Various generated code improvements and fixes.
* Various internal code improvements and fixes.
* Improved `README.md`.

@ -1,38 +0,0 @@
> See [commit history](https://github.com/pegjs/pegjs/compare/v0.7.0...v0.8.0) for a full list of changes.
## v0.8.0 _(December 24, 2013)_
### Big Changes
* Completely rewrote the code generator. Among other things, it allows optimizing generated parsers for parsing speed or code size using the `optimize` option of the `PEG.buildParser` method or the `--optimize`/`-o` option on the command-line. All internal identifiers in generated code now also have a `peg$` prefix to discourage their use and avoid conflicts. [[#35](https://github.com/dmajda/pegjs/issues/35), [#92](https://github.com/dmajda/pegjs/issues/92)]
* Completely redesigned error handling. Instead of returning `null` inside actions to indicate match failure, new `expected` and `error` functions can be called to trigger an error. Also, expectation inside the `SyntaxError` exceptions are now structured to allow easier machine processing. [[#198](https://github.com/dmajda/pegjs/issues/198)]
* Implemented a plugin API. The list of plugins to use can be specified using the `plugins` option of the `PEG.buildParser` method or the `--plugin` option on the command-line. Also implemented the `--extra-options` and `--extra-options-file` command-line options, which are mainly useful to pass additional options to plugins. [[#106](https://github.com/dmajda/pegjs/issues/106)]
* Made `offset`, `line` and `column` functions, not variables. They are now available in all parsers and return lazily-computed position data. Removed now useless `trackLineAndColumn` option of the `PEG.buildParser` method and the `--track-line-and-column` option on the command-line.
* Added a new `text` function. When called inside an action, it returns the text matched by action's expression. [[#131](https://github.com/dmajda/pegjs/issues/131)]
* Added a new `$` operator. It extracts matched strings from expressions.
* The `?` operator now returns `null` on unsuccessful match.
* Predicates now always return `undefined`.
* Replaced the `startRule` parameter of the `parse` method in generated parsers with more generic `options` parameter. The start rule can now be specified as the `startRule` option. The `options` parameter can be also used to pass custom options to the parser because it is visible as the `options` variable inside parser code. [[#37](https://github.com/dmajda/pegjs/issues/37)]
* The list of allowed start rules of a generated parser now has to be specified explicitly using the `allowedStartRules` option of the `PEG.buildParser` method or the `--allowed-start-rule` option on the command-line. This will make certain optimizations like rule inlining easier in the future.
* Removed the `toSource` method of generated parsers and introduced a new `output` option of the `PEG.buildParser` method. It allows callers to specify whether they want to get back the parser object or its source code.
* The source code is now a valid npm package. This makes using development versions easier. [[#32](https://github.com/dmajda/pegjs/issues/32)]
* Generated parsers are now ~25% faster and ~62%/~3% smaller (when optimized for size/speed) than those generated by 0.7.0.
* Requires Node.js 0.8.0+.
### Small Changes
* `bin/pegjs` now outputs just the parser source if the value of the `--export-var` option is empty. This makes embedding generated parsers into other files easier. [[#143](https://github.com/dmajda/pegjs/issues/143)]
* Changed the value of the `name` property of `PEG.GrammarError` instances from “PEG.GrammarError” to just “GrammarError”. This better reflects the fact that PEG.js can get required with different variable name than `PEG`.
* Setup prototype chain for `PEG.GrammarError` correctly.
* Setup prototype chain for `SyntaxError` in generated parsers correctly.
* Fixed error messages in certain cases with trailing input [[#119](https://github.com/dmajda/pegjs/issues/119)]
* Fixed code generated for classes starting with `\^`. [[#125](https://github.com/dmajda/pegjs/issues/125)]
* Fixed too eager proxy rules removal. [[#137](https://github.com/dmajda/pegjs/issues/137)]
* Added a license to all vendored libraries. [[#207](https://github.com/dmajda/pegjs/issues/207)]
* Converted the test suite from QUnit to Jasmine, cleaning it up on the way.
* Travis CI integration.
* Various internal code improvements and fixes.
* Various generated code improvements and fixes.
* Various example grammar improvements and fixes.
* Improved `README.md`.
* Converted `CHANGELOG` to Markdown.

@ -1,29 +0,0 @@
> See [commit history](https://github.com/pegjs/pegjs/compare/v0.8.0...v0.9.0) for a full list of changes.
## v0.9.0 _(August 30, 2015)_
### Major Changes
* **Tracing support.** Parsers can be compiled with support for tracing their progress, which can help debugging complex grammars. This feature is experimental and is expected to evolve over time as experience is gained. [More details](https://github.com/pegjs/pegjs/commit/da57118a43a904f753d44d407994cf0b36358adc)
* **Infinite loop detection.** Grammar constructs that could cause infinite loops in generated parsers are detected during compilation and cause errors.
* **Improved location information API.** The `line`, `column`, and `offset` functions available in parser code were replaced by a single `location` function which returns an object describing the current location. Similarly, the `line`, `column`, and `offset` properties of exceptions were replaced by a single `location` property. The location is no longer a single point but a character range, which is meaningful mainly in actions where the range covers actions expression. [More details](https://github.com/pegjs/pegjs/compare/e75f21dc8f0e66b3d87c4c19b3fcb8f89d9c3acd...eaca5f0acf97b66ef141fed84aa95d4e72e33757)
* **Improved error reporting.** All exceptions thrown when generating a parser have associated location information. And all exceptions thrown by generated parser and PEG.js itself have a stack trace (the `stack` property) in environments that support `Error.captureStackTrace`.
* **Strict mode code**. All PEG.js and generated parser code is written using [JavaScript strict mode](https://developer.mozilla.org/cs/docs/Web/JavaScript/Reference/Strict_mode).
### Minor Changes
* Labels behave like block-scoped variables. This means parser code can see labels defined outside expressions containing code.
* Empty sequences are no longer allowed.
* Label names cant be JavaScript reserved words.
* Rule and label names can contain Unicode characters like in JavaScript.
* Rules have to be separated either by `;` or a newline (until now, any whitespace was enough).
* The PEG.js grammar and all the example grammars were completely rewritten. This rewrite included a number of cleanups, formatting changes, naming changes, and bug fixes.
* The parser object can now be accessed as `parser` in parser code.
* Location information computation is faster.
* Added support for Node.js >= 0.10.x, io.js, and Edge. Removed support for Node.js < 0.10.x.
### Bug Fixes
* Fixed left recursion detector which missed many cases.
* Fixed escaping of U+0100—U+107F and U+1000—U+107F in generated code and error messages.
* Renamed `parse` and `SyntaxError` to `peg$parse` and `peg$SyntaxError` to mark them as internal identifiers.

@ -1,10 +0,0 @@
## Compatibility
Both the parser generator and generated parsers should run well in the following environments:
* Node.js 8+
* Internet Explorer 11
* Microsoft Edge
* Firefox
* Chrome
* Opera

@ -1,32 +0,0 @@
PEG.js is currently maintained by [Futago-za Ryuu](https://github.com/futagoza) ([@futagozaryuu](https://twitter.com/futagozaryuu)).
Since it's [inception](https://www.google.com/search?q=inception+meaning) in 2010, PEG.js was maintained by [David Majda](https://majda.cz/) ([@dmajda](http://twitter.com/dmajda)), until [May 2017](https://github.com/pegjs/pegjs/issues/503).
::: warning
The [Bower package](https://github.com/pegjs/bower) (which was maintained by [Michel Krämer](http://www.michel-kraemer.com/) ([@michelkraemer](https://twitter.com/michelkraemer))) has been deprecated, and will no longer be updated.
:::
## Contribute
You are welcome to contribute code using [GitHub pull requests](https://github.com/pegjs/pegjs/pulls). Unless your contribution is really trivial you should get in touch with me first (preferably by creating a new issue on the [issue tracker](https://github.com/pegjs/pegjs/issues)) - this can prevent wasted effort on both sides.
> Before submitting a pull request, please make sure you've checked out the [Contribution Guidelines](https://github.com/pegjs/pegjs/blob/master/.github/CONTRIBUTING.md).
_Ensure you have Node.js 8.6+ and Yarn installed._
1. Create a fork of [https://github.com/pegjs/pegjs](https://github.com/pegjs/pegjs)
2. Clone your fork, and optionally create a new branch
3. Run the command `yarn install` from the root of your clone
4. Add and commit your changes
5. Validate your changes:
- Lint the JavaScript changes (command line only, run `yarn lint`)
- Run tests to ensure nothing's broken: `yarn test` from the root of the repository
- Run benchmarks to check performance: `yarn benchmark`
- Check the impact of your commits: [see separate documentation](https://github.com/pegjs/pegjs/blob/master/tools/impact/README.md)
6. If validation fails: reverse your commit, fix the problem and then add/commit again
7. Push the commits from your clone to the fork
8. From your fork, start a new pull request
It's also a good idea to check out the [package.json](https://github.com/pegjs/pegjs/blob/master/package.json) that defines various scripts.
To see the list of contributors check out the [repository's contributors page](https://github.com/pegjs/pegjs/graphs/contributors).

@ -1,72 +0,0 @@
## Grammar Syntax and Semantics
The grammar syntax is similar to JavaScript in that it is not line-oriented and ignores whitespace between tokens. You can also use JavaScript-style line comments (`// ...`) and block comments (`/* ... */`).
Let's look at an example grammar that recognizes simple arithmetic expressions like `2*(3+4)`. A parser generated from this grammar computes their values.
```pegjs
start
= additive
additive
= left:multiplicative "+" right:additive { return left + right; }
/ multiplicative
multiplicative
= left:primary "*" right:multiplicative { return left * right; }
/ primary
primary
= integer
/ "(" additive:additive ")" { return additive; }
integer "integer"
= digits:[0-9]+ { return parseInt(digits.join(""), 10); }
```
On the top level, the grammar consists of *rules* (in our example, there are five of them). Each rule has a *name* (e.g. `integer`) that identifies the rule, and a *parsing expression* (e.g. `digits:[0-9]+ { return parseInt(digits.join(""), 10); }`) that defines a pattern to match against the input text and possibly contains some JavaScript code that determines what happens when the pattern matches successfully. A rule can also contain a *human-readable name* that is used in error messages (in our example, only the `integer` rule has a human-readable name). The parsing starts at the first rule, which is also called the *start rule*.
A rule name must be a JavaScript identifier. It is followed by an equality sign (“=”) and a parsing expression. If the rule has a human-readable name, it is written as a JavaScript string between the name and separating equality sign. Rules need to be separated only by whitespace (their beginning is easily recognizable), but a semicolon (“;”) after the parsing expression is allowed.
The first rule can be preceded by an *initializer* - a piece of JavaScript code in curly braces (“{” and “}”). This code is executed before the generated parser starts parsing. All variables and functions defined in the initializer are accessible in rule actions and semantic predicates. The code inside the initializer can access options passed to the parser using the `options` variable. Curly braces in the initializer code must be [balanced](./balanced-braces.md).
Let's look at the example grammar from above using a simple initializer:
```pegjs
{
function makeInteger(o) {
return parseInt(o.join(""), 10);
}
}
start
= additive
additive
= left:multiplicative "+" right:additive { return left + right; }
/ multiplicative
multiplicative
= left:primary "*" right:multiplicative { return left * right; }
/ primary
primary
= integer
/ "(" additive:additive ")" { return additive; }
integer "integer"
= digits:[0-9]+ { return makeInteger(digits); }
```
The parsing expressions of the rules are used to match the input text to the grammar. There are various types of expressions — matching characters or character classes, indicating optional parts and repetition, etc. Expressions can also contain references to other rules. For a more detailed description, check out the [Parsing Expression Types](./parsing-expression-types.md) document.
If an expression successfully matches a part of the text when running the generated parser, it produces a *match result*, which is a JavaScript value. For example:
* An expression matching a literal string produces a JavaScript string containing matched text.
* An expression matching repeated occurrence of some subexpression produces a JavaScript array with all the matches.
The match results propagate through the rules when the rule names are used in expressions, up to the start rule. The generated parser returns start rule's match result when parsing is successful.
One special case of parser expression is a *parser action* - a piece of JavaScript code inside curly braces (“{” and “}”) that takes match results of some of the preceding expressions and returns a JavaScript value. This value is considered a match result of the preceding expression (in other words, the parser action is a match result transformer).
In our arithmetic's example, there are many parser actions. Consider the action in expression `digits:[0-9]+ { return parseInt(digits.join(""), 10); }`. It takes the match result of the expression [0-9]+, which is an array of strings containing digits, as its parameter. It joins the digits together to form a number and converts it to a JavaScript `number` object.

@ -1,49 +0,0 @@
### Action Execution Environment
Actions and predicates have these variables and functions available to them.
* All variables and functions defined in the initializer at the beginning of the grammar are available.
* Labels from preceding expressions are available as local variables, which will have the match result of the labelled expressions.
A label is only available after its labelled expression is matched:
```pegjs
rule = A:('a' B:'b' { /* B is available, A is not */ } )
```
A label in a sub-expression is only valid within the sub-expression:
```pegjs
rule = A:'a' (B: 'b') (C: 'b' { /* A and C are available, B is not */ })
```
* `options` is a variable that contains the parser options.
* `error(message, where)` will report an error and throw an exception. `where` is optional; the default is the value of `location()`.
* `expected(message, where)` is similar to `error`, but reports: Expected _message_ but "_other_" found
* `location()` returns an object like this:
```js
{
start: { offset: 23, line: 5, column: 6 },
end: { offset: 25, line: 5, column: 8 }
}
```
For actions, `start` refers to the position at the beginning of the preceding expression, and `end` refers to the position after the end of the preceding expression.
For predicates, `start` and `end` are the same, the location where the predicate is evaluated.
`offset` is a 0-based character index within the source text.
`line` and `column` are 1-based indices.
Note that `line` and `column` are somewhat expensive to compute, so if you need location frequently, you might want to use `offset()` or `range()` instead.
* `offset()` returns the start offset.
* `range()` returns an array containing the start and end offsets, such as `[23, 25]`.
* `text()` returns the source text between `start` and `end` (which will be "" for predicates).

@ -1,20 +0,0 @@
### Backtracking
Unlike in regular expressions, there is no backtracking in PEG.js expressions.
For example, using the input "hi!":
```pegjs
// This will fail
HI = "hi" / "hi!"
// This will pass
HI = "hi!" / "hi"
// This will also pass
HI = w:"hi" !"!" { return w } / "hi!"
```
For more information on backtracking in PEG.js, [checkout this excellent answer on Stack Overflow](https://stackoverflow.com/a/24809596/1518408).

@ -1,12 +0,0 @@
### Balanced Braces
Code fragments such as actions and predicates must have balanced curly braces, because PEG.js doesn't parse the contents. It only looks at balanced braces to find the end of the code fragment.
If your code fragment needs an unbalanced brace in a string literal, you can balance it in a comment. For example:
```pegjs
brace = [{}] {
return text() === "{" ? 1 : -1;
// } for balance
}
```

@ -1,13 +0,0 @@
### Case-insensitivity
Appending `i` right after either [a literal](./parsing-expression-types.md#literalliteral) or a [a character set](./parsing-expression-types.md#characters) makes the match case-insensitive. The rules shown in the following example all produce the same result:
```pegjs
// without `i`
a1 = "a" / "b" / "c" / "A" / "B" / "C"
b1 = [a-cA-C]
// with `i`
a2 = "a"i / "b"i / "c"i
b2 = [a-c]i
```

@ -1,42 +0,0 @@
### Error Messages
When parsing input with a generated parser, there are times when the parser will throw an error (on failure or when you call [expected()](./action-execution-environment.md) from one of the action blocks) with a message that contains a comma separated list of expressions that where expected or found. This is usually fine, but sometimes it is preferred to have a more human-readable name.
You can annotate your grammar rules with human-readable names that will be used in the error messages. For example, this:
```pegjs
integer "integer" = $[0-9]+
```
will produce an error message like:
> Expected integer but "a" found.
when parsing a non-number, referencing the human-readable name "integer."
Without the human-readable name, PEG.js instead uses a description of the expression that failed to match:
> Expected [0-9] but "a" found.
Aside from the text content of messages, human-readable names also have a subtler effect on *where* errors are reported. PEG.js prefers to match named rules completely or not at all, but not partially. Unnamed rules, on the other hand, can produce an error in the middle of their subexpressions.
For example, for this rule matching a comma-separated list of integers:
```pegjs
seq = integer ("," integer)*
```
an input like `1,2,a` produces this error message:
> Expected integer but "a" found.
But if we add a human-readable name to the `seq` production:
```pegjs
seq "list of numbers"
= integer ("," integer)*
```
then PEG.js prefers an error message that implies a smaller attempted parse tree:
> Expected end of input but "," found.

@ -1,136 +0,0 @@
### Parsing Expression Types
There are several types of parsing expressions, some of them containing subexpressions and thus forming a recursive structure:
* ["literal"](#literalliteral)
* [. (dot character)](#-dot-character)
* [[characters]](#characters)
* [rule](#rule)
* [( expression )](#-expression-)
* [expression *](#expression-)
* [expression +](#expression--1)
* [expression ?](#expression--2)
* [& expression](#-expression)
* [! expression](#-expression-1)
* [& { predicate }](#--predicate-)
* [! { predicate }](#--predicate--1)
* [$ expression](#-expression-2)
* [label : expression](#label--expression)
* [expression<sub>1</sub> expression<sub>2</sub> ... expression<sub>n</sub>](#expression1-expression2---expressionn)
* [expression { action }](#expression--action-)
* [expression<sub>1</sub> / expression<sub>2</sub> / ... / expression<sub>n</sub>](#expression1--expression2----expressionn)
* [expression<sub>1</sub> @expression<sub>2</sub> ... expression<sub>n</sub>](#expression1-expression2---expressionn-1)
#### "*literal*"<br>'*literal*'
Match exact literal string and return it. The string syntax is the same as in JavaScript.
Appending `i` right after the literal makes the match case-insensitive.
#### . *(dot character)*
Match exactly one character and return it as a string.
#### [*characters*]
Match one character from a set and return it as a string. The characters in the list can be escaped in exactly the same way they are escaped in JavaScript strings. The list of characters can also contain ranges (e.g. `[a-f]` means “any character between (and including) _a_ and _f_, all lowercase letters”).
Preceding the characters with `^` inverts the matched set (e.g. `[^a-z]` means “all character but lowercase letters”).
Appending `i` right after the right bracket makes the match case-insensitive.
#### *rule*
Match a parsing expression of a rule recursively and return its match result.
#### ( *expression* )
Match a subexpression and return its match result.
#### *expression* \*
Match zero or more repetitions of the expression and return their match results in an array. The matching is greedy, i.e. the parser tries to match the expression as many times as possible. Unlike in regular expressions, [there is no backtracking](./backtracking.md).
#### *expression* +
Match one or more repetitions of the expression and return their match results in an array. The matching is greedy, i.e. the parser tries to match the expression as many times as possible. Unlike in regular expressions, [there is no backtracking](./backtracking.md).
#### *expression* ?
Try to match the expression. If the match succeeds, return its match result, otherwise return `null`. Unlike in regular expressions, [there is no backtracking](./backtracking.md).
#### & *expression*
Try to match the expression. If the match succeeds, just return `undefined` and do not consume any input, otherwise consider the match failed.
#### ! *expression*
Try to match the expression. If the match does not succeed, just return `undefined` and do not consume any input, otherwise consider the match failed (the expression was matched, when it shouldn't have).
#### & { *predicate* }
This is a positive assertion. No input is consumed.
The predicate should be JavaScript code, and it's executed as a function. Curly braces in the predicate must be [balanced](./balanced-braces.md).
The predicate should `return` a boolean value. If the result is _truthy_, the match result is `undefined`, otherwise the match is considered failed.
The predicate has access to all variables and functions in the [Action Execution Environment](./action-execution-environment.md).
#### ! { *predicate* }
This is a negative assertion. No input is consumed.
The predicate should be JavaScript code, and it's executed as a function. Curly braces in the predicate must be [balanced](./balanced-braces.md).
The predicate should `return` a boolean value. If the result is _falsy_, the match result is `undefined`, otherwise the match is considered failed.
The predicate has access to all variables and functions in the [Action Execution Environment](./action-execution-environment.md).
#### $ *expression*
Try to match the expression. If the match succeeds, return the matched text instead of the match result.
#### *label* : *expression*
Match the expression and remember its match result under given label. The label must be a JavaScript identifier.
Labeled expressions are useful together with actions, where saved match results can be accessed by action's JavaScript code.
#### *expression<sub>1</sub>* *expression<sub>2</sub>* ... *expression<sub>n</sub>*
Match a sequence of expressions and return their match results in an array.
#### *expression* { *action* }
If the expression matches successfully, run the action, otherwise consider the match failed.
The action should be JavaScript code, and it's executed as a function. Curly braces in the action must be [balanced](./balanced-braces.md).
The action should `return` some value, which will be used as the match result of the expression.
The action has access to all variables and functions in the [Action Execution Environment](./action-execution-environment.md).
#### *expression<sub>1</sub>* / *expression<sub>2</sub>* / ... / *expression<sub>n</sub>*
Try to match the first expression, if it does not succeed, try the second one, etc. Return the match result of the first successfully matched expression. If no expression matches, consider the match failed.
#### *expression<sub>1</sub>* @*expression<sub>2</sub>* ... *expression<sub>n</sub>*
Only returns the expression(s) following `@`
> WARNING: You cannot use this on predicate's, and cannot use it alongside an action.
```js
start = MultiPluck
/ SinglePluck
SinglePluck = "0"? @integer
MultiPluck = @integer "." @integer
integer = $[0-9]+
```
When `SinglePluck` finds `011`, it returns `"11"`
When `MultiPluck` finds `0.11`, it returns `["0", "11"]`

@ -1,20 +0,0 @@
### tracer#trace()
Whether you are using the CLI or the API, as long as you pass the `trace` option, the generated parser can trace it's progress by calling `tracer.trace( event )`, which can then be overwritten by passing an alternative tracer in the options to the generated parser.
You can also optionally disable the default tracer by passing `features: { DefaultTracer: false }` to `peg.generate` or `peg.compiler.compile`, in which case a empty function will be called by default unless a tracer is passed to the parser.
The `event` passed to the `trace` method contains the following properties:
property | description
--- | ---
type | name of the event
rule | rule that this event was emitted from
result | the result of the match
location | location in the grammar when the event was emitted
The `type` property will only be 1 of 3 values:
1. `rule.enter` when entering a rule
2. `rule.match` when matching a rule was successful
3. `rule.fail` when matching a rule failed

@ -1,70 +0,0 @@
## Command Line
The CLI `pegjs` can be used from terminals to generate a parser from the given grammar, without accessing the PEG.js API.
It's usage signature is: `pegjs [options] [<input_file>] [--]`
### Configuration file
If you provide a configuration file (via `-c` or `--config`) then you can use all the options used by the [PEG.js API](./javascript-api.md), as well as:
* `input` — The grammar used as the input file
* `output` — Output's generated parser to the provided destination
> 1. Will throw if neither are strings, or the input has already been provided
> 2. the `output` option for the compiler is not usable from the config
### Input File
Only one grammar is accepted as the given input file, otherwise the CLI aborts with an error.
### Options and their values
Usually CLI options are passed like so
pegjs grammar.pegjs -o parser.js -c pegjs.config.js
With the PEG.js CLI, you can also use the assignment operator, so the above can be used like so:
pegjs grammar.pegjs -o=parser.js -c=pegjs.config.js
### Command Line Options
When using the CLI `pegjs`, you can pass the following 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
* `-c`, `--config` — file with additional options (in JSON or JavaScript) to pass to `peg.generate`
* `-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`
* `--extra-options-file` — same as `--config` (was the only cli option for config files before PEG.js v0.11)
* `-f`, `--format` — format of the generated parser: `amd`, `bare`, `commonjs`, `es`, `globals`, `umd` (default: `commonjs`)
* `--no-cache` — opposite of `--cache` (default behavior)
* `--no-trace` — opposite of `--trace` (default behavior)
* `-O`, `--optimize` — selects between optimizing the generated parser for parsing speed (`speed`) or code size (`size`) (default: `speed`)
* `-o`, `--output` — Output file
* `-p`, `--plugin` — makes PEG.js use a specified plugin (can be specified multiple times)
* `--trace` — makes the parser trace its progress
The following options only print to the console before exiting:
* `-h`, `--help` — Print help and exit
* `-v`, `--version` — Print version information and exit
### Repeatable and non-repeatable options
Repeatable options on the cli are handled by pushing the values into a list (which is used as the value for the option):
- `pegjs -a start,Rule -a Rule,Template` will set `options.allowedStartRules` to `[ "start", "Rule", "Template" ]`
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`
### Extra options
Need to pass a custom set of arguments to your plugin? The PEG.js CLI will pass all arguments after `--` to `options["--"]`, which is passed to all plugins.
> NOTE: You will need to use your own argument parser, as the PEG.js CLI does not process these arguments.

@ -1,27 +0,0 @@
## Generating a Parser
PEG.js generates a parser from grammar that describes expected input and can specify what the parser returns (using semantic actions on matched parts of the input). The 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 files, the standard input and output are used (REPL mode).
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](./command-line.md).
### Module
To generate a parser using the module, take a look at the section about the method `peg.generate()` described in the [JavaScript API documentation](./javascript-api.md). This method is the API alternative to the command line tool as it does everything for it, the command line tool just takes care of validating and handling input, output and options.

@ -1,10 +0,0 @@
## Getting Started
The [online editor](https://pegjs.org/online) is the easiest way to generate a parser. Just enter your grammar, try parsing some input, and download the generated parser code.
If you want a more flexible way to generate a parser, check out the following:
- [Installing PEG.js](./installation.md)
- [Generating a Parser](./generating-a-parser.md)
- [JavaScript API](./javascript-api.md)
- [Plugins](./plugins.md)

@ -1,41 +0,0 @@
## 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.
If you plan to use the `pegjs` command only in your `package.json`, it is suggested you install it locally only, as all locally installed packages that contain command line tools are available to it.
### Browser
[Download](https://pegjs.org/#download) the PEG.js library (regular or minified version) or use it directly using UNPKG:
```html
<script src="https://unpkg.com/pegjs/dist/peg.min.js"></script>
```
### Latest
To use the latest features, fixes and changes of PEG.js, install the packaged dev release:
```console
$ npm install pegjs@dev
```
On the browser you can use UNPKG again:
```html
<script src="https://unpkg.com/pegjs@dev/dist/peg.min.js"></script>
```

@ -1,135 +0,0 @@
## JavaScript API
In Node.js, require the PEG.js module:
```js
// ES2015+ Module System
import peg from "pegjs";
// CommonJS
var peg = require("pegjs");
```
In browsers, include the PEG.js library in your web page or application using the `<script>` tag. If PEG.js detects an AMD loader, it will define itself as a module, otherwise the API will be available in the `peg` global object.
After this there are 3 methods and 1 class that you will mainly use:
```js
var grammar = "start = ('a' / 'b')+";
// Parse grammar, generating AST
var ast = peg.parser.parse(grammar);
// Create a new compiler session
var session = new peg.compiler.Session( { warn: customLogger } );
// Generate parser from PEG.js AST using an exisiting session
var parserA = peg.compiler.compile(ast, session);
// Generate parser from the grammar source using a new session
var parserB = peg.generate(grammar);
```
The most common method you will use is `peg.generate()`, which is the API alternative to the [PEG.js CLI](./generating-a-parser.md). More about each method is explained below, along with their respective options.
#### peg.parser.parse(input[, options])
You can simply parse a grammar and get it's AST by using the parser:
```js
var ast = peg.parser.parse("start = ('a' / 'b')+");
```
The following option's are used by the PEG.js parser:
* `extractComments` - If `true`, the parser will collect all comments in the grammar (default: `false`).
* `reservedWords` - An array of words that the parser wont allow as labels for rules (default: [ES5](http://es5.github.io/#x7.6.1)).
When `extractComments` is set to `true`, the parser will collect all comments in the grammar and return them on the `comments` property (as an object map) on the `grammar` AST node (the AST directly returned by the parser). Each comment property has it's offset as the property key, while the property value has the following structure:
```js
{
text: 'all text between /* or */, or // and end of line',
multiline: true|false,
location: location()
}
```
When set to `false`, the `comments` property will be set to `null`.
For more information about `location()`, as well more methods you can use in JavaScript actions within your grammar, see the helper's description in [Action Execution Environment](../grammar/action-execution-environment.md).
#### new peg.compiler.Session([options])
An instance of this class holds helpers (methods, objects with methods, constants, etc) that are shared between multiple calls to `peg.compiler.compile()`.
> This approach is used rather then a traditional compiler class because it provides the plugin developer with an easier way to replace certain components rather then creating their own version of PEG.js to override one or more internal methods.
The following option's are used by the Session API, but are currently all optional:
* `opcodes` - An `enum` like hashmap (plain object) that is used by the bytecode and parser generators.
* `parser` - A pre-generated PEG.js grammar parser that should return an instance of the PEG.js AST's Grammar class. Can be replaced to add additional syntax features, or allow an alternative syntax for the grammar.
* `passes` - An object with each property being an array of methods that will check or alter the AST passed to them.
* `visitor` - An object that should contain the `ASTVisitor` class for the PEG.js AST, as well as the `build()` helper.
* `vm` - An object that should contain `evalModule()`, a wrapper for `eval` based on Node's `vm.runInContext()` method.
* `warn` - A method called only when PEG.js encounters an error that doesn't stop the parser from being generated.
* `error` - A method that will be called when PEG.js encounters an error that will stop the parser from being generated.
This class will also return some helper methods:
* `parse( input, options )` - an alias for `this.parser.parse( input, options )`
* `buildVisitor( functions )` - an alias for `this.visitor.build( functions )`
* `fatal( message, location )` - Will always throw an error (used by default for `this.error()` if not overridden).
#### peg.compiler.compile(ast, session[, options])
This method takes a parsed grammar (the PEG.js AST), sets default options, executes each pass currently within the session (passing the _ast_, _session_ and _options_ arguments to each one), then returns the result, which depends on the value of the `output` option.
```js
var grammar = "start = ('a' / 'b')+";
var ast = peg.parser.parse(grammar);
var passes = peg.util.convertPasses( peg.compiler.passes );
var session = new peg.compiler.Session( { passes } );
var parser = peg.compiler.compile(ast, session);
```
You can tweak the generated parser by passing a third parameter with an options object. The following options are supported:
Option | default value | description
--- | --- | ---
allowedStartRules | first rule | rules the generated parser is allowed to start parsing from
cache | `false` | makes the generated parser cache results, avoiding exponential parsing time in pathological cases but making the parser slower
context | `{}` | contains a map of variables used by `peg.util.vm.evalModule()` when the `output` option is set to `"parser"`
dependencies<sub>1</sub> | `{}` | parser dependencies, the value is an object which maps variables used to access the dependencies to module IDs used to load them
exportVar<sub>2</sub> | `null` | name of an optional global variable into which the generated parser object is assigned to when no module loader is detected
features | `null` | map of optional features that are set to `true` by default: `"text"`, `"offset"`, `"range"`, `"location"`, `"expected"`, `"error"`, `"filename"` and `"DefaultTracer"`
format<sub>3</sub> | `"bare"` | format of the generated parser (`"amd"`, `"bare"`, `"commonjs"`, `"es"`, `"globals"`, or `"umd"`)
header | `null` | adds additional comments or content after the `Generated by ...` comment; this option is only handled if it's an array or a string:
optimize | `"speed"` | selects between optimizing the generated parser for parsing speed (`"speed"`) or code size (`"size"`)
output | `"parser"` | if set to `"parser"`, the method will return generated parser object; if set to `"source"`, it will return generated parser source code as a string
trace | `false` | makes the generated parser trace its progress
1. The `dependencies` option is only used when `format` is set to `"amd"`, `"commonjs"`, `"es"`, or `"umd"`
2. The `exportVar` option is only used when `format` is set to `"globals"` or `"umd"`
3. The `format` option is is always set to `"umd"` when `output` is set to `"parser"`
The `header` options behavior will change depending on the option type:
* `[ string1, string2, ... ]` will add each element (all expected to be strings) as a separate line comment
* `string` will simply append the string (e.g. `"/* eslint-disable */"`) after the `Generated by ...` comment
#### peg.generate(grammar[, options])
Will generate a parser from the given grammar (the _input_ passed to `peg.parser.parse()`):
```js
var parser = peg.generate("start = ('a' / 'b')+");
```
This method will return a generated parser object or its source code as a string (depending on the value of the `output` option - see above). It will throw an exception if the grammar is invalid. The exception will contain the usual `message` property with more details about the error, along with a `location` property to track the location of the error. You can easily tell if the exception was thrown by PEG.js because it will always have the `name` property set to `GrammarError`.
You can tweak the generated parser by passing a second parameter with an options object to `peg.generate()`. The following options are supported:
* All options that you pass to `peg.compiler.compile()`
* `parser` - an optional object with option's passed to the PEG.js parser (`peg.parser.parse()`)
* `plugins` - plugins to use _(their `use()` method is executed by `peg.generate()`)_

@ -1,34 +0,0 @@
## Plugins
You can use plugins by simply passing them to the generate method (e.g. [`peg.generate(grammar, { plugins: [plugin1, plugin2, etc] })`](./javascript-api.md#peggenerategrammar-options)).
#### Creating a Plugin
Plugins are expected to be an object that contains at least one method: `use( session, options )`
- `session` - See the docs for [peg.compiler.Session](./javascript-api.md#new-pegcompilersessionoptions)
- `options` - see the docs for [`peg.generate`](./javascript-api.md#peggenerategrammar-options) and [`peg.compiler.compile`](./javascript-api.md#pegcompilercompileast-session-options)
Here is a simple example:
```js
import customGrammarParser from "./parser";
export function use( session, options ) {
// Replace the grammar parser
session.parser = customGrammarParser;
// always output the source
options.output = "source";
}
```
#### Resources
You can find some plugins to use on
- the [PEG.js wiki](https://github.com/pegjs/pegjs/wiki/Plugins) (or add yours to the list for other's to find)
- NPM: https://www.npmjs.com/browse/keyword/pegjs

@ -1,19 +0,0 @@
## Using the Parser
> parser { DefaultTracer?, SyntaxError, parse(input[, options]) }
Using the generated parser is simple; just call its `parse` method and pass an input string as a parameter. The method will return a parse result (the exact value depends on the grammar used to generate the parser) or throw an exception if the input is invalid. The exception will contain `location`, `expected`, `found`, and `message` properties with more details about the error.
```js
parser.parse("abba"); // returns ["a", "b", "b", "a"]
parser.parse("abcd"); // throws an exception
```
You can tweak parser behavior by passing a second parameter with an `options` object to the `parse` method. The following options are supported:
* `filename` — the name of the source passed to the generated parser; will be used by the `location()` helper
* `startRule` — name of the rule to start parsing from (depends on the rules the grammar supports as starting rules)
* `tracer` — tracer to use (only if the parser was generated with `"trace": true` option passed to the compiler)
Parsers can also support their own custom options on the `options` object passed to them.

@ -4,27 +4,27 @@
// Accepts expressions like "2 * (3 + 4)" and computes their value.
Expression
= head:Term tail:(_ @("+" / "-") _ @Term)* {
= head:Term tail:(_ ("+" / "-") _ Term)* {
return tail.reduce(function(result, element) {
if (element[0] === "+") return result + element[1];
if (element[0] === "-") return result - element[1];
if (element[1] === "+") { return result + element[3]; }
if (element[1] === "-") { return result - element[3]; }
}, head);
}
Term
= head:Factor tail:(_ @("*" / "/") _ @Factor)* {
= head:Factor tail:(_ ("*" / "/") _ Factor)* {
return tail.reduce(function(result, element) {
if (element[0] === "*") return result * element[1];
if (element[0] === "/") return result / element[1];
if (element[1] === "*") { return result * element[3]; }
if (element[1] === "/") { return result / element[3]; }
}, head);
}
Factor
= "(" _ @Expression _ ")"
= "(" _ expr:Expression _ ")" { return expr; }
/ Integer
Integer "integer"
= _ [0-9]+ { return parseInt(text(), 10); }
= [0-9]+ { return parseInt(text(), 10); }
_ "whitespace"
= [ \t\n\r]*

@ -292,7 +292,7 @@ name
= chars:nmchar+ { return chars.join(""); }
num
= [+-]? ([0-9]* "." [0-9]+ / [0-9]+) ("e" [+-]? [0-9]+)? {
= [+-]? ([0-9]+ / [0-9]* "." [0-9]+) ("e" [+-]? [0-9]+)? {
return parseFloat(text());
}

@ -375,7 +375,7 @@ RegularExpressionFlags
//
// Extracted from the following Unicode Character Database file:
//
// http://www.unicode.org/Public/11.0.0/ucd/extracted/DerivedGeneralCategory.txt
// http://www.unicode.org/Public/8.0.0/ucd/extracted/DerivedGeneralCategory.txt
//
// Unix magic used:
//
@ -395,25 +395,25 @@ RegularExpressionFlags
// even parsers in JavaScript engines of common browsers seem to ignore them.
// Letter, Lowercase
Ll = [\u0061-\u007A\u00B5\u00DF-\u00F6\u00F8-\u00FF\u0101\u0103\u0105\u0107\u0109\u010B\u010D\u010F\u0111\u0113\u0115\u0117\u0119\u011B\u011D\u011F\u0121\u0123\u0125\u0127\u0129\u012B\u012D\u012F\u0131\u0133\u0135\u0137-\u0138\u013A\u013C\u013E\u0140\u0142\u0144\u0146\u0148-\u0149\u014B\u014D\u014F\u0151\u0153\u0155\u0157\u0159\u015B\u015D\u015F\u0161\u0163\u0165\u0167\u0169\u016B\u016D\u016F\u0171\u0173\u0175\u0177\u017A\u017C\u017E-\u0180\u0183\u0185\u0188\u018C-\u018D\u0192\u0195\u0199-\u019B\u019E\u01A1\u01A3\u01A5\u01A8\u01AA-\u01AB\u01AD\u01B0\u01B4\u01B6\u01B9-\u01BA\u01BD-\u01BF\u01C6\u01C9\u01CC\u01CE\u01D0\u01D2\u01D4\u01D6\u01D8\u01DA\u01DC-\u01DD\u01DF\u01E1\u01E3\u01E5\u01E7\u01E9\u01EB\u01ED\u01EF-\u01F0\u01F3\u01F5\u01F9\u01FB\u01FD\u01FF\u0201\u0203\u0205\u0207\u0209\u020B\u020D\u020F\u0211\u0213\u0215\u0217\u0219\u021B\u021D\u021F\u0221\u0223\u0225\u0227\u0229\u022B\u022D\u022F\u0231\u0233-\u0239\u023C\u023F-\u0240\u0242\u0247\u0249\u024B\u024D\u024F-\u0293\u0295-\u02AF\u0371\u0373\u0377\u037B-\u037D\u0390\u03AC-\u03CE\u03D0-\u03D1\u03D5-\u03D7\u03D9\u03DB\u03DD\u03DF\u03E1\u03E3\u03E5\u03E7\u03E9\u03EB\u03ED\u03EF-\u03F3\u03F5\u03F8\u03FB-\u03FC\u0430-\u045F\u0461\u0463\u0465\u0467\u0469\u046B\u046D\u046F\u0471\u0473\u0475\u0477\u0479\u047B\u047D\u047F\u0481\u048B\u048D\u048F\u0491\u0493\u0495\u0497\u0499\u049B\u049D\u049F\u04A1\u04A3\u04A5\u04A7\u04A9\u04AB\u04AD\u04AF\u04B1\u04B3\u04B5\u04B7\u04B9\u04BB\u04BD\u04BF\u04C2\u04C4\u04C6\u04C8\u04CA\u04CC\u04CE-\u04CF\u04D1\u04D3\u04D5\u04D7\u04D9\u04DB\u04DD\u04DF\u04E1\u04E3\u04E5\u04E7\u04E9\u04EB\u04ED\u04EF\u04F1\u04F3\u04F5\u04F7\u04F9\u04FB\u04FD\u04FF\u0501\u0503\u0505\u0507\u0509\u050B\u050D\u050F\u0511\u0513\u0515\u0517\u0519\u051B\u051D\u051F\u0521\u0523\u0525\u0527\u0529\u052B\u052D\u052F\u0560-\u0588\u10D0-\u10FA\u10FD-\u10FF\u13F8-\u13FD\u1C80-\u1C88\u1D00-\u1D2B\u1D6B-\u1D77\u1D79-\u1D9A\u1E01\u1E03\u1E05\u1E07\u1E09\u1E0B\u1E0D\u1E0F\u1E11\u1E13\u1E15\u1E17\u1E19\u1E1B\u1E1D\u1E1F\u1E21\u1E23\u1E25\u1E27\u1E29\u1E2B\u1E2D\u1E2F\u1E31\u1E33\u1E35\u1E37\u1E39\u1E3B\u1E3D\u1E3F\u1E41\u1E43\u1E45\u1E47\u1E49\u1E4B\u1E4D\u1E4F\u1E51\u1E53\u1E55\u1E57\u1E59\u1E5B\u1E5D\u1E5F\u1E61\u1E63\u1E65\u1E67\u1E69\u1E6B\u1E6D\u1E6F\u1E71\u1E73\u1E75\u1E77\u1E79\u1E7B\u1E7D\u1E7F\u1E81\u1E83\u1E85\u1E87\u1E89\u1E8B\u1E8D\u1E8F\u1E91\u1E93\u1E95-\u1E9D\u1E9F\u1EA1\u1EA3\u1EA5\u1EA7\u1EA9\u1EAB\u1EAD\u1EAF\u1EB1\u1EB3\u1EB5\u1EB7\u1EB9\u1EBB\u1EBD\u1EBF\u1EC1\u1EC3\u1EC5\u1EC7\u1EC9\u1ECB\u1ECD\u1ECF\u1ED1\u1ED3\u1ED5\u1ED7\u1ED9\u1EDB\u1EDD\u1EDF\u1EE1\u1EE3\u1EE5\u1EE7\u1EE9\u1EEB\u1EED\u1EEF\u1EF1\u1EF3\u1EF5\u1EF7\u1EF9\u1EFB\u1EFD\u1EFF-\u1F07\u1F10-\u1F15\u1F20-\u1F27\u1F30-\u1F37\u1F40-\u1F45\u1F50-\u1F57\u1F60-\u1F67\u1F70-\u1F7D\u1F80-\u1F87\u1F90-\u1F97\u1FA0-\u1FA7\u1FB0-\u1FB4\u1FB6-\u1FB7\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FC7\u1FD0-\u1FD3\u1FD6-\u1FD7\u1FE0-\u1FE7\u1FF2-\u1FF4\u1FF6-\u1FF7\u210A\u210E-\u210F\u2113\u212F\u2134\u2139\u213C-\u213D\u2146-\u2149\u214E\u2184\u2C30-\u2C5E\u2C61\u2C65-\u2C66\u2C68\u2C6A\u2C6C\u2C71\u2C73-\u2C74\u2C76-\u2C7B\u2C81\u2C83\u2C85\u2C87\u2C89\u2C8B\u2C8D\u2C8F\u2C91\u2C93\u2C95\u2C97\u2C99\u2C9B\u2C9D\u2C9F\u2CA1\u2CA3\u2CA5\u2CA7\u2CA9\u2CAB\u2CAD\u2CAF\u2CB1\u2CB3\u2CB5\u2CB7\u2CB9\u2CBB\u2CBD\u2CBF\u2CC1\u2CC3\u2CC5\u2CC7\u2CC9\u2CCB\u2CCD\u2CCF\u2CD1\u2CD3\u2CD5\u2CD7\u2CD9\u2CDB\u2CDD\u2CDF\u2CE1\u2CE3-\u2CE4\u2CEC\u2CEE\u2CF3\u2D00-\u2D25\u2D27\u2D2D\uA641\uA643\uA645\uA647\uA649\uA64B\uA64D\uA64F\uA651\uA653\uA655\uA657\uA659\uA65B\uA65D\uA65F\uA661\uA663\uA665\uA667\uA669\uA66B\uA66D\uA681\uA683\uA685\uA687\uA689\uA68B\uA68D\uA68F\uA691\uA693\uA695\uA697\uA699\uA69B\uA723\uA725\uA727\uA729\uA72B\uA72D\uA72F-\uA731\uA733\uA735\uA737\uA739\uA73B\uA73D\uA73F\uA741\uA743\uA745\uA747\uA749\uA74B\uA74D\uA74F\uA751\uA753\uA755\uA757\uA759\uA75B\uA75D\uA75F\uA761\uA763\uA765\uA767\uA769\uA76B\uA76D\uA76F\uA771-\uA778\uA77A\uA77C\uA77F\uA781\uA783\uA785\uA787\uA78C\uA78E\uA791\uA793-\uA795\uA797\uA799\uA79B\uA79D\uA79F\uA7A1\uA7A3\uA7A5\uA7A7\uA7A9\uA7AF\uA7B5\uA7B7\uA7B9\uA7FA\uAB30-\uAB5A\uAB60-\uAB65\uAB70-\uABBF\uFB00-\uFB06\uFB13-\uFB17\uFF41-\uFF5A]
Ll = [\u0061-\u007A\u00B5\u00DF-\u00F6\u00F8-\u00FF\u0101\u0103\u0105\u0107\u0109\u010B\u010D\u010F\u0111\u0113\u0115\u0117\u0119\u011B\u011D\u011F\u0121\u0123\u0125\u0127\u0129\u012B\u012D\u012F\u0131\u0133\u0135\u0137-\u0138\u013A\u013C\u013E\u0140\u0142\u0144\u0146\u0148-\u0149\u014B\u014D\u014F\u0151\u0153\u0155\u0157\u0159\u015B\u015D\u015F\u0161\u0163\u0165\u0167\u0169\u016B\u016D\u016F\u0171\u0173\u0175\u0177\u017A\u017C\u017E-\u0180\u0183\u0185\u0188\u018C-\u018D\u0192\u0195\u0199-\u019B\u019E\u01A1\u01A3\u01A5\u01A8\u01AA-\u01AB\u01AD\u01B0\u01B4\u01B6\u01B9-\u01BA\u01BD-\u01BF\u01C6\u01C9\u01CC\u01CE\u01D0\u01D2\u01D4\u01D6\u01D8\u01DA\u01DC-\u01DD\u01DF\u01E1\u01E3\u01E5\u01E7\u01E9\u01EB\u01ED\u01EF-\u01F0\u01F3\u01F5\u01F9\u01FB\u01FD\u01FF\u0201\u0203\u0205\u0207\u0209\u020B\u020D\u020F\u0211\u0213\u0215\u0217\u0219\u021B\u021D\u021F\u0221\u0223\u0225\u0227\u0229\u022B\u022D\u022F\u0231\u0233-\u0239\u023C\u023F-\u0240\u0242\u0247\u0249\u024B\u024D\u024F-\u0293\u0295-\u02AF\u0371\u0373\u0377\u037B-\u037D\u0390\u03AC-\u03CE\u03D0-\u03D1\u03D5-\u03D7\u03D9\u03DB\u03DD\u03DF\u03E1\u03E3\u03E5\u03E7\u03E9\u03EB\u03ED\u03EF-\u03F3\u03F5\u03F8\u03FB-\u03FC\u0430-\u045F\u0461\u0463\u0465\u0467\u0469\u046B\u046D\u046F\u0471\u0473\u0475\u0477\u0479\u047B\u047D\u047F\u0481\u048B\u048D\u048F\u0491\u0493\u0495\u0497\u0499\u049B\u049D\u049F\u04A1\u04A3\u04A5\u04A7\u04A9\u04AB\u04AD\u04AF\u04B1\u04B3\u04B5\u04B7\u04B9\u04BB\u04BD\u04BF\u04C2\u04C4\u04C6\u04C8\u04CA\u04CC\u04CE-\u04CF\u04D1\u04D3\u04D5\u04D7\u04D9\u04DB\u04DD\u04DF\u04E1\u04E3\u04E5\u04E7\u04E9\u04EB\u04ED\u04EF\u04F1\u04F3\u04F5\u04F7\u04F9\u04FB\u04FD\u04FF\u0501\u0503\u0505\u0507\u0509\u050B\u050D\u050F\u0511\u0513\u0515\u0517\u0519\u051B\u051D\u051F\u0521\u0523\u0525\u0527\u0529\u052B\u052D\u052F\u0561-\u0587\u13F8-\u13FD\u1D00-\u1D2B\u1D6B-\u1D77\u1D79-\u1D9A\u1E01\u1E03\u1E05\u1E07\u1E09\u1E0B\u1E0D\u1E0F\u1E11\u1E13\u1E15\u1E17\u1E19\u1E1B\u1E1D\u1E1F\u1E21\u1E23\u1E25\u1E27\u1E29\u1E2B\u1E2D\u1E2F\u1E31\u1E33\u1E35\u1E37\u1E39\u1E3B\u1E3D\u1E3F\u1E41\u1E43\u1E45\u1E47\u1E49\u1E4B\u1E4D\u1E4F\u1E51\u1E53\u1E55\u1E57\u1E59\u1E5B\u1E5D\u1E5F\u1E61\u1E63\u1E65\u1E67\u1E69\u1E6B\u1E6D\u1E6F\u1E71\u1E73\u1E75\u1E77\u1E79\u1E7B\u1E7D\u1E7F\u1E81\u1E83\u1E85\u1E87\u1E89\u1E8B\u1E8D\u1E8F\u1E91\u1E93\u1E95-\u1E9D\u1E9F\u1EA1\u1EA3\u1EA5\u1EA7\u1EA9\u1EAB\u1EAD\u1EAF\u1EB1\u1EB3\u1EB5\u1EB7\u1EB9\u1EBB\u1EBD\u1EBF\u1EC1\u1EC3\u1EC5\u1EC7\u1EC9\u1ECB\u1ECD\u1ECF\u1ED1\u1ED3\u1ED5\u1ED7\u1ED9\u1EDB\u1EDD\u1EDF\u1EE1\u1EE3\u1EE5\u1EE7\u1EE9\u1EEB\u1EED\u1EEF\u1EF1\u1EF3\u1EF5\u1EF7\u1EF9\u1EFB\u1EFD\u1EFF-\u1F07\u1F10-\u1F15\u1F20-\u1F27\u1F30-\u1F37\u1F40-\u1F45\u1F50-\u1F57\u1F60-\u1F67\u1F70-\u1F7D\u1F80-\u1F87\u1F90-\u1F97\u1FA0-\u1FA7\u1FB0-\u1FB4\u1FB6-\u1FB7\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FC7\u1FD0-\u1FD3\u1FD6-\u1FD7\u1FE0-\u1FE7\u1FF2-\u1FF4\u1FF6-\u1FF7\u210A\u210E-\u210F\u2113\u212F\u2134\u2139\u213C-\u213D\u2146-\u2149\u214E\u2184\u2C30-\u2C5E\u2C61\u2C65-\u2C66\u2C68\u2C6A\u2C6C\u2C71\u2C73-\u2C74\u2C76-\u2C7B\u2C81\u2C83\u2C85\u2C87\u2C89\u2C8B\u2C8D\u2C8F\u2C91\u2C93\u2C95\u2C97\u2C99\u2C9B\u2C9D\u2C9F\u2CA1\u2CA3\u2CA5\u2CA7\u2CA9\u2CAB\u2CAD\u2CAF\u2CB1\u2CB3\u2CB5\u2CB7\u2CB9\u2CBB\u2CBD\u2CBF\u2CC1\u2CC3\u2CC5\u2CC7\u2CC9\u2CCB\u2CCD\u2CCF\u2CD1\u2CD3\u2CD5\u2CD7\u2CD9\u2CDB\u2CDD\u2CDF\u2CE1\u2CE3-\u2CE4\u2CEC\u2CEE\u2CF3\u2D00-\u2D25\u2D27\u2D2D\uA641\uA643\uA645\uA647\uA649\uA64B\uA64D\uA64F\uA651\uA653\uA655\uA657\uA659\uA65B\uA65D\uA65F\uA661\uA663\uA665\uA667\uA669\uA66B\uA66D\uA681\uA683\uA685\uA687\uA689\uA68B\uA68D\uA68F\uA691\uA693\uA695\uA697\uA699\uA69B\uA723\uA725\uA727\uA729\uA72B\uA72D\uA72F-\uA731\uA733\uA735\uA737\uA739\uA73B\uA73D\uA73F\uA741\uA743\uA745\uA747\uA749\uA74B\uA74D\uA74F\uA751\uA753\uA755\uA757\uA759\uA75B\uA75D\uA75F\uA761\uA763\uA765\uA767\uA769\uA76B\uA76D\uA76F\uA771-\uA778\uA77A\uA77C\uA77F\uA781\uA783\uA785\uA787\uA78C\uA78E\uA791\uA793-\uA795\uA797\uA799\uA79B\uA79D\uA79F\uA7A1\uA7A3\uA7A5\uA7A7\uA7A9\uA7B5\uA7B7\uA7FA\uAB30-\uAB5A\uAB60-\uAB65\uAB70-\uABBF\uFB00-\uFB06\uFB13-\uFB17\uFF41-\uFF5A]
// Letter, Modifier
Lm = [\u02B0-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0374\u037A\u0559\u0640\u06E5-\u06E6\u07F4-\u07F5\u07FA\u081A\u0824\u0828\u0971\u0E46\u0EC6\u10FC\u17D7\u1843\u1AA7\u1C78-\u1C7D\u1D2C-\u1D6A\u1D78\u1D9B-\u1DBF\u2071\u207F\u2090-\u209C\u2C7C-\u2C7D\u2D6F\u2E2F\u3005\u3031-\u3035\u303B\u309D-\u309E\u30FC-\u30FE\uA015\uA4F8-\uA4FD\uA60C\uA67F\uA69C-\uA69D\uA717-\uA71F\uA770\uA788\uA7F8-\uA7F9\uA9CF\uA9E6\uAA70\uAADD\uAAF3-\uAAF4\uAB5C-\uAB5F\uFF70\uFF9E-\uFF9F]
// Letter, Other
Lo = [\u00AA\u00BA\u01BB\u01C0-\u01C3\u0294\u05D0-\u05EA\u05EF-\u05F2\u0620-\u063F\u0641-\u064A\u066E-\u066F\u0671-\u06D3\u06D5\u06EE-\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u0800-\u0815\u0840-\u0858\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0972-\u0980\u0985-\u098C\u098F-\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC-\u09DD\u09DF-\u09E1\u09F0-\u09F1\u09FC\u0A05-\u0A0A\u0A0F-\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32-\u0A33\u0A35-\u0A36\u0A38-\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2-\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0-\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F-\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32-\u0B33\u0B35-\u0B39\u0B3D\u0B5C-\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99-\u0B9A\u0B9C\u0B9E-\u0B9F\u0BA3-\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60-\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0-\u0CE1\u0CF1-\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32-\u0E33\u0E40-\u0E45\u0E81-\u0E82\u0E84\u0E87-\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA-\u0EAB\u0EAD-\u0EB0\u0EB2-\u0EB3\u0EBD\u0EC0-\u0EC4\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065-\u1066\u106E-\u1070\u1075-\u1081\u108E\u1100-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17DC\u1820-\u1842\u1844-\u1878\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE-\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C77\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5-\u1CF6\u2135-\u2138\u2D30-\u2D67\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3006\u303C\u3041-\u3096\u309F\u30A1-\u30FA\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEF\uA000-\uA014\uA016-\uA48C\uA4D0-\uA4F7\uA500-\uA60B\uA610-\uA61F\uA62A-\uA62B\uA66E\uA6A0-\uA6E5\uA78F\uA7F7\uA7FB-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD-\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9E0-\uA9E4\uA9E7-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA6F\uAA71-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5-\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADC\uAAE0-\uAAEA\uAAF2\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40-\uFB41\uFB43-\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF66-\uFF6F\uFF71-\uFF9D\uFFA0-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]
Lo = [\u00AA\u00BA\u01BB\u01C0-\u01C3\u0294\u05D0-\u05EA\u05F0-\u05F2\u0620-\u063F\u0641-\u064A\u066E-\u066F\u0671-\u06D3\u06D5\u06EE-\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u0800-\u0815\u0840-\u0858\u08A0-\u08B4\u0904-\u0939\u093D\u0950\u0958-\u0961\u0972-\u0980\u0985-\u098C\u098F-\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC-\u09DD\u09DF-\u09E1\u09F0-\u09F1\u0A05-\u0A0A\u0A0F-\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32-\u0A33\u0A35-\u0A36\u0A38-\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2-\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0-\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F-\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32-\u0B33\u0B35-\u0B39\u0B3D\u0B5C-\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99-\u0B9A\u0B9C\u0B9E-\u0B9F\u0BA3-\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60-\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0-\u0CE1\u0CF1-\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32-\u0E33\u0E40-\u0E45\u0E81-\u0E82\u0E84\u0E87-\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA-\u0EAB\u0EAD-\u0EB0\u0EB2-\u0EB3\u0EBD\u0EC0-\u0EC4\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065-\u1066\u106E-\u1070\u1075-\u1081\u108E\u10D0-\u10FA\u10FD-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17DC\u1820-\u1842\u1844-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE-\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C77\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5-\u1CF6\u2135-\u2138\u2D30-\u2D67\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3006\u303C\u3041-\u3096\u309F\u30A1-\u30FA\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA014\uA016-\uA48C\uA4D0-\uA4F7\uA500-\uA60B\uA610-\uA61F\uA62A-\uA62B\uA66E\uA6A0-\uA6E5\uA78F\uA7F7\uA7FB-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9E0-\uA9E4\uA9E7-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA6F\uAA71-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5-\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADC\uAAE0-\uAAEA\uAAF2\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40-\uFB41\uFB43-\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF66-\uFF6F\uFF71-\uFF9D\uFFA0-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]
// Letter, Titlecase
Lt = [\u01C5\u01C8\u01CB\u01F2\u1F88-\u1F8F\u1F98-\u1F9F\u1FA8-\u1FAF\u1FBC\u1FCC\u1FFC]
// Letter, Uppercase
Lu = [\u0041-\u005A\u00C0-\u00D6\u00D8-\u00DE\u0100\u0102\u0104\u0106\u0108\u010A\u010C\u010E\u0110\u0112\u0114\u0116\u0118\u011A\u011C\u011E\u0120\u0122\u0124\u0126\u0128\u012A\u012C\u012E\u0130\u0132\u0134\u0136\u0139\u013B\u013D\u013F\u0141\u0143\u0145\u0147\u014A\u014C\u014E\u0150\u0152\u0154\u0156\u0158\u015A\u015C\u015E\u0160\u0162\u0164\u0166\u0168\u016A\u016C\u016E\u0170\u0172\u0174\u0176\u0178-\u0179\u017B\u017D\u0181-\u0182\u0184\u0186-\u0187\u0189-\u018B\u018E-\u0191\u0193-\u0194\u0196-\u0198\u019C-\u019D\u019F-\u01A0\u01A2\u01A4\u01A6-\u01A7\u01A9\u01AC\u01AE-\u01AF\u01B1-\u01B3\u01B5\u01B7-\u01B8\u01BC\u01C4\u01C7\u01CA\u01CD\u01CF\u01D1\u01D3\u01D5\u01D7\u01D9\u01DB\u01DE\u01E0\u01E2\u01E4\u01E6\u01E8\u01EA\u01EC\u01EE\u01F1\u01F4\u01F6-\u01F8\u01FA\u01FC\u01FE\u0200\u0202\u0204\u0206\u0208\u020A\u020C\u020E\u0210\u0212\u0214\u0216\u0218\u021A\u021C\u021E\u0220\u0222\u0224\u0226\u0228\u022A\u022C\u022E\u0230\u0232\u023A-\u023B\u023D-\u023E\u0241\u0243-\u0246\u0248\u024A\u024C\u024E\u0370\u0372\u0376\u037F\u0386\u0388-\u038A\u038C\u038E-\u038F\u0391-\u03A1\u03A3-\u03AB\u03CF\u03D2-\u03D4\u03D8\u03DA\u03DC\u03DE\u03E0\u03E2\u03E4\u03E6\u03E8\u03EA\u03EC\u03EE\u03F4\u03F7\u03F9-\u03FA\u03FD-\u042F\u0460\u0462\u0464\u0466\u0468\u046A\u046C\u046E\u0470\u0472\u0474\u0476\u0478\u047A\u047C\u047E\u0480\u048A\u048C\u048E\u0490\u0492\u0494\u0496\u0498\u049A\u049C\u049E\u04A0\u04A2\u04A4\u04A6\u04A8\u04AA\u04AC\u04AE\u04B0\u04B2\u04B4\u04B6\u04B8\u04BA\u04BC\u04BE\u04C0-\u04C1\u04C3\u04C5\u04C7\u04C9\u04CB\u04CD\u04D0\u04D2\u04D4\u04D6\u04D8\u04DA\u04DC\u04DE\u04E0\u04E2\u04E4\u04E6\u04E8\u04EA\u04EC\u04EE\u04F0\u04F2\u04F4\u04F6\u04F8\u04FA\u04FC\u04FE\u0500\u0502\u0504\u0506\u0508\u050A\u050C\u050E\u0510\u0512\u0514\u0516\u0518\u051A\u051C\u051E\u0520\u0522\u0524\u0526\u0528\u052A\u052C\u052E\u0531-\u0556\u10A0-\u10C5\u10C7\u10CD\u13A0-\u13F5\u1C90-\u1CBA\u1CBD-\u1CBF\u1E00\u1E02\u1E04\u1E06\u1E08\u1E0A\u1E0C\u1E0E\u1E10\u1E12\u1E14\u1E16\u1E18\u1E1A\u1E1C\u1E1E\u1E20\u1E22\u1E24\u1E26\u1E28\u1E2A\u1E2C\u1E2E\u1E30\u1E32\u1E34\u1E36\u1E38\u1E3A\u1E3C\u1E3E\u1E40\u1E42\u1E44\u1E46\u1E48\u1E4A\u1E4C\u1E4E\u1E50\u1E52\u1E54\u1E56\u1E58\u1E5A\u1E5C\u1E5E\u1E60\u1E62\u1E64\u1E66\u1E68\u1E6A\u1E6C\u1E6E\u1E70\u1E72\u1E74\u1E76\u1E78\u1E7A\u1E7C\u1E7E\u1E80\u1E82\u1E84\u1E86\u1E88\u1E8A\u1E8C\u1E8E\u1E90\u1E92\u1E94\u1E9E\u1EA0\u1EA2\u1EA4\u1EA6\u1EA8\u1EAA\u1EAC\u1EAE\u1EB0\u1EB2\u1EB4\u1EB6\u1EB8\u1EBA\u1EBC\u1EBE\u1EC0\u1EC2\u1EC4\u1EC6\u1EC8\u1ECA\u1ECC\u1ECE\u1ED0\u1ED2\u1ED4\u1ED6\u1ED8\u1EDA\u1EDC\u1EDE\u1EE0\u1EE2\u1EE4\u1EE6\u1EE8\u1EEA\u1EEC\u1EEE\u1EF0\u1EF2\u1EF4\u1EF6\u1EF8\u1EFA\u1EFC\u1EFE\u1F08-\u1F0F\u1F18-\u1F1D\u1F28-\u1F2F\u1F38-\u1F3F\u1F48-\u1F4D\u1F59\u1F5B\u1F5D\u1F5F\u1F68-\u1F6F\u1FB8-\u1FBB\u1FC8-\u1FCB\u1FD8-\u1FDB\u1FE8-\u1FEC\u1FF8-\u1FFB\u2102\u2107\u210B-\u210D\u2110-\u2112\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u2130-\u2133\u213E-\u213F\u2145\u2183\u2C00-\u2C2E\u2C60\u2C62-\u2C64\u2C67\u2C69\u2C6B\u2C6D-\u2C70\u2C72\u2C75\u2C7E-\u2C80\u2C82\u2C84\u2C86\u2C88\u2C8A\u2C8C\u2C8E\u2C90\u2C92\u2C94\u2C96\u2C98\u2C9A\u2C9C\u2C9E\u2CA0\u2CA2\u2CA4\u2CA6\u2CA8\u2CAA\u2CAC\u2CAE\u2CB0\u2CB2\u2CB4\u2CB6\u2CB8\u2CBA\u2CBC\u2CBE\u2CC0\u2CC2\u2CC4\u2CC6\u2CC8\u2CCA\u2CCC\u2CCE\u2CD0\u2CD2\u2CD4\u2CD6\u2CD8\u2CDA\u2CDC\u2CDE\u2CE0\u2CE2\u2CEB\u2CED\u2CF2\uA640\uA642\uA644\uA646\uA648\uA64A\uA64C\uA64E\uA650\uA652\uA654\uA656\uA658\uA65A\uA65C\uA65E\uA660\uA662\uA664\uA666\uA668\uA66A\uA66C\uA680\uA682\uA684\uA686\uA688\uA68A\uA68C\uA68E\uA690\uA692\uA694\uA696\uA698\uA69A\uA722\uA724\uA726\uA728\uA72A\uA72C\uA72E\uA732\uA734\uA736\uA738\uA73A\uA73C\uA73E\uA740\uA742\uA744\uA746\uA748\uA74A\uA74C\uA74E\uA750\uA752\uA754\uA756\uA758\uA75A\uA75C\uA75E\uA760\uA762\uA764\uA766\uA768\uA76A\uA76C\uA76E\uA779\uA77B\uA77D-\uA77E\uA780\uA782\uA784\uA786\uA78B\uA78D\uA790\uA792\uA796\uA798\uA79A\uA79C\uA79E\uA7A0\uA7A2\uA7A4\uA7A6\uA7A8\uA7AA-\uA7AE\uA7B0-\uA7B4\uA7B6\uA7B8\uFF21-\uFF3A]
Lu = [\u0041-\u005A\u00C0-\u00D6\u00D8-\u00DE\u0100\u0102\u0104\u0106\u0108\u010A\u010C\u010E\u0110\u0112\u0114\u0116\u0118\u011A\u011C\u011E\u0120\u0122\u0124\u0126\u0128\u012A\u012C\u012E\u0130\u0132\u0134\u0136\u0139\u013B\u013D\u013F\u0141\u0143\u0145\u0147\u014A\u014C\u014E\u0150\u0152\u0154\u0156\u0158\u015A\u015C\u015E\u0160\u0162\u0164\u0166\u0168\u016A\u016C\u016E\u0170\u0172\u0174\u0176\u0178-\u0179\u017B\u017D\u0181-\u0182\u0184\u0186-\u0187\u0189-\u018B\u018E-\u0191\u0193-\u0194\u0196-\u0198\u019C-\u019D\u019F-\u01A0\u01A2\u01A4\u01A6-\u01A7\u01A9\u01AC\u01AE-\u01AF\u01B1-\u01B3\u01B5\u01B7-\u01B8\u01BC\u01C4\u01C7\u01CA\u01CD\u01CF\u01D1\u01D3\u01D5\u01D7\u01D9\u01DB\u01DE\u01E0\u01E2\u01E4\u01E6\u01E8\u01EA\u01EC\u01EE\u01F1\u01F4\u01F6-\u01F8\u01FA\u01FC\u01FE\u0200\u0202\u0204\u0206\u0208\u020A\u020C\u020E\u0210\u0212\u0214\u0216\u0218\u021A\u021C\u021E\u0220\u0222\u0224\u0226\u0228\u022A\u022C\u022E\u0230\u0232\u023A-\u023B\u023D-\u023E\u0241\u0243-\u0246\u0248\u024A\u024C\u024E\u0370\u0372\u0376\u037F\u0386\u0388-\u038A\u038C\u038E-\u038F\u0391-\u03A1\u03A3-\u03AB\u03CF\u03D2-\u03D4\u03D8\u03DA\u03DC\u03DE\u03E0\u03E2\u03E4\u03E6\u03E8\u03EA\u03EC\u03EE\u03F4\u03F7\u03F9-\u03FA\u03FD-\u042F\u0460\u0462\u0464\u0466\u0468\u046A\u046C\u046E\u0470\u0472\u0474\u0476\u0478\u047A\u047C\u047E\u0480\u048A\u048C\u048E\u0490\u0492\u0494\u0496\u0498\u049A\u049C\u049E\u04A0\u04A2\u04A4\u04A6\u04A8\u04AA\u04AC\u04AE\u04B0\u04B2\u04B4\u04B6\u04B8\u04BA\u04BC\u04BE\u04C0-\u04C1\u04C3\u04C5\u04C7\u04C9\u04CB\u04CD\u04D0\u04D2\u04D4\u04D6\u04D8\u04DA\u04DC\u04DE\u04E0\u04E2\u04E4\u04E6\u04E8\u04EA\u04EC\u04EE\u04F0\u04F2\u04F4\u04F6\u04F8\u04FA\u04FC\u04FE\u0500\u0502\u0504\u0506\u0508\u050A\u050C\u050E\u0510\u0512\u0514\u0516\u0518\u051A\u051C\u051E\u0520\u0522\u0524\u0526\u0528\u052A\u052C\u052E\u0531-\u0556\u10A0-\u10C5\u10C7\u10CD\u13A0-\u13F5\u1E00\u1E02\u1E04\u1E06\u1E08\u1E0A\u1E0C\u1E0E\u1E10\u1E12\u1E14\u1E16\u1E18\u1E1A\u1E1C\u1E1E\u1E20\u1E22\u1E24\u1E26\u1E28\u1E2A\u1E2C\u1E2E\u1E30\u1E32\u1E34\u1E36\u1E38\u1E3A\u1E3C\u1E3E\u1E40\u1E42\u1E44\u1E46\u1E48\u1E4A\u1E4C\u1E4E\u1E50\u1E52\u1E54\u1E56\u1E58\u1E5A\u1E5C\u1E5E\u1E60\u1E62\u1E64\u1E66\u1E68\u1E6A\u1E6C\u1E6E\u1E70\u1E72\u1E74\u1E76\u1E78\u1E7A\u1E7C\u1E7E\u1E80\u1E82\u1E84\u1E86\u1E88\u1E8A\u1E8C\u1E8E\u1E90\u1E92\u1E94\u1E9E\u1EA0\u1EA2\u1EA4\u1EA6\u1EA8\u1EAA\u1EAC\u1EAE\u1EB0\u1EB2\u1EB4\u1EB6\u1EB8\u1EBA\u1EBC\u1EBE\u1EC0\u1EC2\u1EC4\u1EC6\u1EC8\u1ECA\u1ECC\u1ECE\u1ED0\u1ED2\u1ED4\u1ED6\u1ED8\u1EDA\u1EDC\u1EDE\u1EE0\u1EE2\u1EE4\u1EE6\u1EE8\u1EEA\u1EEC\u1EEE\u1EF0\u1EF2\u1EF4\u1EF6\u1EF8\u1EFA\u1EFC\u1EFE\u1F08-\u1F0F\u1F18-\u1F1D\u1F28-\u1F2F\u1F38-\u1F3F\u1F48-\u1F4D\u1F59\u1F5B\u1F5D\u1F5F\u1F68-\u1F6F\u1FB8-\u1FBB\u1FC8-\u1FCB\u1FD8-\u1FDB\u1FE8-\u1FEC\u1FF8-\u1FFB\u2102\u2107\u210B-\u210D\u2110-\u2112\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u2130-\u2133\u213E-\u213F\u2145\u2183\u2C00-\u2C2E\u2C60\u2C62-\u2C64\u2C67\u2C69\u2C6B\u2C6D-\u2C70\u2C72\u2C75\u2C7E-\u2C80\u2C82\u2C84\u2C86\u2C88\u2C8A\u2C8C\u2C8E\u2C90\u2C92\u2C94\u2C96\u2C98\u2C9A\u2C9C\u2C9E\u2CA0\u2CA2\u2CA4\u2CA6\u2CA8\u2CAA\u2CAC\u2CAE\u2CB0\u2CB2\u2CB4\u2CB6\u2CB8\u2CBA\u2CBC\u2CBE\u2CC0\u2CC2\u2CC4\u2CC6\u2CC8\u2CCA\u2CCC\u2CCE\u2CD0\u2CD2\u2CD4\u2CD6\u2CD8\u2CDA\u2CDC\u2CDE\u2CE0\u2CE2\u2CEB\u2CED\u2CF2\uA640\uA642\uA644\uA646\uA648\uA64A\uA64C\uA64E\uA650\uA652\uA654\uA656\uA658\uA65A\uA65C\uA65E\uA660\uA662\uA664\uA666\uA668\uA66A\uA66C\uA680\uA682\uA684\uA686\uA688\uA68A\uA68C\uA68E\uA690\uA692\uA694\uA696\uA698\uA69A\uA722\uA724\uA726\uA728\uA72A\uA72C\uA72E\uA732\uA734\uA736\uA738\uA73A\uA73C\uA73E\uA740\uA742\uA744\uA746\uA748\uA74A\uA74C\uA74E\uA750\uA752\uA754\uA756\uA758\uA75A\uA75C\uA75E\uA760\uA762\uA764\uA766\uA768\uA76A\uA76C\uA76E\uA779\uA77B\uA77D-\uA77E\uA780\uA782\uA784\uA786\uA78B\uA78D\uA790\uA792\uA796\uA798\uA79A\uA79C\uA79E\uA7A0\uA7A2\uA7A4\uA7A6\uA7A8\uA7AA-\uA7AD\uA7B0-\uA7B4\uA7B6\uFF21-\uFF3A]
// Mark, Spacing Combining
Mc = [\u0903\u093B\u093E-\u0940\u0949-\u094C\u094E-\u094F\u0982-\u0983\u09BE-\u09C0\u09C7-\u09C8\u09CB-\u09CC\u09D7\u0A03\u0A3E-\u0A40\u0A83\u0ABE-\u0AC0\u0AC9\u0ACB-\u0ACC\u0B02-\u0B03\u0B3E\u0B40\u0B47-\u0B48\u0B4B-\u0B4C\u0B57\u0BBE-\u0BBF\u0BC1-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCC\u0BD7\u0C01-\u0C03\u0C41-\u0C44\u0C82-\u0C83\u0CBE\u0CC0-\u0CC4\u0CC7-\u0CC8\u0CCA-\u0CCB\u0CD5-\u0CD6\u0D02-\u0D03\u0D3E-\u0D40\u0D46-\u0D48\u0D4A-\u0D4C\u0D57\u0D82-\u0D83\u0DCF-\u0DD1\u0DD8-\u0DDF\u0DF2-\u0DF3\u0F3E-\u0F3F\u0F7F\u102B-\u102C\u1031\u1038\u103B-\u103C\u1056-\u1057\u1062-\u1064\u1067-\u106D\u1083-\u1084\u1087-\u108C\u108F\u109A-\u109C\u17B6\u17BE-\u17C5\u17C7-\u17C8\u1923-\u1926\u1929-\u192B\u1930-\u1931\u1933-\u1938\u1A19-\u1A1A\u1A55\u1A57\u1A61\u1A63-\u1A64\u1A6D-\u1A72\u1B04\u1B35\u1B3B\u1B3D-\u1B41\u1B43-\u1B44\u1B82\u1BA1\u1BA6-\u1BA7\u1BAA\u1BE7\u1BEA-\u1BEC\u1BEE\u1BF2-\u1BF3\u1C24-\u1C2B\u1C34-\u1C35\u1CE1\u1CF2-\u1CF3\u1CF7\u302E-\u302F\uA823-\uA824\uA827\uA880-\uA881\uA8B4-\uA8C3\uA952-\uA953\uA983\uA9B4-\uA9B5\uA9BA-\uA9BB\uA9BD-\uA9C0\uAA2F-\uAA30\uAA33-\uAA34\uAA4D\uAA7B\uAA7D\uAAEB\uAAEE-\uAAEF\uAAF5\uABE3-\uABE4\uABE6-\uABE7\uABE9-\uABEA\uABEC]
Mc = [\u0903\u093B\u093E-\u0940\u0949-\u094C\u094E-\u094F\u0982-\u0983\u09BE-\u09C0\u09C7-\u09C8\u09CB-\u09CC\u09D7\u0A03\u0A3E-\u0A40\u0A83\u0ABE-\u0AC0\u0AC9\u0ACB-\u0ACC\u0B02-\u0B03\u0B3E\u0B40\u0B47-\u0B48\u0B4B-\u0B4C\u0B57\u0BBE-\u0BBF\u0BC1-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCC\u0BD7\u0C01-\u0C03\u0C41-\u0C44\u0C82-\u0C83\u0CBE\u0CC0-\u0CC4\u0CC7-\u0CC8\u0CCA-\u0CCB\u0CD5-\u0CD6\u0D02-\u0D03\u0D3E-\u0D40\u0D46-\u0D48\u0D4A-\u0D4C\u0D57\u0D82-\u0D83\u0DCF-\u0DD1\u0DD8-\u0DDF\u0DF2-\u0DF3\u0F3E-\u0F3F\u0F7F\u102B-\u102C\u1031\u1038\u103B-\u103C\u1056-\u1057\u1062-\u1064\u1067-\u106D\u1083-\u1084\u1087-\u108C\u108F\u109A-\u109C\u17B6\u17BE-\u17C5\u17C7-\u17C8\u1923-\u1926\u1929-\u192B\u1930-\u1931\u1933-\u1938\u1A19-\u1A1A\u1A55\u1A57\u1A61\u1A63-\u1A64\u1A6D-\u1A72\u1B04\u1B35\u1B3B\u1B3D-\u1B41\u1B43-\u1B44\u1B82\u1BA1\u1BA6-\u1BA7\u1BAA\u1BE7\u1BEA-\u1BEC\u1BEE\u1BF2-\u1BF3\u1C24-\u1C2B\u1C34-\u1C35\u1CE1\u1CF2-\u1CF3\u302E-\u302F\uA823-\uA824\uA827\uA880-\uA881\uA8B4-\uA8C3\uA952-\uA953\uA983\uA9B4-\uA9B5\uA9BA-\uA9BB\uA9BD-\uA9C0\uAA2F-\uAA30\uAA33-\uAA34\uAA4D\uAA7B\uAA7D\uAAEB\uAAEE-\uAAEF\uAAF5\uABE3-\uABE4\uABE6-\uABE7\uABE9-\uABEA\uABEC]
// Mark, Nonspacing
Mn = [\u0300-\u036F\u0483-\u0487\u0591-\u05BD\u05BF\u05C1-\u05C2\u05C4-\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7-\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0902\u093A\u093C\u0941-\u0948\u094D\u0951-\u0957\u0962-\u0963\u0981\u09BC\u09C1-\u09C4\u09CD\u09E2-\u09E3\u09FE\u0A01-\u0A02\u0A3C\u0A41-\u0A42\u0A47-\u0A48\u0A4B-\u0A4D\u0A51\u0A70-\u0A71\u0A75\u0A81-\u0A82\u0ABC\u0AC1-\u0AC5\u0AC7-\u0AC8\u0ACD\u0AE2-\u0AE3\u0AFA-\u0AFF\u0B01\u0B3C\u0B3F\u0B41-\u0B44\u0B4D\u0B56\u0B62-\u0B63\u0B82\u0BC0\u0BCD\u0C00\u0C04\u0C3E-\u0C40\u0C46-\u0C48\u0C4A-\u0C4D\u0C55-\u0C56\u0C62-\u0C63\u0C81\u0CBC\u0CBF\u0CC6\u0CCC-\u0CCD\u0CE2-\u0CE3\u0D00-\u0D01\u0D3B-\u0D3C\u0D41-\u0D44\u0D4D\u0D62-\u0D63\u0DCA\u0DD2-\u0DD4\u0DD6\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB-\u0EBC\u0EC8-\u0ECD\u0F18-\u0F19\u0F35\u0F37\u0F39\u0F71-\u0F7E\u0F80-\u0F84\u0F86-\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102D-\u1030\u1032-\u1037\u1039-\u103A\u103D-\u103E\u1058-\u1059\u105E-\u1060\u1071-\u1074\u1082\u1085-\u1086\u108D\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752-\u1753\u1772-\u1773\u17B4-\u17B5\u17B7-\u17BD\u17C6\u17C9-\u17D3\u17DD\u180B-\u180D\u1885-\u1886\u18A9\u1920-\u1922\u1927-\u1928\u1932\u1939-\u193B\u1A17-\u1A18\u1A1B\u1A56\u1A58-\u1A5E\u1A60\u1A62\u1A65-\u1A6C\u1A73-\u1A7C\u1A7F\u1AB0-\u1ABD\u1B00-\u1B03\u1B34\u1B36-\u1B3A\u1B3C\u1B42\u1B6B-\u1B73\u1B80-\u1B81\u1BA2-\u1BA5\u1BA8-\u1BA9\u1BAB-\u1BAD\u1BE6\u1BE8-\u1BE9\u1BED\u1BEF-\u1BF1\u1C2C-\u1C33\u1C36-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE0\u1CE2-\u1CE8\u1CED\u1CF4\u1CF8-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302D\u3099-\u309A\uA66F\uA674-\uA67D\uA69E-\uA69F\uA6F0-\uA6F1\uA802\uA806\uA80B\uA825-\uA826\uA8C4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA951\uA980-\uA982\uA9B3\uA9B6-\uA9B9\uA9BC\uA9E5\uAA29-\uAA2E\uAA31-\uAA32\uAA35-\uAA36\uAA43\uAA4C\uAA7C\uAAB0\uAAB2-\uAAB4\uAAB7-\uAAB8\uAABE-\uAABF\uAAC1\uAAEC-\uAAED\uAAF6\uABE5\uABE8\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]
Mn = [\u0300-\u036F\u0483-\u0487\u0591-\u05BD\u05BF\u05C1-\u05C2\u05C4-\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7-\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08E3-\u0902\u093A\u093C\u0941-\u0948\u094D\u0951-\u0957\u0962-\u0963\u0981\u09BC\u09C1-\u09C4\u09CD\u09E2-\u09E3\u0A01-\u0A02\u0A3C\u0A41-\u0A42\u0A47-\u0A48\u0A4B-\u0A4D\u0A51\u0A70-\u0A71\u0A75\u0A81-\u0A82\u0ABC\u0AC1-\u0AC5\u0AC7-\u0AC8\u0ACD\u0AE2-\u0AE3\u0B01\u0B3C\u0B3F\u0B41-\u0B44\u0B4D\u0B56\u0B62-\u0B63\u0B82\u0BC0\u0BCD\u0C00\u0C3E-\u0C40\u0C46-\u0C48\u0C4A-\u0C4D\u0C55-\u0C56\u0C62-\u0C63\u0C81\u0CBC\u0CBF\u0CC6\u0CCC-\u0CCD\u0CE2-\u0CE3\u0D01\u0D41-\u0D44\u0D4D\u0D62-\u0D63\u0DCA\u0DD2-\u0DD4\u0DD6\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB-\u0EBC\u0EC8-\u0ECD\u0F18-\u0F19\u0F35\u0F37\u0F39\u0F71-\u0F7E\u0F80-\u0F84\u0F86-\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102D-\u1030\u1032-\u1037\u1039-\u103A\u103D-\u103E\u1058-\u1059\u105E-\u1060\u1071-\u1074\u1082\u1085-\u1086\u108D\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752-\u1753\u1772-\u1773\u17B4-\u17B5\u17B7-\u17BD\u17C6\u17C9-\u17D3\u17DD\u180B-\u180D\u18A9\u1920-\u1922\u1927-\u1928\u1932\u1939-\u193B\u1A17-\u1A18\u1A1B\u1A56\u1A58-\u1A5E\u1A60\u1A62\u1A65-\u1A6C\u1A73-\u1A7C\u1A7F\u1AB0-\u1ABD\u1B00-\u1B03\u1B34\u1B36-\u1B3A\u1B3C\u1B42\u1B6B-\u1B73\u1B80-\u1B81\u1BA2-\u1BA5\u1BA8-\u1BA9\u1BAB-\u1BAD\u1BE6\u1BE8-\u1BE9\u1BED\u1BEF-\u1BF1\u1C2C-\u1C33\u1C36-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE0\u1CE2-\u1CE8\u1CED\u1CF4\u1CF8-\u1CF9\u1DC0-\u1DF5\u1DFC-\u1DFF\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302D\u3099-\u309A\uA66F\uA674-\uA67D\uA69E-\uA69F\uA6F0-\uA6F1\uA802\uA806\uA80B\uA825-\uA826\uA8C4\uA8E0-\uA8F1\uA926-\uA92D\uA947-\uA951\uA980-\uA982\uA9B3\uA9B6-\uA9B9\uA9BC\uA9E5\uAA29-\uAA2E\uAA31-\uAA32\uAA35-\uAA36\uAA43\uAA4C\uAA7C\uAAB0\uAAB2-\uAAB4\uAAB7-\uAAB8\uAABE-\uAABF\uAAC1\uAAEC-\uAAED\uAAF6\uABE5\uABE8\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]
// Number, Decimal Digit
Nd = [\u0030-\u0039\u0660-\u0669\u06F0-\u06F9\u07C0-\u07C9\u0966-\u096F\u09E6-\u09EF\u0A66-\u0A6F\u0AE6-\u0AEF\u0B66-\u0B6F\u0BE6-\u0BEF\u0C66-\u0C6F\u0CE6-\u0CEF\u0D66-\u0D6F\u0DE6-\u0DEF\u0E50-\u0E59\u0ED0-\u0ED9\u0F20-\u0F29\u1040-\u1049\u1090-\u1099\u17E0-\u17E9\u1810-\u1819\u1946-\u194F\u19D0-\u19D9\u1A80-\u1A89\u1A90-\u1A99\u1B50-\u1B59\u1BB0-\u1BB9\u1C40-\u1C49\u1C50-\u1C59\uA620-\uA629\uA8D0-\uA8D9\uA900-\uA909\uA9D0-\uA9D9\uA9F0-\uA9F9\uAA50-\uAA59\uABF0-\uABF9\uFF10-\uFF19]

@ -0,0 +1,14 @@
"use strict";
const fs = require("fs");
const path = require("path");
const util = require("util");
const generate = require("../").generate;
const parser = require("../lib/parser");
let grammar = fs.readFileSync(path.join(__dirname, "test.pegjs"), { encoding: "utf-8" });
// let parseResult = parser.parse(grammar);
let parseResult = generate(grammar);
console.log(util.inspect(parseResult, { depth: null, colors: true }));

@ -0,0 +1,5 @@
import Foo from "./util.pegjs"
import { CommaDelimited as DelimitedNumber } from "./delimited-number"
TopLevelRule
= "hello"

@ -0,0 +1,21 @@
"use strict";
let gulp = require("gulp");
let peg = require("./lib/peg");
let rename = require("gulp-rename");
let transform = require("gulp-transform");
function generate(contents) {
return peg.generate(contents.toString(), {
output: "source",
format: "commonjs"
});
}
// Generate the grammar parser.
gulp.task("parser", () =>
gulp.src("src/parser.pegjs")
.pipe(transform("utf8", generate))
.pipe(rename({ extname: ".js" }))
.pipe(gulp.dest("lib"))
);

@ -0,0 +1,5 @@
{
"env": {
"commonjs": true
}
}

@ -0,0 +1,76 @@
"use strict";
let visitor = require("./visitor");
// AST utilities.
let asts = {
findRule(ast, name) {
for (let i = 0; i < ast.rules.length; i++) {
if (ast.rules[i].name === name) {
return ast.rules[i];
}
}
return undefined;
},
indexOfRule(ast, name) {
for (let i = 0; i < ast.rules.length; i++) {
if (ast.rules[i].name === name) {
return i;
}
}
return -1;
},
alwaysConsumesOnSuccess(ast, node) {
function consumesTrue() { return true; }
function consumesFalse() { return false; }
function consumesExpression(node) {
return consumes(node.expression);
}
let consumes = visitor.build({
rule: consumesExpression,
named: consumesExpression,
choice(node) {
return node.alternatives.every(consumes);
},
action: consumesExpression,
sequence(node) {
return node.elements.some(consumes);
},
labeled: consumesExpression,
text: consumesExpression,
simple_and: consumesFalse,
simple_not: consumesFalse,
optional: consumesFalse,
zero_or_more: consumesFalse,
one_or_more: consumesExpression,
group: consumesExpression,
semantic_and: consumesFalse,
semantic_not: consumesFalse,
rule_ref(node) {
return consumes(asts.findRule(ast, node.name));
},
literal(node) {
return node.value !== "";
},
class: consumesTrue,
any: consumesTrue
});
return consumes(node);
}
};
module.exports = asts;

@ -0,0 +1,78 @@
"use strict";
let generateBytecode = require("./passes/generate-bytecode");
let generateJS = require("./passes/generate-js");
let removeProxyRules = require("./passes/remove-proxy-rules");
let reportDuplicateLabels = require("./passes/report-duplicate-labels");
let reportDuplicateRules = require("./passes/report-duplicate-rules");
let reportInfiniteRecursion = require("./passes/report-infinite-recursion");
let reportInfiniteRepetition = require("./passes/report-infinite-repetition");
let reportUndefinedRules = require("./passes/report-undefined-rules");
let visitor = require("./visitor");
function processOptions(options, defaults) {
return Object.assign({}, defaults, options);
}
let compiler = {
// AST node visitor builder. Useful mainly for plugins which manipulate the
// AST.
visitor: visitor,
// Compiler passes.
//
// Each pass is a function that is passed the AST. It can perform checks on it
// or modify it as needed. If the pass encounters a semantic error, it throws
// |peg.GrammarError|.
passes: {
check: {
reportUndefinedRules: reportUndefinedRules,
reportDuplicateRules: reportDuplicateRules,
reportDuplicateLabels: reportDuplicateLabels,
reportInfiniteRecursion: reportInfiniteRecursion,
reportInfiniteRepetition: reportInfiniteRepetition
},
transform: {
removeProxyRules: removeProxyRules
},
generate: {
generateBytecode: generateBytecode,
generateJS: generateJS
}
},
// Generates a parser from a specified grammar AST. Throws |peg.GrammarError|
// if the AST contains a semantic error. Note that not all errors are detected
// during the generation and some may protrude to the generated parser and
// cause its malfunction.
compile(ast, passes, options = {}) {
let processedOptions = processOptions(options, {
allowedStartRules: [ast.rules[0].name],
cache: false,
dependencies: {},
exportVar: null,
format: "bare",
optimize: "speed",
output: "parser",
trace: false
});
Object.values(passes).forEach((stagePasses) => {
stagePasses.forEach(pass => { pass(ast, processedOptions); });
});
switch (processedOptions.output) {
case "parser":
return eval(ast.code);
case "source":
return ast.code;
// FIXME: Move to Validatem code at entrypoint
default:
throw new Error("Invalid output format: " + processedOptions.output + ".");
}
}
};
module.exports = compiler;

@ -0,0 +1,59 @@
"use strict";
function hex(character) {
return character
.charCodeAt(0)
.toString(16)
.toUpperCase();
}
// JavaScript code generation helpers.
let js = {
stringEscape(s) {
// ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a string
// literal except for the closing quote character, backslash, carriage
// return, line separator, paragraph separator, and line feed. Any character
// may appear in the form of an escape sequence.
//
// For portability, we also escape all control and non-ASCII characters.
return s
.replace(/\\/g, "\\\\") // backslash
.replace(/"/g, "\\\"") // closing double quote
.replace(/\0/g, "\\0") // null
.replace(/\x08/g, "\\b") // backspace
.replace(/\t/g, "\\t") // horizontal tab
.replace(/\n/g, "\\n") // line feed
.replace(/\v/g, "\\v") // vertical tab
.replace(/\f/g, "\\f") // form feed
.replace(/\r/g, "\\r") // carriage return
.replace(/[\x00-\x0F]/g, ch => "\\x0" + hex(ch))
.replace(/[\x10-\x1F\x7F-\xFF]/g, ch => "\\x" + hex(ch))
.replace(/[\u0100-\u0FFF]/g, ch => "\\u0" + hex(ch))
.replace(/[\u1000-\uFFFF]/g, ch => "\\u" + hex(ch));
},
regexpClassEscape(s) {
// Based on ECMA-262, 5th ed., 7.8.5 & 15.10.1.
//
// For portability, we also escape all control and non-ASCII characters.
return s
.replace(/\\/g, "\\\\") // backslash
.replace(/\//g, "\\/") // closing slash
.replace(/]/g, "\\]") // closing bracket
.replace(/\^/g, "\\^") // caret
.replace(/-/g, "\\-") // dash
.replace(/\0/g, "\\0") // null
.replace(/\x08/g, "\\b") // backspace
.replace(/\t/g, "\\t") // horizontal tab
.replace(/\n/g, "\\n") // line feed
.replace(/\v/g, "\\v") // vertical tab
.replace(/\f/g, "\\f") // form feed
.replace(/\r/g, "\\r") // carriage return
.replace(/[\x00-\x0F]/g, ch => "\\x0" + hex(ch))
.replace(/[\x10-\x1F\x7F-\xFF]/g, ch => "\\x" + hex(ch))
.replace(/[\u0100-\u0FFF]/g, ch => "\\u0" + hex(ch))
.replace(/[\u1000-\uFFFF]/g, ch => "\\u" + hex(ch));
}
};
module.exports = js;

@ -0,0 +1,54 @@
"use strict";
// Bytecode instruction opcodes.
let opcodes = {
// Stack Manipulation
PUSH: 0, // PUSH c
PUSH_UNDEFINED: 1, // PUSH_UNDEFINED
PUSH_NULL: 2, // PUSH_NULL
PUSH_FAILED: 3, // PUSH_FAILED
PUSH_EMPTY_ARRAY: 4, // PUSH_EMPTY_ARRAY
PUSH_CURR_POS: 5, // PUSH_CURR_POS
POP: 6, // POP
POP_CURR_POS: 7, // POP_CURR_POS
POP_N: 8, // POP_N n
NIP: 9, // NIP
APPEND: 10, // APPEND
WRAP: 11, // WRAP n
TEXT: 12, // TEXT
// Conditions and Loops
IF: 13, // IF t, f
IF_ERROR: 14, // IF_ERROR t, f
IF_NOT_ERROR: 15, // IF_NOT_ERROR t, f
WHILE_NOT_ERROR: 16, // WHILE_NOT_ERROR b
// Matching
MATCH_ANY: 17, // MATCH_ANY a, f, ...
MATCH_STRING: 18, // MATCH_STRING s, a, f, ...
MATCH_STRING_IC: 19, // MATCH_STRING_IC s, a, f, ...
MATCH_REGEXP: 20, // MATCH_REGEXP r, a, f, ...
ACCEPT_N: 21, // ACCEPT_N n
ACCEPT_STRING: 22, // ACCEPT_STRING s
FAIL: 23, // FAIL e
// Calls
LOAD_SAVED_POS: 24, // LOAD_SAVED_POS p
UPDATE_SAVED_POS: 25, // UPDATE_SAVED_POS
CALL: 26, // CALL f, n, pc, p1, p2, ..., pN
// Rules
RULE: 27, // RULE r
// Failure Reporting
SILENT_FAILS_ON: 28, // SILENT_FAILS_ON
SILENT_FAILS_OFF: 29 // SILENT_FAILS_OFF
};
module.exports = opcodes;

@ -0,0 +1,618 @@
"use strict";
let asts = require("../asts");
let js = require("../js");
let op = require("../opcodes");
let visitor = require("../visitor");
// Generates bytecode.
//
// Instructions
// ============
//
// Stack Manipulation
// ------------------
//
// [0] PUSH c
//
// stack.push(consts[c]);
//
// [1] PUSH_UNDEFINED
//
// stack.push(undefined);
//
// [2] PUSH_NULL
//
// stack.push(null);
//
// [3] PUSH_FAILED
//
// stack.push(FAILED);
//
// [4] PUSH_EMPTY_ARRAY
//
// stack.push([]);
//
// [5] PUSH_CURR_POS
//
// stack.push(currPos);
//
// [6] POP
//
// stack.pop();
//
// [7] POP_CURR_POS
//
// currPos = stack.pop();
//
// [8] POP_N n
//
// stack.pop(n);
//
// [9] NIP
//
// value = stack.pop();
// stack.pop();
// stack.push(value);
//
// [10] APPEND
//
// value = stack.pop();
// array = stack.pop();
// array.push(value);
// stack.push(array);
//
// [11] WRAP n
//
// stack.push(stack.pop(n));
//
// [12] TEXT
//
// stack.push(input.substring(stack.pop(), currPos));
//
// Conditions and Loops
// --------------------
//
// [13] IF t, f
//
// if (stack.top()) {
// interpret(ip + 3, ip + 3 + t);
// } else {
// interpret(ip + 3 + t, ip + 3 + t + f);
// }
//
// [14] IF_ERROR t, f
//
// if (stack.top() === FAILED) {
// interpret(ip + 3, ip + 3 + t);
// } else {
// interpret(ip + 3 + t, ip + 3 + t + f);
// }
//
// [15] IF_NOT_ERROR t, f
//
// if (stack.top() !== FAILED) {
// interpret(ip + 3, ip + 3 + t);
// } else {
// interpret(ip + 3 + t, ip + 3 + t + f);
// }
//
// [16] WHILE_NOT_ERROR b
//
// while(stack.top() !== FAILED) {
// interpret(ip + 2, ip + 2 + b);
// }
//
// Matching
// --------
//
// [17] MATCH_ANY a, f, ...
//
// if (input.length > currPos) {
// interpret(ip + 3, ip + 3 + a);
// } else {
// interpret(ip + 3 + a, ip + 3 + a + f);
// }
//
// [18] MATCH_STRING s, a, f, ...
//
// if (input.substr(currPos, consts[s].length) === consts[s]) {
// interpret(ip + 4, ip + 4 + a);
// } else {
// interpret(ip + 4 + a, ip + 4 + a + f);
// }
//
// [19] MATCH_STRING_IC s, a, f, ...
//
// if (input.substr(currPos, consts[s].length).toLowerCase() === consts[s]) {
// interpret(ip + 4, ip + 4 + a);
// } else {
// interpret(ip + 4 + a, ip + 4 + a + f);
// }
//
// [20] MATCH_REGEXP r, a, f, ...
//
// if (consts[r].test(input.charAt(currPos))) {
// interpret(ip + 4, ip + 4 + a);
// } else {
// interpret(ip + 4 + a, ip + 4 + a + f);
// }
//
// [21] ACCEPT_N n
//
// stack.push(input.substring(currPos, n));
// currPos += n;
//
// [22] ACCEPT_STRING s
//
// stack.push(consts[s]);
// currPos += consts[s].length;
//
// [23] FAIL e
//
// stack.push(FAILED);
// fail(consts[e]);
//
// Calls
// -----
//
// [24] LOAD_SAVED_POS p
//
// savedPos = stack[p];
//
// [25] UPDATE_SAVED_POS
//
// savedPos = currPos;
//
// [26] CALL f, n, pc, p1, p2, ..., pN
//
// value = consts[f](stack[p1], ..., stack[pN]);
// stack.pop(n);
// stack.push(value);
//
// Rules
// -----
//
// [27] RULE r
//
// stack.push(parseRule(r));
//
// Failure Reporting
// -----------------
//
// [28] SILENT_FAILS_ON
//
// silentFails++;
//
// [29] SILENT_FAILS_OFF
//
// silentFails--;
function generateBytecode(ast) {
let consts = [];
function addConst(value) {
let index = consts.indexOf(value);
return index === -1 ? consts.push(value) - 1 : index;
}
function addFunctionConst(params, code) {
return addConst(
"function(" + params.join(", ") + ") {" + code + "}"
);
}
function cloneEnv(env) {
let clone = {};
Object.keys(env).forEach(name => {
clone[name] = env[name];
});
return clone;
}
function buildSequence() {
return Array.prototype.concat.apply([], arguments);
}
function buildCondition(condCode, thenCode, elseCode) {
return condCode.concat(
[thenCode.length, elseCode.length],
thenCode,
elseCode
);
}
function buildLoop(condCode, bodyCode) {
return condCode.concat([bodyCode.length], bodyCode);
}
function buildCall(functionIndex, delta, env, sp) {
let params = Object.keys(env).map(name => sp - env[name]);
return [op.CALL, functionIndex, delta, params.length].concat(params);
}
function buildSimplePredicate(expression, negative, context) {
return buildSequence(
[op.PUSH_CURR_POS],
[op.SILENT_FAILS_ON],
generate(expression, {
sp: context.sp + 1,
env: cloneEnv(context.env),
action: null
}),
[op.SILENT_FAILS_OFF],
buildCondition(
[negative ? op.IF_ERROR : op.IF_NOT_ERROR],
buildSequence(
[op.POP],
[negative ? op.POP : op.POP_CURR_POS],
[op.PUSH_UNDEFINED]
),
buildSequence(
[op.POP],
[negative ? op.POP_CURR_POS : op.POP],
[op.PUSH_FAILED]
)
)
);
}
function buildSemanticPredicate(code, negative, context) {
let functionIndex = addFunctionConst(Object.keys(context.env), code);
return buildSequence(
[op.UPDATE_SAVED_POS],
buildCall(functionIndex, 0, context.env, context.sp),
buildCondition(
[op.IF],
buildSequence(
[op.POP],
negative ? [op.PUSH_FAILED] : [op.PUSH_UNDEFINED]
),
buildSequence(
[op.POP],
negative ? [op.PUSH_UNDEFINED] : [op.PUSH_FAILED]
)
)
);
}
function buildAppendLoop(expressionCode) {
return buildLoop(
[op.WHILE_NOT_ERROR],
buildSequence([op.APPEND], expressionCode)
);
}
let generate = visitor.build({
grammar(node) {
node.rules.forEach(generate);
node.consts = consts;
},
rule(node) {
node.bytecode = generate(node.expression, {
sp: -1, // stack pointer
env: { }, // mapping of label names to stack positions
action: null // action nodes pass themselves to children here
});
},
named(node, context) {
let nameIndex = addConst(
"peg$otherExpectation(\"" + js.stringEscape(node.name) + "\")"
);
// The code generated below is slightly suboptimal because |FAIL| pushes
// to the stack, so we need to stick a |POP| in front of it. We lack a
// dedicated instruction that would just report the failure and not touch
// the stack.
return buildSequence(
[op.SILENT_FAILS_ON],
generate(node.expression, context),
[op.SILENT_FAILS_OFF],
buildCondition([op.IF_ERROR], [op.FAIL, nameIndex], [])
);
},
choice(node, context) {
function buildAlternativesCode(alternatives, context) {
return buildSequence(
generate(alternatives[0], {
sp: context.sp,
env: cloneEnv(context.env),
action: null
}),
alternatives.length > 1
? buildCondition(
[op.IF_ERROR],
buildSequence(
[op.POP],
buildAlternativesCode(alternatives.slice(1), context)
),
[]
)
: []
);
}
return buildAlternativesCode(node.alternatives, context);
},
action(node, context) {
let env = cloneEnv(context.env);
let emitCall = node.expression.type !== "sequence"
|| node.expression.elements.length === 0;
let expressionCode = generate(node.expression, {
sp: context.sp + (emitCall ? 1 : 0),
env: env,
action: node
});
let functionIndex = addFunctionConst(Object.keys(env), node.code);
return emitCall
? buildSequence(
[op.PUSH_CURR_POS],
expressionCode,
buildCondition(
[op.IF_NOT_ERROR],
buildSequence(
[op.LOAD_SAVED_POS, 1],
buildCall(functionIndex, 1, env, context.sp + 2)
),
[]
),
[op.NIP]
)
: expressionCode;
},
sequence(node, context) {
function buildElementsCode(elements, context) {
if (elements.length > 0) {
let processedCount = node.elements.length - elements.slice(1).length;
return buildSequence(
generate(elements[0], {
sp: context.sp,
env: context.env,
action: null
}),
buildCondition(
[op.IF_NOT_ERROR],
buildElementsCode(elements.slice(1), {
sp: context.sp + 1,
env: context.env,
action: context.action
}),
buildSequence(
processedCount > 1 ? [op.POP_N, processedCount] : [op.POP],
[op.POP_CURR_POS],
[op.PUSH_FAILED]
)
)
);
} else {
if (context.action) {
let functionIndex = addFunctionConst(
Object.keys(context.env),
context.action.code
);
return buildSequence(
[op.LOAD_SAVED_POS, node.elements.length],
buildCall(
functionIndex,
node.elements.length,
context.env,
context.sp
),
[op.NIP]
);
} else {
return buildSequence([op.WRAP, node.elements.length], [op.NIP]);
}
}
}
return buildSequence(
[op.PUSH_CURR_POS],
buildElementsCode(node.elements, {
sp: context.sp + 1,
env: context.env,
action: context.action
})
);
},
labeled(node, context) {
let env = cloneEnv(context.env);
context.env[node.label] = context.sp + 1;
return generate(node.expression, {
sp: context.sp,
env: env,
action: null
});
},
text(node, context) {
return buildSequence(
[op.PUSH_CURR_POS],
generate(node.expression, {
sp: context.sp + 1,
env: cloneEnv(context.env),
action: null
}),
buildCondition(
[op.IF_NOT_ERROR],
buildSequence([op.POP], [op.TEXT]),
[op.NIP]
)
);
},
simple_and(node, context) {
return buildSimplePredicate(node.expression, false, context);
},
simple_not(node, context) {
return buildSimplePredicate(node.expression, true, context);
},
optional(node, context) {
return buildSequence(
generate(node.expression, {
sp: context.sp,
env: cloneEnv(context.env),
action: null
}),
buildCondition(
[op.IF_ERROR],
buildSequence([op.POP], [op.PUSH_NULL]),
[]
)
);
},
zero_or_more(node, context) {
let expressionCode = generate(node.expression, {
sp: context.sp + 1,
env: cloneEnv(context.env),
action: null
});
return buildSequence(
[op.PUSH_EMPTY_ARRAY],
expressionCode,
buildAppendLoop(expressionCode),
[op.POP]
);
},
one_or_more(node, context) {
let expressionCode = generate(node.expression, {
sp: context.sp + 1,
env: cloneEnv(context.env),
action: null
});
return buildSequence(
[op.PUSH_EMPTY_ARRAY],
expressionCode,
buildCondition(
[op.IF_NOT_ERROR],
buildSequence(buildAppendLoop(expressionCode), [op.POP]),
buildSequence([op.POP], [op.POP], [op.PUSH_FAILED])
)
);
},
group(node, context) {
return generate(node.expression, {
sp: context.sp,
env: cloneEnv(context.env),
action: null
});
},
semantic_and(node, context) {
return buildSemanticPredicate(node.code, false, context);
},
semantic_not(node, context) {
return buildSemanticPredicate(node.code, true, context);
},
rule_ref(node) {
return [op.RULE, asts.indexOfRule(ast, node.name)];
},
literal(node) {
if (node.value.length > 0) {
let stringIndex = addConst("\""
+ js.stringEscape(
node.ignoreCase ? node.value.toLowerCase() : node.value
)
+ "\""
);
let expectedIndex = addConst(
"peg$literalExpectation("
+ "\"" + js.stringEscape(node.value) + "\", "
+ node.ignoreCase
+ ")"
);
// For case-sensitive strings the value must match the beginning of the
// remaining input exactly. As a result, we can use |ACCEPT_STRING| and
// save one |substr| call that would be needed if we used |ACCEPT_N|.
return buildCondition(
node.ignoreCase
? [op.MATCH_STRING_IC, stringIndex]
: [op.MATCH_STRING, stringIndex],
node.ignoreCase
? [op.ACCEPT_N, node.value.length]
: [op.ACCEPT_STRING, stringIndex],
[op.FAIL, expectedIndex]
);
} else {
let stringIndex = addConst("\"\"");
return [op.PUSH, stringIndex];
}
},
class(node) {
let regexp = "/^["
+ (node.inverted ? "^" : "")
+ node.parts.map(part =>
Array.isArray(part)
? js.regexpClassEscape(part[0])
+ "-"
+ js.regexpClassEscape(part[1])
: js.regexpClassEscape(part)
).join("")
+ "]/" + (node.ignoreCase ? "i" : "");
let parts = "["
+ node.parts.map(part =>
Array.isArray(part)
? "[\"" + js.stringEscape(part[0]) + "\", \"" + js.stringEscape(part[1]) + "\"]"
: "\"" + js.stringEscape(part) + "\""
).join(", ")
+ "]";
let regexpIndex = addConst(regexp);
let expectedIndex = addConst(
"peg$classExpectation("
+ parts + ", "
+ node.inverted + ", "
+ node.ignoreCase
+ ")"
);
return buildCondition(
[op.MATCH_REGEXP, regexpIndex],
[op.ACCEPT_N, 1],
[op.FAIL, expectedIndex]
);
},
any() {
let expectedIndex = addConst("peg$anyExpectation()");
return buildCondition(
[op.MATCH_ANY],
[op.ACCEPT_N, 1],
[op.FAIL, expectedIndex]
);
}
});
generate(ast);
}
module.exports = generateBytecode;

File diff suppressed because it is too large Load Diff

@ -0,0 +1,39 @@
"use strict";
let visitor = require("../visitor");
// Removes proxy rules -- that is, rules that only delegate to other rule.
function removeProxyRules(ast, options) {
function isProxyRule(node) {
return node.type === "rule" && node.expression.type === "rule_ref";
}
function replaceRuleRefs(ast, from, to) {
let replace = visitor.build({
rule_ref(node) {
if (node.name === from) {
node.name = to;
}
}
});
replace(ast);
}
let indices = [];
ast.rules.forEach((rule, i) => {
if (isProxyRule(rule)) {
replaceRuleRefs(ast, rule.name, rule.expression.name);
if (options.allowedStartRules.indexOf(rule.name) === -1) {
indices.push(i);
}
}
});
indices.reverse();
indices.forEach(i => { ast.rules.splice(i, 1); });
}
module.exports = removeProxyRules;

@ -0,0 +1,62 @@
"use strict";
let GrammarError = require("../../grammar-error");
let visitor = require("../visitor");
// Checks that each label is defined only once within each scope.
function reportDuplicateLabels(ast) {
function cloneEnv(env) {
let clone = {};
Object.keys(env).forEach(name => {
clone[name] = env[name];
});
return clone;
}
function checkExpressionWithClonedEnv(node, env) {
check(node.expression, cloneEnv(env));
}
let check = visitor.build({
rule(node) {
check(node.expression, { });
},
choice(node, env) {
node.alternatives.forEach(alternative => {
check(alternative, cloneEnv(env));
});
},
action: checkExpressionWithClonedEnv,
labeled(node, env) {
if (Object.prototype.hasOwnProperty.call(env, node.label)) {
throw new GrammarError(
"Label \"" + node.label + "\" is already defined "
+ "at line " + env[node.label].start.line + ", "
+ "column " + env[node.label].start.column + ".",
node.location
);
}
check(node.expression, env);
env[node.label] = node.location;
},
text: checkExpressionWithClonedEnv,
simple_and: checkExpressionWithClonedEnv,
simple_not: checkExpressionWithClonedEnv,
optional: checkExpressionWithClonedEnv,
zero_or_more: checkExpressionWithClonedEnv,
one_or_more: checkExpressionWithClonedEnv,
group: checkExpressionWithClonedEnv
});
check(ast);
}
module.exports = reportDuplicateLabels;

@ -0,0 +1,28 @@
"use strict";
let GrammarError = require("../../grammar-error");
let visitor = require("../visitor");
// Checks that each rule is defined only once.
function reportDuplicateRules(ast) {
let rules = {};
let check = visitor.build({
rule(node) {
if (Object.prototype.hasOwnProperty.call(rules, node.name)) {
throw new GrammarError(
"Rule \"" + node.name + "\" is already defined "
+ "at line " + rules[node.name].start.line + ", "
+ "column " + rules[node.name].start.column + ".",
node.location
);
}
rules[node.name] = node.location;
}
});
check(ast);
}
module.exports = reportDuplicateRules;

@ -0,0 +1,54 @@
"use strict";
let GrammarError = require("../../grammar-error");
let asts = require("../asts");
let visitor = require("../visitor");
// Reports left recursion in the grammar, which prevents infinite recursion in
// the generated parser.
//
// Both direct and indirect recursion is detected. The pass also correctly
// reports cases like this:
//
// start = "a"? start
//
// In general, if a rule reference can be reached without consuming any input,
// it can lead to left recursion.
function reportInfiniteRecursion(ast) {
let visitedRules = [];
let check = visitor.build({
rule(node) {
visitedRules.push(node.name);
check(node.expression);
visitedRules.pop(node.name);
},
sequence(node) {
node.elements.every(element => {
check(element);
return !asts.alwaysConsumesOnSuccess(ast, element);
});
},
rule_ref(node) {
if (visitedRules.indexOf(node.name) !== -1) {
visitedRules.push(node.name);
throw new GrammarError(
"Possible infinite loop when parsing (left recursion: "
+ visitedRules.join(" -> ")
+ ").",
node.location
);
}
check(asts.findRule(ast, node.name));
}
});
check(ast);
}
module.exports = reportInfiniteRecursion;

@ -0,0 +1,33 @@
"use strict";
let GrammarError = require("../../grammar-error");
let asts = require("../asts");
let visitor = require("../visitor");
// Reports expressions that don't consume any input inside |*| or |+| in the
// grammar, which prevents infinite loops in the generated parser.
function reportInfiniteRepetition(ast) {
let check = visitor.build({
zero_or_more(node) {
if (!asts.alwaysConsumesOnSuccess(ast, node.expression)) {
throw new GrammarError(
"Possible infinite loop when parsing (repetition used with an expression that may not consume any input).",
node.location
);
}
},
one_or_more(node) {
if (!asts.alwaysConsumesOnSuccess(ast, node.expression)) {
throw new GrammarError(
"Possible infinite loop when parsing (repetition used with an expression that may not consume any input).",
node.location
);
}
}
});
check(ast);
}
module.exports = reportInfiniteRepetition;

@ -0,0 +1,23 @@
"use strict";
let GrammarError = require("../../grammar-error");
let asts = require("../asts");
let visitor = require("../visitor");
// Checks that all referenced rules exist.
function reportUndefinedRules(ast) {
let check = visitor.build({
rule_ref(node) {
if (!asts.findRule(ast, node.name)) {
throw new GrammarError(
"Rule \"" + node.name + "\" is not defined.",
node.location
);
}
}
});
check(ast);
}
module.exports = reportUndefinedRules;

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save