Compare commits

...

367 Commits

Author SHA1 Message Date
Futago-za Ryuu b7b87ea8ae Fix comma-dangle warning from ESLint 5 years ago
Futago-za Ryuu 56722b6d41 Rebuild the website as a SSR static site 5 years ago
Futago-za Ryuu afeb2a3330 Support naming Webpack configs 5 years ago
Futago-za Ryuu 5f8344395c Update @pegjs/bundler
- Swap 'webpack-cli' for 'webpack-nano'
- Removed the built-in banner/header
- Added 'banner' option for custom headers
- Added alternative 'minimize' option
5 years ago
Futago-za Ryuu 04275b23da Update dependencies 5 years ago
Futago-za Ryuu 3c05ffe3f9 Remove VuePress 5 years ago
Futago-za Ryuu a1cf32d65a Move compatibility.md 5 years ago
Futago-za Ryuu 68ca388d91 Update badges 5 years ago
Futago-za Ryuu 5a209ff186 Remove CBT logo 5 years ago
Futago-za Ryuu 9360abb554 Cleanup GITHUB_REF env variable before use 5 years ago
Futago-za Ryuu 77b5fe7254 Remove minimum coverage ratio
It seems to have broken the codecov.io report generator instead :(
5 years ago
Futago-za Ryuu c8afff5864 Fix pegjs-dev publisher 5 years ago
Futago-za Ryuu f897df619e Set minimum coverage ratio 5 years ago
Futago-za Ryuu 8c653757e2 Fix linting errors 5 years ago
Futago-za Ryuu a7373c7345 Ensure vscode-eslint lints files in dot folders 5 years ago
Futago-za Ryuu e9920c8c4c Lint .eslintrc.js 5 years ago
Futago-za Ryuu 1159660cf7 Forward location to buildMessage (closes #608) 5 years ago
Futago-za Ryuu d615cd7975 Regenerate lockfile 5 years ago
Futago-za Ryuu c523cf5693 Update config for next.pegjs.org
- Enable 'smoothScroll' option
- Use '@vuepress/plugin-back-to-top'
- Use '@vuepress/plugin-google-analytics'
- Add 'docs/.vuepress/favicon.ico'
5 years ago
Futago-za Ryuu 6484145542 Require types/node v8.x 5 years ago
Futago-za Ryuu 1cd8ba29b0 Remove unrequired dependencies 5 years ago
Futago-za Ryuu f6ddc51745 Match Node version required by VuePress 5 years ago
Futago-za Ryuu 61eaba4c01 Update changelog entries 5 years ago
Futago-za Ryuu 7d13580855 Drop support for Node 6 5 years ago
Futago-za Ryuu 8b7bff7ac3 Resolve linting errors
This also temporarliy disables linting '.ts' files due to the fact that the currect '.d.ts' files contain too many errors/warnings that need to be manually fixed, but since I'm going to be rewriting the whole module in TypeScript anyway, resolving these ESLint error's is a pointless waste of time.
5 years ago
Futago-za Ryuu 61377b1bd7 Azure Pipelines -> GitHub Actions
- Update CodeCov CI provider URL
- Remove Support for Azure Pipelines
- Add support for GitHub Actions
- Stop generating redundent reports
- Update @pegjs/publish-dev
5 years ago
Futago-za Ryuu cf022429bb Cleanup and Update
- Update all dependencies
- Use '@futagoza/*' ESLint configurations
- Remove redundent '@pegjs/eslint-config'
- Add TypeScript support to the bundler
5 years ago
Futago-za Ryuu f00b516cd7 Update eslint config
- Move to manageble private package
- Ensure '.vue' rules are used via override
- Add support for TypeScript
- Update AP config to install correctly
5 years ago
Futago-za Ryuu 310252f7c5 support dev-publishing other packages 5 years ago
Futago-za Ryuu d08e8bf52d Upgrade devDependencies
- codecov: 3.3.0
- eslint: 5.16.0
- mocha: 6.1.3
- mocha-junit-reporter: 1.22.0
- nyc: 14.0.0
- vuepress: 1.0.0-alpha.47
- sinon: 7.3.2
- @babel/core: 7.4.3
- @babel/preset-env: 7.4.3
- webpack: 4.30.0
5 years ago
Futago-za Ryuu 138fb96aed Use progress reporter for faster local testing 5 years ago
Futago-za Ryuu e16dc50686 website: Use configs for nav and sidebars 5 years ago
Futago-za Ryuu fae001e4ed Upgrade devDependencies:
- codecov: 3.2.0
- eslint: 5.15.3
- eslint-config-futagozaryuu: 5.8.0
- eslint-plugin-vue: 5.2.2
- mocha: 6.0.3
- nyc: 13.3.0
- vuepress: 1.0.0-alpha.44
- sinon: 7.3.0
- @babel/core: 7.4.0
- @babel/preset-env: 7.4.2
- webpack: 4.29.6
- webpack-cli: 3.3.0
5 years ago
Nils-Hero Lindemann 0b102d29a8 Fix last link in the TOC (#621)
There was a '-1' missing at the end of the link.
5 years ago
Futago-za Ryuu 30f3260008 Skip publishing on Build.Reason === PullRequest 5 years ago
Futago-za Ryuu 56f3c98579 Use env parameter to pass variables 5 years ago
Futago-za Ryuu 42514c4951 Ensure GIT_COMMIT_SHA is valid 5 years ago
Futago-za Ryuu 910a51bf5f Dont auto-publish on PR's 5 years ago
Futago-za Ryuu 42a6f774fb Update installation document 5 years ago
Futago-za Ryuu 9b8b1c5e64 Fix links in browser benchmark results 5 years ago
Futago-za Ryuu 85dbe5a396 Fix build path for browser benchmark entry 5 years ago
Futago-za Ryuu 0253215c24 Update benchmark paths 5 years ago
Futago-za Ryuu 53b966289b Fix url's for ajax requests 5 years ago
Futago-za Ryuu e82994582a Use files from repo during benchmark in a browser 5 years ago
Futago-za Ryuu f69239dcc0 Use env directly with publishing script 5 years ago
Futago-za Ryuu ec3f2962a8 CI: env -> variables 5 years ago
Futago-za Ryuu 83616b4d5d CI: Use displayName + NPM_CI_TOKEN 5 years ago
Futago-za Ryuu 6a810cc78f pegjs@dev should always run 5 years ago
Futago-za Ryuu 38cd65d193 Use env variables when auto-publishing 5 years ago
Futago-za Ryuu baf8b3a339 Publish to pegjs@dev on every CI run
This adds a new local package called '@pegjs/publish-dev' that will be run by the CI after all other tasks.

'@pegjs/publish-dev' will, as the name implies, publish a new release of pegjs on NPM under the dev tag.
5 years ago
Futago-za Ryuu d7c11c54e8 Ensure all js files are transpiled 5 years ago
Futago-za Ryuu ef2d318c15 Regenerate test bundle [NO_CI] 5 years ago
Futago-za Ryuu 703fbbf8d0 Ensure mocha only finds test files 5 years ago
Futago-za Ryuu caa8b4cf7b Use html reporter for mocha browser 5 years ago
Futago-za Ryuu fcbfa39102 Ensure mocha runs on the browser 5 years ago
Futago-za Ryuu ea991cd65c Rebuild ci bundles 5 years ago
Futago-za Ryuu ed6690e5bb Use mocha/mocha.js 5 years ago
Futago-za Ryuu 6525825f2e Use mocha-loader 5 years ago
Futago-za Ryuu f7a52c70a4 Webpack: use library option 5 years ago
Futago-za Ryuu c35a61f524 Commit bundled web ci files 5 years ago
Futago-za Ryuu a2c677ef38 Use CODECOV_TOKEN secret 5 years ago
Futago-za Ryuu 5542547091 Switch to codecov.io 5 years ago
Futago-za Ryuu b1350d46f8 ci: use beforeEach and afterEach hooks 5 years ago
Futago-za Ryuu 05c6fc9a34 Remove env variables for Git 5 years ago
Futago-za Ryuu 9801b966c0 Add repository to packages table 5 years ago
Futago-za Ryuu 97f98122f8 devDependencies > dependencies 5 years ago
Futago-za Ryuu 8d1a9a6ceb Updated packages table [no ci] 5 years ago
Futago-za Ryuu da3ea8e47d Implement @pegjs/bundler 5 years ago
Futago-za Ryuu b2e6958698 Ensure all node_modules dirs are ignored 5 years ago
Futago-za Ryuu 7a78b7cfdf Upgrade dependencies 5 years ago
Futago-za Ryuu f13d0268d6 Pipelines: combine some scripts 5 years ago
Futago-za Ryuu 06f782d397 Pipelines: Move CC scripts to after hook 5 years ago
Futago-za Ryuu e72e85bc1d Pipelines: fix cc-test-reporter path 5 years ago
Futago-za Ryuu 0259640d3c Pipelines: Add test script hooks for CC 5 years ago
Futago-za Ryuu e6c4d8289d Rename azure_coverage to publish_* 5 years ago
Futago-za Ryuu 935f80d740 Pipelines: Use node-matrix-test.yml 5 years ago
Futago-za Ryuu 9906f21c57 Update output for mocha-junit-reporter 5 years ago
Futago-za Ryuu dedb372076 Pipelines: Add displayName for coverage step 5 years ago
Futago-za Ryuu c67fdeb59b Change endpoint for Pipeline templates 5 years ago
Futago-za Ryuu ba6cac15b3 Add endpoint for Pipeline templates 5 years ago
Futago-za Ryuu 41b5f44288 Use Pipeline templates from futagoza/apt 5 years ago
Futago-za Ryuu 0074d0456a Upgrade dependencies 5 years ago
Futago-za Ryuu 9716fe5f38 Yarn: ignore website directory 5 years ago
Futago-za Ryuu c17e9b2df7 Removed '--coverage-input-type lcov -d' 5 years ago
Futago-za Ryuu c59c81c318 Removed test coverage badges (#598) 5 years ago
Futago-za Ryuu dcd43eb251 cc-test-reporter -d 5 years ago
Futago-za Ryuu 9d381f0a09 Explicitly tell codeclimate the coverage format 5 years ago
Futago-za Ryuu b240b77386 Move coveralls step into main ci step 5 years ago
Futago-za Ryuu 1f1ac34009 Remove trigger section; Use defaults 5 years ago
Futago-za Ryuu 8b5d384e32 Add inclusion path 5 years ago
Futago-za Ryuu 7f908e9a7b Update workspaces field 5 years ago
Futago-za Ryuu d8b7e15169 Add echo statements 5 years ago
Futago-za Ryuu 15cb8ff968 Only use value of BuildID as name 5 years ago
azure-pipelines[bot] 024ac1a1b5 Update azure-pipelines.yml for Azure Pipelines 5 years ago
Futago-za Ryuu aa0412b2fb nyc: use text-summary 5 years ago
Futago-za Ryuu 3986ca7048 Export utils explicitly 5 years ago
Futago-za Ryuu e17cdabd4d Use default arguments 5 years ago
Futago-za Ryuu 2dc0a1b64a Upgrade dependencies 5 years ago
Futago-za Ryuu 485f37c290 Add changes for #596 5 years ago
Futago-za Ryuu bdde25a9e4
Set up CI with Azure Pipelines (#596)
* Add support for Azure Pipelines
* Remove Travis CI support
* coverage: Generate cobertura and lcov reports only
* Add support for Code Climate
5 years ago
Futago-za Ryuu 8c30834ccc Run eslint on .vue files 5 years ago
Futago-za Ryuu b7d4d01ff5 Fix build script for Now v2 [skip ci] 5 years ago
Futago-za Ryuu 498c13f7a9 Use latest version of Yarn on Travis 5 years ago
Futago-za Ryuu 132a68b4d5 Upgrade to Vuepress@next
Travis was failing with a weird ESLint error, and when I checked locally, the problem seemed to be related to Vuepress v0. Upgrading to Vuepress v1-alpha seems to fix this (at least on my machine...)
5 years ago
Futago-za Ryuu 2433c76ffb Add now-build script for Now v2 5 years ago
Futago-za Ryuu 4095a05420 Add a dummy page for the editor (temp) 5 years ago
Futago-za Ryuu 9b805a955d Add index page 5 years ago
Futago-za Ryuu f10d93f32f Move + Update dev docs 5 years ago
Futago-za Ryuu 12c98b7098 Add index page for Changelogs 5 years ago
Futago-za Ryuu 22c280f069 Hide edit button 5 years ago
Futago-za Ryuu a8e7534595 Add basic config for Vuepress 5 years ago
Futago-za Ryuu a04486711f Switch to Now v2 5 years ago
Futago-za Ryuu 29943edf60 Add forum badge 5 years ago
Futago-za Ryuu f754684fae Update Rollup dependencies 5 years ago
Futago-za Ryuu 1dd5a04ef2 Add support for Vuepress v0.14 5 years ago
Futago-za Ryuu 5dfb6b14dc Update eslint config
I removed "linebreak-style"  because it is now enabled by default within my eslint-config, with the same options.

Disabled padding-line-between-statements until https://github.com/eslint/eslint/issues/11178 is resolved
5 years ago
Futago-za Ryuu 011b28be03 Upgrade dependencies
- @babel/core
- @babel/preset-env
- rollup
5 years ago
Futago-za Ryuu 9751980261 Remove unrequired ESLint rules 6 years ago
Futago-za Ryuu 4f9cec5937 Ensure .js files always use LF 6 years ago
Futago-za Ryuu 7cf887ec4b Update packages table 6 years ago
Futago-za Ryuu 4723176e20 Update changelog for v0.11 6 years ago
Futago-za Ryuu 104edadf27 website: Fix twitter link 6 years ago
Futago-za Ryuu 93ceeff597 General QOL changes
- Added 'test/package.json' for dependencies used by spec tests
- Changed package names of local tools to reflect actual usage
- Removed bins for local tools (using files via 'node [file]' command)
- Updated help text for the CLIs of local tools to reflect changes
- Updated READMEs for tools
- Moved babel dependencies to 'tools/bundle/package.json'
- 'tools/bundle' now only logs created and watching
- Updated scripts in root package.json
6 years ago
Futago-za Ryuu 4866d6ddb6 Move server.js to website/server.js 6 years ago
Futago-za Ryuu 7deb6a779e Add README for bundle + consmetic changes 6 years ago
Futago-za Ryuu 0f2426bdbf Move dist bundler to tools/bundle 6 years ago
Futago-za Ryuu 6d4ad48319 Remove Gulp 6 years ago
Futago-za Ryuu 1c81df1245 Update MD doc for devs 6 years ago
Futago-za Ryuu 71414cfb19 Update URLs: e.g. spec > development/spec 6 years ago
Futago-za Ryuu aa58b73cae Use ESLint directly instead of gulp-eslint 6 years ago
Futago-za Ryuu 390478d61e Move test/spec to test 6 years ago
Futago-za Ryuu 70a6fab636 Add README for tools/benchmark 6 years ago
Futago-za Ryuu 163ff20508 Move test/benchmark to tools/benchmark 6 years ago
Futago-za Ryuu 9c039ce79b Move test/impact to tools/impact 6 years ago
Futago-za Ryuu 32477337c1 Updated dependencies 6 years ago
Futago-za Ryuu 87dcc13d0f Updated changelog for upcoming 0.11 6 years ago
Futago-za Ryuu e69646cc78 Merge branch 'master' of github.com:pegjs/pegjs 6 years ago
Futago-za Ryuu 2ae32a6510
Merge pull request #587 from psbrandt/patch-1
✍🏼 Fix small typo.
6 years ago
Pascal Brandt d29704ff9c
✍🏼 Fix small typo. 6 years ago
Futago-za Ryuu afc653c46f fix stray spelling error: empry -> empty 6 years ago
Futago-za Ryuu 27687615e5 Document filename option for generated parsers 6 years ago
Futago-za Ryuu d233660161 fix incorrect API reference 6 years ago
Futago-za Ryuu a70fc76648 Update dependencies 6 years ago
Futago-za Ryuu 176f89b9c2
Merge pull request #585 from doersino/patch-1
Fix typo
6 years ago
Noah Doersing 1d2ed4ca22
Fix typo 6 years ago
Futago-za Ryuu 3d755b8196 Update gulpfile.js 6 years ago
Futago-za Ryuu a1b8013b6b Add info for production building 6 years ago
Futago-za Ryuu 4f4af756d3 Fix CBT image width [ci skip] 6 years ago
Futago-za Ryuu 40b7cdfa81 Update lockfile 6 years ago
Futago-za Ryuu fe2237476f Clarify parts of the documentation 6 years ago
Futago-za Ryuu 213c70ced4 Spec Runner cant run on IE11 6 years ago
Futago-za Ryuu 14b8b76a79 runInContext -> evalModule 6 years ago
Futago-za Ryuu 616749377b Fix IE11 Support (#583)
- Revert ES6 changes to arithmetics.pegjs
- Use Array#forEach instead of for..of
- Don't use native Array#find & Array#findIndex
- Added util/arrays.js (find & findIndex)
- Use Function instead of eval
6 years ago
Futago-za Ryuu e636ee654c Update typings (Plucking) 6 years ago
Futago-za Ryuu ec93e64939 Update root README.md: Add packages table 6 years ago
Futago-za Ryuu 9dc4d4a5ef website online/try: serve different example 6 years ago
Futago-za Ryuu fd3dbb77ac Update arithmetics example (Value plucking) 6 years ago
Futago-za Ryuu e0e9fbcd30 Unicode 11 6 years ago
Futago-za Ryuu e64118f3b7 Update src/parser.pegjs
- use value plucking
- remove helpers not needed now
- types in OPS_* are now returned by *Operator
- RESERVED_WORDS is now a `Object<Identifier,true>`
- use ES2015+ JavaScript
- cleanup source code
6 years ago
Futago-za Ryuu 4964b9af7e Add pegjs.org/development/try 6 years ago
Futago-za Ryuu c65e9dd95f Updated dependencies 6 years ago
Futago-za Ryuu 460f0cc5bc Implement value plucking
Resolves #235, #427, #545
6 years ago
Futago-za Ryuu 26969475f7 IdentifierName > Identifier 6 years ago
Futago-za Ryuu 6bc85de256 Define version only in one place 6 years ago
Futago-za Ryuu 4b0f637626 Revert "Ensure VERSION is consistent"
This reverts commit 95abd42c95.
6 years ago
Futago-za Ryuu 8b43c8419f Use input/output from the config file 6 years ago
Futago-za Ryuu 95abd42c95 Ensure VERSION is consistent
The PEG.js version is exported and also written into the generated parser. In both these instances the version is a separate string, which means every time the version is bumped, it has to be changed in 3 places. This commit makes it slightly less of a maintenance burden.
6 years ago
Futago-za Ryuu ecb81504cb Remove redundant __slice
Should have been removed in #f66751b
6 years ago
Futago-za Ryuu aadc318fcd Add a guide for the CLI 6 years ago
Futago-za Ryuu 7813c07025 Fix: global variable is peg, not PEG 6 years ago
Futago-za Ryuu 506419474d Include yarn.lock on zeit.now deployment 6 years ago
Futago-za Ryuu dd044b8cfb remove extronous files 6 years ago
Futago-za Ryuu 46280b3992 Use cdn for jQuery 6 years ago
Futago-za Ryuu dd76ff85d4 Update execution files 6 years ago
Futago-za Ryuu 8c751e6917 Istanbul: only check packages 6 years ago
Futago-za Ryuu 445cdcde44 ensure zeit.now ignores devDependencies 6 years ago
Futago-za Ryuu 2b543ed97a browserify -> rollup 6 years ago
Futago-za Ryuu be88239543 Move PEG.js to packages/pegjs
* Move PEG.js from . to packages/pegjs
* Update relevanr paths
* Remove pegjs-dev; Use pegjs directly
* Generate browser files at packages/pegjs/dist
* nyc: exclude website
* website: keep packages folder
* Root package.json is private now
6 years ago
Futago-za Ryuu 35a650dc50 Update dependency: babelify@v10 6 years ago
Futago-za Ryuu 60c81d1cba Update paths 6 years ago
Futago-za Ryuu 46ce02404f Remove refs to removed files. 6 years ago
Futago-za Ryuu a8d8afbbda Add missing dirs for websites test suites 6 years ago
Futago-za Ryuu f09f2f2cb4 Move CBT logo 6 years ago
Futago-za Ryuu 5e7134936b Merge the test suites into the website 6 years ago
Futago-za Ryuu 4596daae28 Add config for Zeit Now 6 years ago
Futago-za Ryuu dfbfdd350b Import source code for pegjs.org 6 years ago
Futago-za Ryuu 7c93ffb22b Move old changelogs to docs/changelogs [ci skip] 6 years ago
Futago-za Ryuu 8bd4d390a9 Add linkback to CrossBrowserTesting [ci skip] 6 years ago
Futago-za Ryuu 7edc7d902b Merge branch 'master' of github.com:pegjs/pegjs 6 years ago
Futago-za Ryuu f66751ba39 prefer rest and spread 6 years ago
Futago-za Ryuu 60f69d6558 Stop ESLint warnings
- about use of eval
- whitespace before comments
6 years ago
Futago-za Ryuu b92690392e Extend the main .eslintrc.js 6 years ago
Futago-za Ryuu 0089da6698 Use Babel 7 dependencies 6 years ago
Futago-za Ryuu 2790479154 Update dependencies 6 years ago
Futago-za Ryuu 3cedf4439d Update supported platforms
- Drop support for Node.js v4
- Add support for Node.js v10
- Drop support for IE < 11
6 years ago
Futago-za Ryuu 06c9400bca
Update plugins.md 6 years ago
Futago-za Ryuu 4089aac71e Use util.processOptions 6 years ago
Futago-za Ryuu b8db835af9 Refactor vm.runInContext 6 years ago
Futago-za Ryuu 94ca36469b Move compiler/vm.js to util/vm.js 6 years ago
Futago-za Ryuu 146d021d21 Updated keywords for NPM 6 years ago
Futago-za Ryuu fbc8ea2bdf Add an ignore file
The gulp file is usuaully used to glob the JavaScript files and run ESLint on them, but editor based instances of ESLint (e.g. VSCode extension) don't read the gulp file, so can't tell which files to ignore unless specified in the official .eslintignore file.
6 years ago
Futago-za Ryuu b81396a904 Regenerate parser 6 years ago
Futago-za Ryuu b31009f73d Use peg.util.reservedWords 6 years ago
Futago-za Ryuu 01555ebbac Move compiler/js.js to util/js.js 6 years ago
Futago-za Ryuu 8d3dc109ed Rename js.regexpClassEscape to js.regexpEscape 6 years ago
Futago-za Ryuu 878421ab75 Moved seperate utilities into util route. 6 years ago
Futago-za Ryuu 83e3b9edc4 Add missing whitespace to generated parsers 6 years ago
Futago-za Ryuu af917b1e4d Refactor removeProxyRules 6 years ago
Futago-za Ryuu dbdba75b15 run plugins optionally 6 years ago
Futago-za Ryuu 7e10622b9a Update lockfile 6 years ago
Futago-za Ryuu 1fca2daff6 Move processOptions to utils 6 years ago
Futago-za Ryuu b5d01f7505 Test only the latest versions of LTS releases 6 years ago
Futago-za Ryuu c2c823196f Re-generate parser 6 years ago
Futago-za Ryuu 699038c507 Link to doc for plugins 6 years ago
Futago-za Ryuu ab9b8d41bb Add doc for tracer.trace 6 years ago
Futago-za Ryuu 87ad103177 Move nyc options to separate config 6 years ago
Futago-za Ryuu 94a5f24817 Use only Yarn 6 years ago
Futago-za Ryuu b3329e626e Integrate yarn 6 years ago
Futago-za Ryuu 6335818cb7 Gulp 4 6 years ago
Futago-za Ryuu 3745195315 Make the default tracer an optional feature 6 years ago
Futago-za Ryuu 72ba85b3af Use 'visitor.on' instead of 'visitor.for' 6 years ago
Futago-za Ryuu 7cd291cbe0 Add doc for plugins (closes #544) 6 years ago
Futago-za Ryuu 70dea07923 Update twitter link 6 years ago
Futago-za Ryuu 46c3dcf40b Document Session#fatal method 6 years ago
Futago-za Ryuu f4ca7ca461 Remove grammar option for Session API 6 years ago
Futago-za Ryuu 6d25da2d2b Use bare option with browserify 6 years ago
Futago-za Ryuu 126a4c95f4 Update devDependencies
Closes #568
6 years ago
Futago-za Ryuu 2f0680ca16 Restore orignal output on generation fail
If the output file already exists, and the parser generator fails, the result is a empty file. This commit tries  to avoid this pitfall.
6 years ago
Futago-za Ryuu 21a6de06d5 Optional features
This commit enables optional features that are enabled by default in the generated parser.

For now, only some of the helpers and filename are generated based on this new option, but this will change in the future most likely.

Resolves #421
6 years ago
Futago-za Ryuu 15d364587c Update tsd to include changes since 8e9be9a 6 years ago
Futago-za Ryuu 2ac387e1c9 Move documentation
The README.md file in the root of the repository had become too large, and as a result the file became hard to maintain.

This commit extracts all the documentation and moves it to separate but managable files within the docs directory, a new folder also located in the root of the repository.
6 years ago
Futago-za Ryuu 418f441d88 Ignore '.idea' directory 6 years ago
Futago-za Ryuu fedf0f3480 Resolve 'vm.runInContext' bottleneck
Calling 'vm.runInContext'  is slightly more expensive then calling `eval`, but removing the string template and extracting the variable generator helps abit.
6 years ago
Futago-za Ryuu 43a305eaef Clarify templates
- what to chose and do
- remove checkboxs
- all question in comments
- reformat style
6 years ago
Futago-za Ryuu b3135690b0 Not session.fail but session.fatal 6 years ago
Futago-za Ryuu 30cfa29553 Provide context to parser (#517) 6 years ago
Futago-za Ryuu 04dfef3b63 Use error emitter (Closes #430) 6 years ago
Futago-za Ryuu ef0595596f Implement error emitter (Closes #431)
Along with commit 851d8ed, this resolves #431 based on the fact that plugins can overwrite session methods, allowing use cases like multiple or limited errors (and/or warnings) to be an opt-in feature.
6 years ago
Futago-za Ryuu a11d217167 Updated devDependencies 6 years ago
Futago-za Ryuu 621b11b715 Disable no-unused-vars in Session API 6 years ago
Futago-za Ryuu 6500189d58 Report unused rules (Closes #200) 6 years ago
Futago-za Ryuu 851d8edfdd Implement warning emitter (Closes #327) 6 years ago
Futago-za Ryuu f4c67993f6 Added the Session API 6 years ago
Futago-za Ryuu 8e9be9afea Use CommentMap 6 years ago
Futago-za Ryuu 11bc94f4c3 Updated docs for JavaScript API [ci skip]
This includes detials about the 3 main methods a developer will use along with their respective options.

Closes #553
6 years ago
Futago-za Ryuu a5d7cc11a4 ECMA, not ESMA 6 years ago
Futago-za Ryuu fe6f09238a Relay parser opts from peg.generate (#553) 6 years ago
Futago-za Ryuu 8d711627c1 Remove usless refrences to peg 6 years ago
Futago-za Ryuu 269b36b9db Remove redundant glob for linting 6 years ago
Futago-za Ryuu a79757683f Should be 'test/impact master' 6 years ago
Futago-za Ryuu 5476eca59f Moved AST and visitor classes 6 years ago
Futago-za Ryuu f41ef82ce9 Update tsd to include latest changes
These changes are mainly from from @Minigun and @futagoza
6 years ago
Futago-za Ryuu 4b6ceb2b46 Fix plugin test that replaces parser
This test broke down aftert I intergrated the AST utils directly into the Grammar class, then I had problems importing the PEG.js parser to use the Grammar class, but found a workaround using 'process.cwd()'
6 years ago
Futago-za Ryuu b0a5db1ab9 Expose ast classes used by parser 6 years ago
Futago-za Ryuu 9ecb21b749 stripLocation > stripProperties 6 years ago
Futago-za Ryuu 9d266625b4 Merge ast utils into Grammar class 6 years ago
Mingun 1a713d0175 Add some useful debug information to some exceptions (#475)
* Add some useful debug information to some exceptions

* Add guard for visitor functions preventing from cryptic errors due to incomplete visitors

* Add guard for js generator for preventing from cryptic errors due to incarrect stack manipulations
6 years ago
Mingun 0dab14d652 Add ability to extract comments from the grammar (#511)
All comments stored in the `comments` property of the `grammar` node.
Comments extracted only if the `extractComments` options set to `true` when you generate parser.
This property is object with mapping start offset of comment to comment object, that looks like:

```js
{
  text: 'text in the comment, just after // or /* and before */',
  multiline: true|false,// true for /**/ comments, false for // comments
  location: location()
}
```
6 years ago
Futago-za Ryuu b6bc0d905e Use .js files with -c option on CLI
This commit adds support for '.js' files to be passed to the '-c', '--config'  or '--extra-options-file' options on the CLI, allowing the developer to do some extra work before the parser is generated (if they wish), or dynamically set options based on the enviroment.
6 years ago
Futago-za Ryuu d06a5b52ef Restore silentFails guard for rule$expects 6 years ago
Futago-za Ryuu 75a4101622 Some cosmetic changes
- Remove unused '__slice' variable
- Nicely indent a map/concat chain
- 'forEach' instead of 'map' in emitted code
6 years ago
Futago-za Ryuu f5b323b401 Report consistent errors on look ahead + cached results
This should resolve issue #452, and is based entirely on a fix @nikku did on a local branch of PEG.js v0.10.0 (Currently at https://github.com/nikku/pegjs/tree/452-peg-js-0.10-fix).

Also his test case from #555 is included.

Fixes #452, Closes #555
6 years ago
Mingun 9b90fa1d81 Move all codegeneration from `generateBytecode` pass to `generateJs` pass (#459)
* Split 'consts' collection by content types into:

  - literals: for literal expressions, like `"a"`
  - classes: for character class expressions, like `[a]`
  - expectations: for constants describing expected values when parse failed
  - functions: for constants with function code

* Move any JavaScript code generation from 'generateBytecode' to 'generateJs'.
* Rename opcode 'MATCH_REGEXP' to 'MATCH_CLASS' (name reflects purpose, not implementation).
* Replace 'PUSH' opcode with 'PUSH_EMPTY_STRING' opcode because it is only used with empty strings
6 years ago
Futago-za Ryuu 617b6b7425 Updated utils and tsd
- Exposed 'visitor.ASTVisitor'
- Remoed 'util.createVisitor'
- Added type 'peg.SourceLocation'
- Updated tsd for 'peg.compiler.visitor'
- Added tsd for 'peg.util.enforceFastProperties'
- Added tsd for new parser modules
6 years ago
Futago-za Ryuu 27ec5ed9b1 Ensure we are nearly always in fast mode on V8
See: https://stackoverflow.com/a/24989927/1518408
6 years ago
Futago-za Ryuu 7a19d46e8a Add the ASTVisitor class (#451)
For compatibility with pre-0.11 plugins, this class lives on the same namespace as the orignal visitor helper and also exports a static method called 'build'.
6 years ago
Futago-za Ryuu 93cc6c5b26 Parser calls AST node creator now
Before this commit, the PEG.js parser always created the AST using a plain JavaSctript object, but allthough simple and effective for the job, this method sacrificies performance slightly.

From now on the parser shall call a Node creator. This should help with performance, as well as in the future move some AST helpers into the new AST functions.
6 years ago
Futago-za Ryuu 7cdfc03e9f Added utility methods for objects
Before there used to be some internal utility methods for arrays and objects, but as the code base moved to ES5+ use  case only, these were removed in favour of native alternatives, but most of these were only beneficial for arrays.

This commit add's common utility methods for objects, and also exposes these as they can be used by plugin developer's on the PEG.js AST.
6 years ago
Futago-za Ryuu 02486cef7f ignore sh.exe stack trace file 6 years ago
Futago-za Ryuu 1b2072f239 Fix edgecase in gulpfile.js
There seem's to be an edgecase where a spawned process (in this case node.exe it self) is opened and gulp straight away thinks it closed. At first I thought it was a problem with Gulp, but after fiddleing it seem's to be a Window's problem, so I just updated the `node()` spawner to work on all platforms by using Gulp's callback to create an async task. Problem solved :)
6 years ago
Futago-za Ryuu b0056d7a9f Merge branch 'master' of github.com:pegjs/pegjs 6 years ago
Mingun 4cc9185a78 Improve error when reserved word used as label (#552)
Before this commit error looks like (for input `start = break:'a'`)

> Expected "!", "$", "&", "(", "*", "+", ".", "/", "/*", "//", ";", "?", character class, code block, comment, end of line, identifier, literal, or whitespace but ":" found.

After this error looks like

> Label can't be a reserved word "break".
6 years ago
Futago-za Ryuu 1434346332 Move require statement to the top 6 years ago
Futago-za Ryuu 93f9068c99 Updated tsd for compiler passes [ci skip] 6 years ago
Mingun fde1c480f4 Use chai-like instead of own properties matcher (#550) 6 years ago
Mingun a480c7d39c Excess points are deleted from the PR template (#551)
They already covered by `lint` and `test` checks [ci skip]
6 years ago
Mingun 534dc53ac2 Optimize redundant fail checks (#400)
eliminate unnecessary checks for the result of parse, when it can be statically determined
6 years ago
Futago-za Ryuu f5699d63fb Updated devDependencies
- Bump: eslint-config-futagozaryuu@3.8
- Bump:  run-sequence@2.2.1
6 years ago
Futago-za Ryuu cb385476c1 Updated header for generated browser files
The 'broser/*.js' files should now include the 'eslint-disable' comment directive.
6 years ago
Futago-za Ryuu 92f1798308 Moved Babel options to .babelrc 6 years ago
Futago-za Ryuu 06f1565a32 tsd: Added NotExpectation interface 6 years ago
Mingun 42ec335d13 Optimize silent fails: remove checks that always false (#399)
* Optimization: do not generate unreachable calls |peg$fail| and constants for it (local to the rule).
* Optimization: do not generate unreachable calls |peg$fail| and constants for it (non-local to rule).
6 years ago
Mingun a7a0a0d9ac Bump devDependencies (#549)
- Removed: babel-preset-es2015@6.24.1
- Added: babel-preset-env@1.6.1
- Updated: gulp-mocha@5.0.0
- Updated: nyc@11.4.1
- Updated: vinyl-buffer@1.0.1
- Updated: vinyl-source-stream@2.0.0
6 years ago
Mingun 669f782a5f Partial fix #194 - nonsenses error messages with semantic predicates (#547)
* Remove stack manipulations from FAIL opcode and rename FAIL to EXPECT
* Always save the expected values regardless of the match result of expression
* Remove unnecessary check for match result in the `named` node
* Collect and process expectations from predicates
6 years ago
Futago-za Ryuu 1b20aa5427 Ensure usage of 'lib/peg.d.ts'
This commit ensures that all modules outside 'lib' are importing 'lib/peg.js' so that VS Code automatically gets 'lib/peg.d.ts'.

An alias module for 'lib/peg.js' called 'pegjs-dev' was made for test files at 'test/node_modules/pegjs-dev.js'
6 years ago
Futago-za Ryuu 03cc2eae95 Added 'lib/peg.d.ts' for internal use 6 years ago
Futago-za Ryuu ea688abd02 Fix shadowing issue on UMD format (#499) 6 years ago
Futago-za Ryuu cd02806c94 Moved 'package.json:repository' field 6 years ago
Futago-za Ryuu 95409f0155 Moved Github related documents 6 years ago
Futago-za Ryuu 01a2be7b78 Removed 'gulp benchmark' from default tasks 6 years ago
Futago-za Ryuu d3cbbee592 Added .d.ts declaration files (#519) 6 years ago
Futago-za Ryuu a02f8091e3
Merge pull request #541 from Mingun/correct-options-in-tests
Auto-add `allowedStartRules` to test options for `changeAST` method if it not defined
6 years ago
Mingun 3e89534bb7 Auto-add `allowedStartRules` to test options for `changeAST` and `reportError` methods if it not defined 6 years ago
Futago-za Ryuu 75d655409c
Merge pull request #546 from Mingun/coverage
Add code coverage by Istanbul and coveralls.io
6 years ago
Mingun 3f8cf7cd58 Add coveralls.io support 6 years ago
Mingun f0e5eebe1a Add code coverage by Intanbul 6 years ago
Futago-za Ryuu d6142772f8 Switch dev to pegjs@dev [ci skip] 6 years ago
Futago-za Ryuu 1dd1487f9b Set version to v0.11.0-dev 6 years ago
Futago-za Ryuu db70215c4a Added 'header' option (#491) 6 years ago
Futago-za Ryuu 247a0bf707 Removed non-LTS versions of Node.js 6 years ago
Futago-za Ryuu f7dd11698a Updates devDependencies
- eslint-config-futagozaryuu
- sinon
6 years ago
Futago-za Ryuu 2a7dcdcfbe Changed 'bin/usage.txt' to 'bin/usage.js'
This change ensures the usage text always has LF line ending on Linux
7 years ago
Futago-za Ryuu 881eb67545 Removed redundant css files
The css files used in the benchmark contained 2 files for IE that contained syntax errors. These files weren't actually used by the benchmark, but were still in the repository.
7 years ago
Futago-za Ryuu a33eb0b45c Updated contribution section 7 years ago
Futago-za Ryuu 30d39f6267 Added PR Template
Based on the example at https://github.com/stevemao/github-issue-templates/tree/master/checklist2
7 years ago
Futago-za Ryuu 280466cc7b Added Issue Template
Based on the example at https://github.com/stevemao/github-issue-templates/tree/master/checklist2
7 years ago
Futago-za Ryuu 9568522d9c Move guidelines to docs folder 7 years ago
Futago-za Ryuu 123a20a83c Updated ignored and published files 7 years ago
Futago-za Ryuu 37698d8981 Updated NPM scripts & Gulp tasks
- updated names & ordering
- set "gulp clean" to also remove generated examples
- added "gulp lint" to list of default tasks
7 years ago
Futago-za Ryuu b4e5b97a2e Disabled eslint rule 'prefer-spread' 7 years ago
Futago-za Ryuu 5f0001c3e5 Fix compatibility for older bins 7 years ago
Futago-za Ryuu e6d018a88d Update code format and style
This is related to my last commit. I've updated all the JavaScript files to satisfy 'eslint-config-futagozaryuu', my eslint configuration.

I'm sure I've probally missed something, but I've run all NPM scripts and Gulp tasks, fixed any bugs that cropped up, and updated some stuff (mainly related to generated messages), so as far as I can, tell this conversion is over (I know I've probally jixed it just by saying this ;P).
7 years ago
Futago-za Ryuu 3c6523ff83 Switched eslint configuration
Was using 'eslint-config-dmajda' by @dmajda, but since it's diffucult for me to use multiple styles across multiple projects, I'm switching to my own 'eslint-config-futagozaryuu'.
7 years ago
Futago-za Ryuu 50cbcd6704 Updated devDependencies
Was planning on doing this after 0.11 (see #497), but since I'm doing an overhaul of the development files now instead, might as well...
7 years ago
Futago-za Ryuu 35832f474f Updated gulpfile.js
- Updated glob for test files
- Updated HEADER var for generated browser build
- Inlined list of JS_FILES to lint
- Added helper 'execFile'
- Simplyfied 'gulp benchmark'
- Parser generator now use's 'bin/peg.js'
- Moved HEADER var into 'browser:build' function
- Simplyfied 'gulp browser:clean'
- removed dependency 'gulp-transform'
7 years ago
Futago-za Ryuu 9802bae15f test/impact: Add compatibility for older bin files
This ensures the impact test doesn't throw when testing against older commits that contain the bin files at their orignal locations.
7 years ago
Futago-za Ryuu abadaf4d5d Add test for empty grammars
This add's a test that ensures grammars without any rules are not accepted.
7 years ago
Futago-za Ryuu 96a386ff15 Merged documents for test suites 7 years ago
Futago-za Ryuu 5c36738a52 Rewrote test/impact as a Node.js script
"test/impact" was a bash script before, and used tools spefic to some systems, which required Window users to have more software installed.

This rewrite removes the bash script and add's a cross platform Node.js script that doesn't depend on platform-spefic tools.
7 years ago
Futago-za Ryuu 08bbd6d5b6 Moved "eslint-env node" to the root
It seem's kind of pointless setting the comment "/* eslint-env node */" at the top of only some JavaScript files when nearly all of them are Node.js releated, so I moved this option to the root level config, only leaving the 'lib' folder as "/* eslint-env commonjs */"
7 years ago
Futago-za Ryuu 5a833bd982 Moved all spec and benchmark tests
- Moved benchmark to test/benchmark
- Moved tests to test/spec
- Removed individual servers
- Implemented single test server
- Moved server assets to test/server
- Updated Gulpfile.js
- Moved tools/impact to test/impact

This commit move's nearly all code related to testing the PEG.js module into the test directory, and also ensures they run as they did before the move.
7 years ago
Futago-za Ryuu a1ad351c2c Add extension for bin file
Fixes #535 (again ...)
7 years ago
Futago-za Ryuu 14948dad93 Update files field to include bin files
Closes #529, Fixes #535
7 years ago
felix 6a9a9a5d23 Add more explanation of balanced braces (#533) 7 years ago
felix cb3c5f4473 Improve error message for unbalanced brace. (#534)
Currently, an open brace without a corresponding brace will emit this confusing error message:

> Expected "!", "$", "&", "(", "*", "+", ".", "/", "/*", "//", ";", "?", character class, code block, comment, end of line, identifier, literal, or whitespace but "{" found.

This change adds an error case to the grammar to make it clear what the problem is.
7 years ago
felix 369b8cdcc6 Clarify details for the execution environment for actions (#531)
* Clarify execution environment of actions and predicates
* Makes a new section for describing the common execution environment
* Add the new section to TOC
* Clarify start/end for predicates
* Clarify the scope of labels
7 years ago
felix ee00a1ae6a Check allowedStartRules exist. (#532)
Fixes #524
7 years ago
felix 958e15879d Reimplement offset() and add range(). (#528)
* Reimplement offset()
* Implement range()

Fixes #526, thanks @felix9
7 years ago
Futago-za Ryuu 5cde815341 Add default export for es format.
This is a minor addition that add's a default export statement (e.g. `export default { ... };`) for the es output format.

Fixes #525
7 years ago
Alan Mimms 4cdc6d6353 Do not indent backtick quoted strings in code blocks (#492)
* Do not indent backtick quoted strings in initializer or rule action code blocks
* Use const instead of var for ESLint happiness
* Fix ESLint issues for double quotes and indent6
7 years ago
Futago-za Ryuu 57bb28414e Merge pull request #509 from Mingun/simplify-bc
Simplify bytecode: remove unnecessary opcode.
7 years ago
Futago-za Ryuu 0ed8c6f89a Rewrote command line tool
- Split into 3 files: "peg.js", "options.js" and "usage.txt"
- Rewrote arguments parser and helpers to be more precise
- Any arguments after "--" will be passed to "options['--']" now
- Added negation options: "--no-cache" and "--no-trace"
- Added "bare" to accepted module formats
- Added 2 aliases for "--extra-options-file": "-c" and "--config"
- Added short options: "-a", "-f" and "-p"
- Reformatted help text in "usage.txt"
- Updated documentation related to command line options and normal options
- Changed "bin" field in "package.json" from "bin/pegjs" to "bin/peg"
- Added documentation note about command line options that are repeated
- Updated gulpfile.js, replacing "bin/pegjs" with "bin/*.js"

See #429, which was what I intended to fix/solve, but instead pushed back and did this instead.
7 years ago
Futago-za Ryuu d7d5f375f1 Removed redundant .eslintrc
See 55bcaa46ef
7 years ago
Futago-za Ryuu 48a0c37997 Fix link for dot character [ci skip] 7 years ago
Futago-za Ryuu 6661f6b958 Updated documentation
- Updated Badges
- Moved the introduction back to the top
- Added a title for the TOC list
- Added "Latest" sub-section (closes #521)
- Added "Case-insensitivity" sub-section (see #518)
- Added "Backtracking" sub-section (closes #438)
- Fixed link for . (dot character)
- Added a title for the links in the development section
- Added "Contribution" sub-section (closses #457)
- Updated the TOC list
7 years ago
Futago-za Ryuu b926be7d71 Added npm scripts for gulp tasks 7 years ago
Futago-za Ryuu dcf9790da0 Ensure 'package-lock.json' is never created
I've noticed on Travis that if a project is testing on Node.js 8 then NPM will automatically create the 'package-lock.json' file, but it's best not to use this file yet.

See 10ec7f0576
7 years ago
Futago-za Ryuu 30ea7d5ed0 Fix "gulp benchmark" for Windows
I'm presuming this task worked fine on Linux, but I use a Windows 10 laptop, and since Windows doesn't open extensionless files to check their shebang, this task failed.

Node.js on the other hand ignore's JavaScript files with a shebang, so this simple fix should make it work on all platforms now.
7 years ago
Futago-za Ryuu 55bcaa46ef Updated ESLint configuration files
- added "root" option to main config
- moved "env.commonjs" to root
7 years ago
Futago-za Ryuu 10ec7f0576 Removed `package-lock.json`
See npm/npm#16866
7 years ago
Futago-za Ryuu 8cf81b47b7 Ensure bin/*.js files use LF instead of CRLF 7 years ago
Futago-za Ryuu 1afe682c65 Merge pull request #510 from Mingun/group-location
Add location information to group AST node
7 years ago
Mingun c98fee1629 Add location information to group AST node 7 years ago
Mingun 575db38d1f Simplify bytecode: remove unnecessary opcode.
Now generated sources looks little better :)
7 years ago
Futago-za Ryuu 03912dc761 Create CODE_OF_CONDUCT.md 7 years ago
Futago-za Ryuu 928fdca6ac Added TOC's [skip ci] 7 years ago
Futago-za Ryuu 8856913ae8 Updated maintainer #503 7 years ago
Futago-za Ryuu 9658f4a92d Added package-lock.json 7 years ago
Futago-za Ryuu 081856cdeb Set "linebreak-style" rule to 0 7 years ago
Futago-za Ryuu 5e3ed79f95 Merge pull request #415 from sampsyo/master
Docs: try to explain error messages
7 years ago
Futago-za Ryuu 6939d1eb8d Merge pull request #481 from fatfisz/esm-support
Add support for ES modules
7 years ago
Futago-za Ryuu bc5c8a0f97 Add support for testing with Node.js 8 7 years ago
fatfisz 9c60380f86 Add info about es to the cmd tool 7 years ago
fatfisz d1f62596f1 Add info about the "es" target to the README 7 years ago
fatfisz c541911c04 Extract formats into array
Previously there was a very long condition.
7 years ago
fatfisz e3b7f0c3a9 Change "esm" to "es" 7 years ago
fatfisz aab928de91 Add support for ES modules 7 years ago
Futago-za Ryuu 35f3c5267a Merge pull request #490 from chearon/css-num-fix
CSS example: parse decimal form of nums correctly
7 years ago
Futago-za Ryuu f18cf30d76 Merge pull request #493 from AdhirRamjiawan/master
spelling error
7 years ago
Futago-za Ryuu 91c85d824d Merge pull request #494 from davidberneda/patch-1
Update arithmetics.pegjs
7 years ago
Futago-za Ryuu 624f87f66b README.md: Remove the notice about looking for a new maintainer [ci skip]
PEG.js has [a new maintainer](https://github.com/pegjs/pegjs/issues/503#issuecomment-303004127).
7 years ago
David Majda ba2f8bf3c2 README.md: Add a notice about looking for a new maintainer 7 years ago
David Berneda 962db9d090 Update arithmetics.pegjs
Allow spacing before digits like: "     2 * (3 + 4)"
7 years ago
Adhir Ramjiawan f861c2f476 spelling error 7 years ago
Caleb Hearon 770ca6e723 CSS example: parse decimal form of nums correctly
Before, 0.02 could get parsed as 0 and 0.02 when looking for nums+
7 years ago
Adrian Sampson ceebc8cda1 Better error position explanation
Based on @Mingun's help.
8 years ago
Adrian Sampson 3330ceb7b8 Docs: try to explain error messages (#368) 8 years ago

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

@ -0,0 +1,8 @@
!.eslintrc.js
/.idea
/.nyc_output
/public
/packages/pegjs/dist
/coverage
node_modules
/website/assets

@ -0,0 +1,37 @@
"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,
};

@ -1,3 +0,0 @@
{
"extends": "dmajda"
}

@ -0,0 +1,46 @@
# 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,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 (`gulp test`) and
ESLint checks (`gulp lint`).
Before submitting, make sure your change passes the tests (`yarn test`) and
ESLint checks (`yarn lint`).
[issues]: https://github.com/pegjs/pegjs/issues
[issues-search-bugs]: https://github.com/pegjs/pegjs/issues?q=is%3Aopen+is%3Aissue+label%3ABug

@ -0,0 +1,54 @@
### 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:**

@ -0,0 +1,20 @@
### 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 -->

@ -0,0 +1,87 @@
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 }}

14
.gitignore vendored

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

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

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

@ -1,16 +0,0 @@
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,618 +1,95 @@
Change Log
==========
* 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
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
> This is a work in progress changelog for the next release _(currently v0.11)_.
### 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).
* [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))
### 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.
[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.
* 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

@ -1,6 +1,7 @@
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,527 +1,64 @@
[![Build status](https://img.shields.io/travis/pegjs/pegjs.svg)](https://travis-ci.org/pegjs/pegjs)
[![npm version](https://img.shields.io/npm/v/pegjs.svg)](https://www.npmjs.com/package/pegjs)
[![Bower version](https://img.shields.io/bower/v/pegjs.svg)](https://github.com/pegjs/bower)
[![License](https://img.shields.io/badge/license-mit-blue.svg)](https://opensource.org/licenses/MIT)
PEG.js
======
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.
Features
--------
* Simple and expressive grammar syntax
* Integrates both lexical and syntactical analysis
* Parsers have excellent error reporting out of the box
* Based on [parsing expression
grammar](http://en.wikipedia.org/wiki/Parsing_expression_grammar) formalism
— more powerful than traditional LL(*k*) and LR(*k*) parsers
* Usable [from your browser](https://pegjs.org/online), from the command line,
or via JavaScript API
Getting Started
---------------
[Online version](https://pegjs.org/online) is the easiest way to generate a
parser. Just enter your grammar, try parsing few inputs, and download generated
parser code.
Installation
------------
### Node.js
To use the `pegjs` command, install PEG.js globally:
```console
$ npm install -g pegjs
```
To use the JavaScript API, install PEG.js locally:
```console
$ npm install pegjs
```
If you need both the `pegjs` command and the JavaScript API, install PEG.js both
ways.
### Browser
[Download](https://pegjs.org/#download) the PEG.js library (regular or minified
version) or install it using Bower:
```console
$ bower install pegjs
```
Generating a Parser
-------------------
PEG.js generates parser from a grammar that describes expected input and can
specify what the parser returns (using semantic actions on matched parts of the
input). Generated parser itself is a JavaScript object with a simple API.
### Command Line
To generate a parser from your grammar, use the `pegjs` command:
```console
$ pegjs arithmetics.pegjs
```
This writes parser source code into a file with the same name as the grammar
file but with “.js” extension. You can also specify the output file explicitly:
```console
$ pegjs -o arithmetics-parser.js arithmetics.pegjs
```
If you omit both input and output file, standard input and output are used.
By default, the generated parser is in the Node.js module format. You can
override this using the `--format` option.
You can tweak the generated parser with several options:
* `--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`
* `--format` — format of the generated parser: `amd`, `commonjs`, `globals`,
`umd` (default: `commonjs`)
* `--optimize` — selects between optimizing the generated parser for parsing
speed (`speed`) or code size (`size`) (default: `speed`)
* `--plugin` — makes PEG.js use a specified plugin (can be specified multiple
times)
* `--trace` — makes the parser trace its progress
### JavaScript API
In Node.js, require the PEG.js parser generator module:
```javascript
var peg = require("pegjs");
```
In browser, 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.
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; valid only when `format` is set to `"amd"`, `"commonjs"`, or
`"umd"` (default: `{}`)
* `exportVar` — name of a global variable into which the parser object is
assigned to when no module loader is detected; valid only when `format` is
set to `"globals"` or `"umd"` (default: `null`)
* `format` — format of the genreated parser (`"amd"`, `"bare"`, `"commonjs"`,
`"globals"`, or `"umd"`); valid only when `output` is set to `"source"`
(default: `"bare"`)
* `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
Development
-----------
* [Project website](https://pegjs.org/)
* [Wiki](https://github.com/pegjs/pegjs/wiki)
* [Source code](https://github.com/pegjs/pegjs)
* [Issue tracker](https://github.com/pegjs/pegjs/issues)
* [Google Group](http://groups.google.com/group/pegjs)
* [Twitter](http://twitter.com/peg_js)
PEG.js is developed by [David Majda](https://majda.cz/)
([@dmajda](http://twitter.com/dmajda)). The [Bower
package](https://github.com/pegjs/bower) is maintained by [Michel
Krämer](http://www.michel-kraemer.com/)
([@michelkraemer](https://twitter.com/michelkraemer)).
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 GitHub pull request.
Note that PEG.js is still very much work in progress. There are no compatibility
guarantees until version 1.0.
![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

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

@ -1,50 +0,0 @@
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.

@ -1,42 +0,0 @@
"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;

@ -1,35 +0,0 @@
/* -----------------------------------------------------------------------
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;}

@ -1,76 +0,0 @@
/* --------------------------------------------------------------
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; }

@ -1,40 +0,0 @@
<!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>

@ -1,138 +0,0 @@
"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) {
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();
});

@ -1,198 +0,0 @@
#!/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();
}
});

@ -1,118 +0,0 @@
"use strict";
/* global setTimeout */
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;

@ -1,36 +0,0 @@
#!/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: "es2015", compact: false })
.bundle()
.pipe(res);
});
app.listen(8000, () => {
console.log("Benchmark server running at http://localhost:8000...");
});

@ -1,22 +0,0 @@
(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.

@ -1,7 +0,0 @@
/**
* 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});

@ -1,36 +0,0 @@
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

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

@ -1,326 +0,0 @@
#!/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();
}
});

@ -0,0 +1,14 @@
* [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)_

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

@ -0,0 +1,60 @@
> 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.

@ -0,0 +1,10 @@
> 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).

@ -0,0 +1,14 @@
> 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.

@ -0,0 +1,24 @@
> 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.

@ -0,0 +1,38 @@
> 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`.

@ -0,0 +1,37 @@
> 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`.

@ -0,0 +1,36 @@
> 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`.

@ -0,0 +1,38 @@
> 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.

@ -0,0 +1,29 @@
> 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.

@ -0,0 +1,10 @@
## 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

@ -0,0 +1,32 @@
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).

@ -0,0 +1,72 @@
## 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.

@ -0,0 +1,49 @@
### 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).

@ -0,0 +1,20 @@
### 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).

@ -0,0 +1,12 @@
### 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
}
```

@ -0,0 +1,13 @@
### 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
```

@ -0,0 +1,42 @@
### 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.

@ -0,0 +1,136 @@
### 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"]`

@ -0,0 +1,20 @@
### 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

@ -0,0 +1,70 @@
## 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.

@ -0,0 +1,27 @@
## 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.

@ -0,0 +1,10 @@
## 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)

@ -0,0 +1,41 @@
## 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>
```

@ -0,0 +1,135 @@
## 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()`)_

@ -0,0 +1,34 @@
## 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

@ -0,0 +1,19 @@
## 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[1] === "+") { return result + element[3]; }
if (element[1] === "-") { return result - element[3]; }
if (element[0] === "+") return result + element[1];
if (element[0] === "-") return result - element[1];
}, head);
}
Term
= head:Factor tail:(_ ("*" / "/") _ Factor)* {
= head:Factor tail:(_ @("*" / "/") _ @Factor)* {
return tail.reduce(function(result, element) {
if (element[1] === "*") { return result * element[3]; }
if (element[1] === "/") { return result / element[3]; }
if (element[0] === "*") return result * element[1];
if (element[0] === "/") return result / element[1];
}, head);
}
Factor
= "(" _ expr:Expression _ ")" { return expr; }
= "(" _ @Expression _ ")"
/ 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/8.0.0/ucd/extracted/DerivedGeneralCategory.txt
// http://www.unicode.org/Public/11.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\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]
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]
// 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\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]
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]
// 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\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]
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]
// 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\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\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]
// 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\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]
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]
// 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]

@ -1,108 +0,0 @@
"use strict";
/* eslint-env node */
let babelify = require("babelify");
let browserify = require("browserify");
let buffer = require("vinyl-buffer");
let del = require("del");
let eslint = require("gulp-eslint");
let gulp = require("gulp");
let header = require("gulp-header");
let mocha = require("gulp-mocha");
let package_ = require("./package");
let peg = require("./lib/peg");
let rename = require("gulp-rename");
let runSequence = require("run-sequence");
let source = require("vinyl-source-stream");
let spawn = require("child_process").spawn;
let transform = require("gulp-transform");
let uglify = require("gulp-uglify");
const HEADER = [
"// PEG.js " + package_.version,
"//",
"// https://pegjs.org/",
"//",
"// Copyright (c) 2010-2016 David Majda",
"// Licensed under the MIT License.",
""
].map(line => `${line}\n`).join("");
const JS_FILES = [
"lib/**/*.js",
"!lib/parser.js",
"test/**/*.js",
"test/server",
"!test/vendor/**/*",
"benchmark/**/*.js",
"benchmark/run",
"benchmark/server",
"!benchmark/vendor/**/*",
"bin/pegjs",
"gulpfile.js"
];
const TEST_FILES = [
"test/**/*.js",
"!test/vendor/**/*"
];
function generate(contents) {
return peg.generate(contents.toString(), {
output: "source",
format: "commonjs"
});
}
// Run ESLint on all JavaScript files.
gulp.task("lint", () =>
gulp.src(JS_FILES)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
);
// Run tests.
gulp.task("test", () =>
gulp.src(TEST_FILES, { read: false })
.pipe(mocha())
);
// Run benchmarks.
gulp.task("benchmark", () =>
spawn("benchmark/run", { stdio: "inherit" })
);
// Create the browser build.
gulp.task("browser:build", () =>
browserify("lib/peg.js", { standalone: "peg" })
.transform(babelify, { presets: "es2015", compact: false })
.bundle()
.pipe(source("peg.js"))
.pipe(header(HEADER))
.pipe(gulp.dest("browser"))
.pipe(rename({ suffix: ".min" }))
.pipe(buffer())
.pipe(uglify())
.pipe(header(HEADER))
.pipe(gulp.dest("browser"))
);
// Delete the browser build.
gulp.task("browser:clean", () =>
del("browser")
);
// Generate the grammar parser.
gulp.task("parser", () =>
gulp.src("src/parser.pegjs")
.pipe(transform(generate))
.pipe(rename({ extname: ".js" }))
.pipe(gulp.dest("lib"))
);
// Default task.
gulp.task("default", cb =>
runSequence("lint", "test", cb)
);

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

@ -1,76 +0,0 @@
"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;

@ -1,91 +0,0 @@
"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) {
let processedOptions = {};
Object.keys(options).forEach(name => {
processedOptions[name] = options[name];
});
Object.keys(defaults).forEach(name => {
if (!Object.prototype.hasOwnProperty.call(processedOptions, name)) {
processedOptions[name] = defaults[name];
}
});
return processedOptions;
}
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) {
options = options !== undefined ? options : {};
options = processOptions(options, {
allowedStartRules: [ast.rules[0].name],
cache: false,
dependencies: {},
exportVar: null,
format: "bare",
optimize: "speed",
output: "parser",
trace: false
});
Object.keys(passes).forEach(stage => {
passes[stage].forEach(p => { p(ast, options); });
});
switch (options.output) {
case "parser":
return eval(ast.code);
case "source":
return ast.code;
default:
throw new Error("Invalid output format: " + options.output + ".");
}
}
};
module.exports = compiler;

@ -1,54 +0,0 @@
"use strict";
function hex(ch) { return ch.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;

@ -1,54 +0,0 @@
"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;

@ -1,618 +0,0 @@
"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

@ -1,39 +0,0 @@
"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;

@ -1,62 +0,0 @@
"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;

@ -1,28 +0,0 @@
"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;

@ -1,54 +0,0 @@
"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;

@ -1,33 +0,0 @@
"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;

@ -1,23 +0,0 @@
"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;

@ -1,75 +0,0 @@
"use strict";
// Simple AST node visitor builder.
let visitor = {
build(functions) {
function visit(node) {
return functions[node.type].apply(null, arguments);
}
function visitNop() {
// Do nothing.
}
function visitExpression(node) {
let extraArgs = Array.prototype.slice.call(arguments, 1);
visit.apply(null, [node.expression].concat(extraArgs));
}
function visitChildren(property) {
return function(node) {
let extraArgs = Array.prototype.slice.call(arguments, 1);
node[property].forEach(child => {
visit.apply(null, [child].concat(extraArgs));
});
};
}
const DEFAULT_FUNCTIONS = {
grammar(node) {
let extraArgs = Array.prototype.slice.call(arguments, 1);
if (node.initializer) {
visit.apply(null, [node.initializer].concat(extraArgs));
}
node.rules.forEach(rule => {
visit.apply(null, [rule].concat(extraArgs));
});
},
initializer: visitNop,
rule: visitExpression,
named: visitExpression,
choice: visitChildren("alternatives"),
action: visitExpression,
sequence: visitChildren("elements"),
labeled: visitExpression,
text: visitExpression,
simple_and: visitExpression,
simple_not: visitExpression,
optional: visitExpression,
zero_or_more: visitExpression,
one_or_more: visitExpression,
group: visitExpression,
semantic_and: visitNop,
semantic_not: visitNop,
rule_ref: visitNop,
literal: visitNop,
class: visitNop,
any: visitNop
};
Object.keys(DEFAULT_FUNCTIONS).forEach(type => {
if (!Object.prototype.hasOwnProperty.call(functions, type)) {
functions[type] = DEFAULT_FUNCTIONS[type];
}
});
return visit;
}
};
module.exports = visitor;

@ -1,16 +0,0 @@
"use strict";
// Thrown when the grammar contains an error.
class GrammarError {
constructor(message, location) {
this.name = "GrammarError";
this.message = message;
this.location = location;
if (typeof Error.captureStackTrace === "function") {
Error.captureStackTrace(this, GrammarError);
}
}
}
module.exports = GrammarError;

File diff suppressed because one or more lines are too long

@ -1,54 +0,0 @@
"use strict";
let GrammarError = require("./grammar-error");
let compiler = require("./compiler");
let parser = require("./parser");
let peg = {
// PEG.js version (uses semantic versioning).
VERSION: "0.10.0",
GrammarError: GrammarError,
parser: parser,
compiler: compiler,
// Generates a parser from a specified grammar and returns it.
//
// The grammar must be a string in the format described by the metagramar in
// the parser.pegjs file.
//
// Throws |peg.parser.SyntaxError| if the grammar contains a syntax error or
// |peg.GrammarError| if it 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.
generate(grammar, options) {
options = options !== undefined ? options : {};
function convertPasses(passes) {
let converted = {};
Object.keys(passes).forEach(stage => {
converted[stage] = Object.keys(passes[stage])
.map(name => passes[stage][name]);
});
return converted;
}
let plugins = "plugins" in options ? options.plugins : [];
let config = {
parser: peg.parser,
passes: convertPasses(peg.compiler.passes)
};
plugins.forEach(p => { p.use(config, options); });
return peg.compiler.compile(
config.parser.parse(grammar),
config.passes,
options
);
}
};
module.exports = peg;

@ -0,0 +1,21 @@
{
"version": 2,
"name": "pegjs",
"alias": [
"pegjs.org",
"www.pegjs.org"
],
"routes": [
{
"handle": "filesystem"
},
{
"src": "/",
"dest": "/index.html"
},
{
"src": "/([^\\.*]+)",
"dest": "/$1.html"
}
]
}

@ -1,71 +1,35 @@
{
"name": "pegjs",
"version": "0.10.0",
"description": "Parser generator for JavaScript",
"keywords": [
"parser generator",
"PEG"
],
"homepage": "https://pegjs.org/",
"bugs": "https://github.com/pegjs/pegjs/issues",
"license": "MIT",
"author": "David Majda <david@majda.cz> (https://majda.cz/)",
"files": [
"CHANGELOG.md",
"LICENSE",
"README.md",
"bin/pegjs",
"examples/arithmetics.pegjs",
"examples/css.pegjs",
"examples/javascript.pegjs",
"examples/json.pegjs",
"lib/compiler/asts.js",
"lib/compiler/index.js",
"lib/compiler/js.js",
"lib/compiler/opcodes.js",
"lib/compiler/passes/generate-bytecode.js",
"lib/compiler/passes/generate-js.js",
"lib/compiler/passes/remove-proxy-rules.js",
"lib/compiler/passes/report-duplicate-labels.js",
"lib/compiler/passes/report-duplicate-rules.js",
"lib/compiler/passes/report-infinite-recursion.js",
"lib/compiler/passes/report-infinite-repetition.js",
"lib/compiler/passes/report-undefined-rules.js",
"lib/compiler/visitor.js",
"lib/grammar-error.js",
"lib/parser.js",
"lib/peg.js",
"package.json"
],
"main": "lib/peg",
"bin": "bin/pegjs",
"repository": "pegjs/pegjs",
"scripts": {
"test": "gulp"
},
"devDependencies": {
"babel-preset-es2015": "6.14.0",
"babelify": "7.3.0",
"browserify": "13.1.0",
"chai": "3.5.0",
"del": "2.2.2",
"eslint-config-dmajda": "1.0.0",
"express": "4.14.0",
"glob": "7.0.6",
"gulp": "3.9.1",
"gulp-eslint": "3.0.1",
"gulp-header": "1.8.8",
"gulp-mocha": "3.0.1",
"gulp-rename": "1.2.2",
"gulp-transform": "1.0.8",
"gulp-uglify": "2.0.0",
"morgan": "1.7.0",
"run-sequence": "1.2.2",
"sinon": "1.17.6",
"vinyl-buffer": "1.0.0",
"vinyl-source-stream": "1.1.0"
},
"engines": {
"node": ">=4"
}
"name": "pegjs-dev",
"private": true,
"workspaces": [
"packages/*",
"tools/*",
"test",
"website"
],
"scripts": {
"lint": "eslint --ext .js .",
"spec": "mocha --reporter progress",
"benchmark": "node tools/benchmark",
"build-parser": "pegjs -c src/pegjs.config.js",
"build-dist": "bundle",
"build-website": "node website/export",
"clean": "rimraf public packages/pegjs/dist examples/*.js",
"impact": "node tools/impact master",
"build": "node website/export --fresh",
"test": "nyc mocha",
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov"
},
"dependencies": {
"@futagoza/eslint-config": "11.2.0",
"@types/node": "8",
"codecov": "3.6.1",
"eslint": "6.6.0",
"mocha": "6.2.2",
"nyc": "14.1.1",
"rimraf": "3.0.0"
},
"engines": {
"node": ">= 8"
}
}

@ -0,0 +1,22 @@
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
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,35 @@
![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
## features
* Simple and expressive grammar syntax
* Integrates both lexical and syntactical analysis
* Parsers have excellent error reporting out of the box
* Based on [parsing expression grammar](http://en.wikipedia.org/wiki/Parsing_expression_grammar) formalism - more powerful than traditional LL(*k*) and LR(*k*) parsers
* Usable [from your browser](https://pegjs.org/online), from the command line, or via JavaScript API
## documentation
- [Getting Started](https://github.com/pegjs/pegjs/blob/master/docs/guides/getting-started.md)
- [Installation](https://github.com/pegjs/pegjs/blob/master/docs/guides/installation.md)
- [Generating a Parser](https://github.com/pegjs/pegjs/blob/master/docs/guides/generating-a-parser.md)
- [Using the Parser](https://github.com/pegjs/pegjs/blob/master/docs/guides/using-the-parser.md)
- [Grammar Syntax and Semantics](https://github.com/pegjs/pegjs/tree/master/docs/grammar)
- [JavaScript API](https://github.com/pegjs/pegjs/blob/master/docs/guides/javascript-api.md)
- [Plugins](https://github.com/pegjs/pegjs/blob/master/docs/guides/plugins.md)
- [Compatibility](https://github.com/pegjs/pegjs/blob/master/docs/compatibility.md)
- [Development](https://github.com/pegjs/pegjs/blob/master/docs/development.md)
## license
Released under the [MIT License](https://opensource.org/licenses/MIT).
Copyright (c) 2010-2016 [David Majda](https://majda.cz/)<br>
Copyright (c) 2017+ [Futago-za Ryuu](https://github.com/futagoza)

@ -0,0 +1,350 @@
"use strict";
const fs = require( "fs" );
const path = require( "path" );
const peg = require( "../lib/peg" );
const util = peg.util;
// Options
let inputFile = null;
let outputFile = null;
let options = {
"--": [],
"cache": false,
"dependencies": {},
"exportVar": null,
"format": "commonjs",
"optimize": "speed",
"output": "source",
"parser": {},
"plugins": [],
"trace": false,
};
const EXPORT_VAR_FORMATS = [ "globals", "umd" ];
const DEPENDENCY_FORMATS = [ "amd", "commonjs", "es", "umd" ];
const MODULE_FORMATS = [ "amd", "bare", "commonjs", "es", "globals", "umd" ];
const OPTIMIZATION_GOALS = [ "size", "speed" ];
// Helpers
function abort( message ) {
console.error( message );
process.exit( 1 );
}
function addExtraOptions( config ) {
if ( typeof config === "string" ) {
try {
config = JSON.parse( config );
} catch ( e ) {
if ( ! ( e instanceof SyntaxError ) ) throw e;
abort( "Error parsing JSON: " + e.message );
}
}
if ( typeof config !== "object" ) {
abort( "The JSON with extra options has to represent an object." );
}
if ( config.input !== null || config.output !== null ) {
// We don't want to touch the orignal config, just in case it comes from
// a javascript file, in which case its possible the same object is used
// for something else, somewhere else.
config = util.clone( config );
const { input, output } = config;
if ( input !== null ) {
if ( typeof input !== "string" )
abort( "The option `input` must be a string." );
if ( inputFile !== null )
abort( `The input file is already set, cannot use: "${ input }".` );
inputFile = input;
delete config.input;
}
if ( output !== null ) {
if ( typeof output !== "string" )
abort( "The option `output` must be a string." );
outputFile = output;
delete config.output;
}
}
options = util.processOptions( config, options );
}
function formatChoicesList( list ) {
list = list.map( entry => `"${ entry }"` );
const lastOption = list.pop();
return list.length === 0
? lastOption
: list.join( ", " ) + " or " + lastOption;
}
function updateList( list, string ) {
string
.split( "," )
.forEach( entry => {
entry = entry.trim();
if ( list.indexOf( entry ) === -1 ) {
list.push( entry );
}
} );
}
// Arguments
let args = process.argv.slice( 2 );
function nextArg( option ) {
if ( args.length === 0 ) {
abort( `Missing parameter of the ${ option } option.` );
}
return args.shift();
}
// Parse Arguments
while ( args.length > 0 ) {
let config, mod;
let argument = args.shift();
if ( argument.indexOf( "-" ) === 0 && argument.indexOf( "=" ) > 1 ) {
argument = argument.split( "=" );
args.unshift( argument.length > 2 ? argument.slice( 1 ) : argument[ 1 ] );
argument = argument[ 0 ];
}
switch ( argument ) {
case "--":
options[ "--" ] = args;
args = [];
break;
case "-a":
case "--allowed-start-rules":
if ( ! options.allowedStartRules ) options.allowedStartRules = [];
updateList( options.allowedStartRules, nextArg( "--allowed-start-rules" ) );
break;
case "--cache":
options.cache = true;
break;
case "--no-cache":
options.cache = false;
break;
case "-d":
case "--dependency":
argument = nextArg( "-d/--dependency" );
mod = argument.split( ":" );
if ( mod.length === 1 ) mod = [ argument, argument ];
else if ( mod.length > 2 ) mod[ 1 ] = mod.slice( 1 );
options.dependencies[ mod[ 0 ] ] = mod[ 1 ];
break;
case "-e":
case "--export-var":
options.exportVar = nextArg( "-e/--export-var" );
break;
case "--extra-options":
addExtraOptions( nextArg( "--extra-options" ) );
break;
case "-c":
case "--config":
case "--extra-options-file":
argument = nextArg( "-c/--config/--extra-options-file" );
if ( path.extname( argument ) === ".js" ) {
config = require( path.resolve( argument ) );
} else {
try {
config = fs.readFileSync( argument, "utf8" );
} catch ( e ) {
abort( `Can't read from file "${ argument }".` );
}
}
addExtraOptions( config );
break;
case "-f":
case "--format":
argument = nextArg( "-f/--format" );
if ( MODULE_FORMATS.indexOf( argument ) === -1 ) {
abort( `Module format must be either ${ formatChoicesList( MODULE_FORMATS ) }.` );
}
options.format = argument;
break;
case "-h":
case "--help":
console.log( require( "./usage" ) );
process.exit();
break;
case "-O":
case "--optimize":
argument = nextArg( "-O/--optimize" );
if ( OPTIMIZATION_GOALS.indexOf( argument ) === -1 ) {
abort( `Optimization goal must be either ${ formatChoicesList( OPTIMIZATION_GOALS ) }.` );
}
options.optimize = argument;
break;
case "-o":
case "--output":
outputFile = nextArg( "-o/--output" );
break;
case "-p":
case "--plugin":
argument = nextArg( "-p/--plugin" );
try {
mod = require( argument );
} catch ( ex1 ) {
if ( ex1.code !== "MODULE_NOT_FOUND" ) throw ex1;
try {
mod = require( path.resolve( argument ) );
} catch ( ex2 ) {
if ( ex2.code !== "MODULE_NOT_FOUND" ) throw ex2;
abort( `Can't load module "${ argument }".` );
}
}
options.plugins.push( mod );
break;
case "--trace":
options.trace = true;
break;
case "--no-trace":
options.trace = false;
break;
case "-v":
case "--version":
console.log( "PEG.js v" + peg.VERSION );
process.exit();
break;
default:
if ( inputFile !== null ) {
abort( `Unknown option: "${ argument }".` );
}
inputFile = argument;
}
}
// Validation and defaults
if ( Object.keys( options.dependencies ).length > 0 ) {
if ( DEPENDENCY_FORMATS.indexOf( options.format ) === -1 ) {
abort( `Can't use the -d/--dependency option with the "${ options.format }" module format.` );
}
}
if ( options.exportVar !== null ) {
if ( EXPORT_VAR_FORMATS.indexOf( options.format ) === -1 ) {
abort( `Can't use the -e/--export-var option with the "${ options.format }" module format.` );
}
}
if ( inputFile === null ) inputFile = "-";
if ( outputFile === null ) {
if ( inputFile === "-" ) outputFile = "-";
else if ( inputFile ) {
outputFile = inputFile
.substr( 0, inputFile.length - path.extname( inputFile ).length )
+ ".js";
}
}
// Export
options.inputFile = inputFile;
options.outputFile = outputFile;
module.exports = options;

@ -0,0 +1,121 @@
#!/usr/bin/env node
"use strict";
const fs = require( "fs" );
const peg = require( "../lib/peg" );
const options = require( "./options" );
// Helpers
function readStream( inputStream, callback ) {
let input = "";
inputStream.on( "data", data => {
input += data;
} );
inputStream.on( "end", () => {
callback( input );
} );
}
function closeStream( stream ) {
if ( stream !== process.stdin || stream !== process.stdout ) stream.end();
}
function abort( message ) {
console.error( message );
process.exit( 1 );
}
// Main
let inputStream, outputStream, orignalContent;
const inputFile = options.inputFile;
const outputFile = options.outputFile;
options.parser = options.parser || {};
if ( inputFile === "-" ) {
process.stdin.resume();
inputStream = process.stdin;
inputStream.on( "error", () => {
abort( `Can't read from file "${ inputFile }".` );
} );
} else {
inputStream = fs.createReadStream( inputFile );
options.parser.filename = inputFile;
}
if ( outputFile === "-" ) {
outputStream = process.stdout;
} else {
if ( fs.existsSync( outputFile ) ) {
orignalContent = fs.readFileSync( outputFile, "utf8" );
}
outputStream = fs.createWriteStream( outputFile );
outputStream.on( "error", () => {
abort( `Can't write to file "${ outputFile }".` );
} );
}
readStream( inputStream, input => {
let location, source;
try {
source = peg.generate( input, options );
} catch ( e ) {
if ( typeof e.location === "object" ) {
location = e.location.start;
if ( typeof location === "object" ) {
return abort( location.line + ":" + location.column + ": " + e.message );
}
}
if ( orignalContent ) {
closeStream( outputStream );
fs.writeFileSync( outputFile, orignalContent, "utf8" );
}
return abort( e.message );
}
outputStream.write( source );
closeStream( outputStream );
} );

@ -0,0 +1,55 @@
"use strict";
module.exports = `
Usage: pegjs [options] [<input_file>] [--]
Options:
-a, --allowed-start-rules <rules> Comma-separated list of rules the generated
parser will be allowed to start parsing from
(default: first rule in the grammar)
(note: repeatable option)
--cache Make generated parser cache results
-c, --config <file> Aliases for "--extra-options-file"
-d, --dependency <dependency> Use specified dependency
(note: repeatable option)
-e, --export-var <variable> Name of a global variable into which the
parser object is assigned to when no
module loader is detected
--extra-options <options> A string with additional options (in JSON
format) to pass to peg.generate
(note: repeatable option)
--extra-options-file <file> File with additional options (in JSON
or JavaScript) to pass to peg.generate
(note: repeatable option)
-f, --format <format> Format of the generated parser:
amd, bare, commonjs, es, globals, umd
(default: commonjs)
-h, --help Print help and exit
--no-cache Generated parser doesn't cache results
(default behavior)
--no-trace Disable tracing in generated parser
(default behavior)
-O, --optimize <goal> Select optimization for speed or size
(default: speed)
-o, --output <file> Output file
-p, --plugin <plugin> Use a specified plugin
(note: repeatable option)
--trace Enable tracing in generated parser
-v, --version Print version information and exit
`;

@ -0,0 +1,118 @@
"use strict";
const Node = require( "./Node" );
const visitor = require( "./visitor" );
const util = require( "../util" );
class Grammar extends Node {
// Creates a new AST
constructor( initializer, rules, comments, location ) {
super( "grammar", location );
this.initializer = initializer;
this.comments = comments;
this.rules = rules;
// eslint-disable-next-line no-use-before-define
this._alwaysConsumesOnSuccess = new AlwaysConsumesOnSuccess( this );
}
alwaysConsumesOnSuccess( node ) {
return this._alwaysConsumesOnSuccess.visit( node );
}
findRule( name ) {
return util.find( this.rules, rule => rule.name === name );
}
indexOfRule( name ) {
return util.findIndex( this.rules, rule => rule.name === name );
}
}
module.exports = Grammar;
/* ***************************** @private ***************************** */
class AlwaysConsumesOnSuccess extends visitor.ASTVisitor {
constructor( ast ) {
super();
this.ast = ast;
}
choice( node ) {
return node.alternatives.every( this.visit, this );
}
sequence( node ) {
return node.elements.some( this.visit, this );
}
rule_ref( node ) {
return this.visit( this.ast.findRule( node.name ) );
}
literal( node ) {
return node.value !== "";
}
}
function consumesTrue() {
return true;
}
function consumesFalse() {
return false;
}
function consumesExpression( node ) {
return this.visit( node.expression );
}
util.extend( AlwaysConsumesOnSuccess.prototype, {
rule: consumesExpression,
named: consumesExpression,
action: consumesExpression,
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,
class: consumesTrue,
any: consumesTrue,
} );

@ -0,0 +1,14 @@
"use strict";
class Node {
constructor( type, location ) {
this.type = type;
this.location = location;
}
}
module.exports = Node;

@ -0,0 +1,5 @@
"use strict";
exports.visitor = require( "./visitor" );
exports.Node = require( "./Node" );
exports.Grammar = require( "./Grammar" );

@ -0,0 +1,141 @@
"use strict";
const util = require( "../util" );
// Abstract syntax tree visitor for PEG.js
class ASTVisitor {
// Will traverse the node, strictly assuming the visitor can handle the node type.
visit( node ) {
// istanbul ignore next
if ( ! node ) throw new Error( "Visitor function called with no arguments or a `falsy` node" );
const fn = this[ node.type ];
// istanbul ignore next
if ( ! fn ) throw new Error( `Visitor function for node type "${ node.type }" not defined` );
return fn.apply( this, arguments ); // eslint-disable-line prefer-rest-params
}
}
module.exports = {
ASTVisitor,
// Simple AST node visitor builder for PEG.js
build( functions ) {
let visitor = new ASTVisitor();
util.extend( visitor, functions );
visitor = util.enforceFastProperties( visitor );
return visitor.visit.bind( visitor );
},
};
// Helper's to create visitor's for use with the ASTVisitor class
const on = ASTVisitor.on = {
// Visit a node that is defined as a property on another node
property( name ) {
return function visitProperty( node, ...extraArgs ) {
const value = node[ name ];
if ( extraArgs.length )
this.visit( value, ...extraArgs );
else
this.visit( value );
};
},
// Visit an array of nodes that are defined as a property on another node
children( name ) {
return function visitProperty( node, ...extraArgs ) {
const children = node[ name ];
const visitor = this;
const cb = extraArgs.length < 1
? function withoutArgs( child ) {
visitor.visit( child );
}
: function withArgs( child ) {
visitor.visit( child, ...extraArgs );
};
children.forEach( cb );
};
},
};
// Build the default ast visitor functions
const visitNop = util.noop;
const visitExpression = on.property( "expression" );
const DEFAULT_FUNCTIONS = {
grammar( node, ...extraArgs ) {
if ( node.initializer ) {
this.visit( node.initializer, ...extraArgs );
}
node.rules.forEach( rule => {
this.visit( rule, ...extraArgs );
} );
},
initializer: visitNop,
rule: visitExpression,
named: visitExpression,
choice: on.children( "alternatives" ),
action: visitExpression,
sequence: on.children( "elements" ),
labeled: visitExpression,
text: visitExpression,
simple_and: visitExpression,
simple_not: visitExpression,
optional: visitExpression,
zero_or_more: visitExpression,
one_or_more: visitExpression,
group: visitExpression,
semantic_and: visitNop,
semantic_not: visitNop,
rule_ref: visitNop,
literal: visitNop,
class: visitNop,
any: visitNop,
};
util.each( DEFAULT_FUNCTIONS, ( fn, name ) => {
ASTVisitor.prototype[ name ] = fn;
} );

@ -0,0 +1,98 @@
"use strict";
const calcReportFailures = require( "./passes/calc-report-failures" );
const generateBytecode = require( "./passes/generate-bytecode" );
const generateJS = require( "./passes/generate-js" );
const removeProxyRules = require( "./passes/remove-proxy-rules" );
const reportDuplicateLabels = require( "./passes/report-duplicate-labels" );
const reportDuplicateRules = require( "./passes/report-duplicate-rules" );
const reportUnusedRules = require( "./passes/report-unused-rules" );
const reportInfiniteRecursion = require( "./passes/report-infinite-recursion" );
const reportInfiniteRepetition = require( "./passes/report-infinite-repetition" );
const reportUndefinedRules = require( "./passes/report-undefined-rules" );
const inferenceMatchResult = require( "./passes/inference-match-result" );
const reportIncorrectPlucking = require( "./passes/report-incorrect-plucking" );
const Session = require( "./session" );
const util = require( "../util" );
const compiler = {
Session: Session,
// 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,
reportUnusedRules: reportUnusedRules,
reportDuplicateLabels: reportDuplicateLabels,
reportInfiniteRecursion: reportInfiniteRecursion,
reportInfiniteRepetition: reportInfiniteRepetition,
reportIncorrectPlucking: reportIncorrectPlucking,
},
transform: {
removeProxyRules: removeProxyRules,
},
generate: {
calcReportFailures: calcReportFailures,
inferenceMatchResult: inferenceMatchResult,
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, session, options = {} ) {
options = util.processOptions( options, {
allowedStartRules: [ ast.rules[ 0 ].name ],
cache: false,
context: {},
dependencies: {},
exportVar: null,
features: null,
format: "bare",
header: null,
optimize: "speed",
output: "parser",
trace: false,
} );
// We want `session.vm.evalModule` to return the parser
if ( options.output === "parser" ) options.format = "umd";
util.each( session.passes, stage => {
stage.forEach( pass => {
pass( ast, session, options );
} );
} );
switch ( options.output ) {
case "parser":
return session.vm.evalModule( ast.code, options.context );
case "source":
return ast.code;
default:
session.error( `Invalid output format: ${ options.output }.` );
}
},
};
module.exports = compiler;

@ -0,0 +1,60 @@
"use strict";
// Bytecode instruction opcodes.
const opcodes = {
// Stack Manipulation
PUSH_EMPTY_STRING: 0, // PUSH_EMPTY_STRING
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
PLUCK: 41, // PLUCK n, k, p1, ..., pK
// 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_CLASS: 20, // MATCH_CLASS c, a, f, ...
ACCEPT_N: 21, // ACCEPT_N n
ACCEPT_STRING: 22, // ACCEPT_STRING s
EXPECT: 23, // EXPECT 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
EXPECT_NS_BEGIN: 38, // EXPECT_NS_BEGIN
EXPECT_NS_END: 39, // EXPECT_NS_END invert
};
module.exports = opcodes;

@ -0,0 +1,65 @@
"use strict";
// Determines if rule always used in disabled report failure context,
// that means, that any failures, reported within it, are never will be
// visible, so the no need to report it.
function calcReportFailures( ast, session, options ) {
// By default, not report failures for rules...
ast.rules.forEach( rule => {
rule.reportFailures = false;
} );
// ...but report for start rules, because in that context report failures
// always enabled
const changedRules = options.allowedStartRules.map( name => {
const rule = ast.findRule( name );
rule.reportFailures = true;
return rule;
} );
const calc = session.buildVisitor( {
rule( node ) {
calc( node.expression );
},
// Because all rules already by default marked as not report any failures
// just break AST traversing when we need mark all referenced rules from
// this sub-AST as always not report anything (of course if it not be
// already marked as report failures).
named() {},
rule_ref( node ) {
const rule = ast.findRule( node.name );
// This function only called when rule can report failures. If so, we
// need recalculate all rules that referenced from it. But do not do
// this twice - if rule is already marked, it was in `changedRules`.
if ( ! rule.reportFailures ) {
rule.reportFailures = true;
changedRules.push( rule );
}
},
} );
while ( changedRules.length > 0 ) {
calc( changedRules.pop() );
}
}
module.exports = calcReportFailures;

@ -0,0 +1,754 @@
"use strict";
const util = require( "../../util" );
// Generates bytecode.
//
// Instructions
// ============
//
// Stack Manipulation
// ------------------
//
// [0] PUSH_EMPTY_STRING
//
// stack.push("");
//
// [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, literals[s].length) === literals[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, literals[s].length).toLowerCase() === literals[s]) {
// interpret(ip + 4, ip + 4 + a);
// } else {
// interpret(ip + 4 + a, ip + 4 + a + f);
// }
//
// [20] MATCH_CLASS c, a, f, ...
//
// if (classes[c].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(literals[s]);
// currPos += literals[s].length;
//
// [23] EXPECT e
//
// expect(expectations[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 = functions[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--;
//
// [38] EXPECT_NS_BEGIN
//
// expected.push({ pos: curPos, variants: [] });
//
// [39] EXPECT_NS_END invert
//
// value = expected.pop();
// if (value.pos === expected.top().pos) {
// if (invert) {
// value.variants.forEach(e => { e.not = !e.not; });
// }
// expected.top().variants.pushAll(value.variants);
// }
function generateBytecode( ast, session ) {
const op = session.opcodes;
const literals = [];
const classes = [];
const expectations = [];
const functions = [];
let generate;
function addLiteralConst( value ) {
const index = literals.indexOf( value );
return index === -1 ? literals.push( value ) - 1 : index;
}
function addClassConst( node ) {
const cls = {
value: node.parts,
inverted: node.inverted,
ignoreCase: node.ignoreCase,
};
const pattern = JSON.stringify( cls );
const index = util.findIndex( classes, c => JSON.stringify( c ) === pattern );
return index === -1 ? classes.push( cls ) - 1 : index;
}
function addExpectedConst( expected ) {
const pattern = JSON.stringify( expected );
const index = util.findIndex( expectations, e => JSON.stringify( e ) === pattern );
return index === -1 ? expectations.push( expected ) - 1 : index;
}
function addFunctionConst( predicate, params, code ) {
const func = { predicate: predicate, params: params, body: code };
const pattern = JSON.stringify( func );
const index = util.findIndex( functions, f => JSON.stringify( f ) === pattern );
return index === -1 ? functions.push( func ) - 1 : index;
}
const buildSequence = ( ...parts ) => [].concat( ...parts );
function buildCondition( match, condCode, thenCode, elseCode ) {
if ( match > 0 ) return thenCode;
if ( match < 0 ) return 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 ) {
const params = util.values( env, value => sp - value );
return [ op.CALL, functionIndex, delta, params.length ].concat( params );
}
function buildSimplePredicate( expression, negative, context ) {
const match = expression.match|0;
return buildSequence(
[ op.PUSH_CURR_POS ],
[ op.EXPECT_NS_BEGIN ],
generate( expression, {
sp: context.sp + 1,
env: util.clone( context.env ),
action: null,
reportFailures: context.reportFailures,
} ),
[ op.EXPECT_NS_END, negative ? 1 : 0 ],
buildCondition(
negative ? -match : match,
[ 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( node, negative, context ) {
const functionIndex = addFunctionConst( true, Object.keys( context.env ), node.code );
return buildSequence(
[ op.UPDATE_SAVED_POS ],
buildCall( functionIndex, 0, context.env, context.sp ),
buildCondition(
node.match|0,
[ 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 ),
);
}
generate = session.buildVisitor( {
grammar( node ) {
node.rules.forEach( generate );
node.literals = literals;
node.classes = classes;
node.expectations = expectations;
node.functions = functions;
},
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
reportFailures: node.reportFailures, // if `false`, suppress generation of EXPECT opcodes
} );
},
named( node, context ) {
// Do not generate unused constant, if no need it
const nameIndex = context.reportFailures ? addExpectedConst(
{ type: "rule", value: node.name },
) : null;
const expressionCode = generate( node.expression, {
sp: context.sp,
env: context.env,
action: context.action,
reportFailures: false,
} );
// No need to disable report failures if it already disabled
return context.reportFailures ? buildSequence(
[ op.EXPECT, nameIndex ],
[ op.SILENT_FAILS_ON ],
expressionCode,
[ op.SILENT_FAILS_OFF ],
) : expressionCode;
},
choice( node, context ) {
function buildAlternativesCode( alternatives, context ) {
return buildSequence(
generate( alternatives[ 0 ], {
sp: context.sp,
env: util.clone( context.env ),
action: null,
reportFailures: context.reportFailures,
} ),
alternatives.length < 2
? []
: buildCondition(
// If alternative always match no need generate code for next alternatives
-( alternatives[ 0 ].match|0 ),
[ op.IF_ERROR ],
buildSequence(
[ op.POP ],
buildAlternativesCode( alternatives.slice( 1 ), context ),
),
[],
),
);
}
return buildAlternativesCode( node.alternatives, context );
},
action( node, context ) {
const env = util.clone( context.env );
const emitCall = node.expression.type !== "sequence" || node.expression.elements.length === 0;
const expressionCode = generate( node.expression, {
sp: context.sp + ( emitCall ? 1 : 0 ),
env: env,
action: node,
reportFailures: context.reportFailures,
} );
const match = node.expression.match|0;
const functionIndex = emitCall && match >= 0
? addFunctionConst( false, Object.keys( env ), node.code )
: null;
return emitCall === false
? expressionCode
: buildSequence(
[ op.PUSH_CURR_POS ],
expressionCode,
buildCondition(
match,
[ op.IF_NOT_ERROR ],
buildSequence(
[ op.LOAD_SAVED_POS, 1 ],
buildCall( functionIndex, 1, env, context.sp + 2 ),
),
[],
),
[ op.NIP ],
);
},
sequence( node, context ) {
const TOTAL_ELEMENTS = node.elements.length;
function buildElementsCode( elements, context ) {
if ( elements.length > 0 ) {
const processedCount = TOTAL_ELEMENTS - elements.slice( 1 ).length;
return buildSequence(
generate( elements[ 0 ], {
sp: context.sp,
env: context.env,
pluck: context.pluck,
action: null,
reportFailures: context.reportFailures,
} ),
buildCondition(
elements[ 0 ].match|0,
[ op.IF_NOT_ERROR ],
buildElementsCode( elements.slice( 1 ), {
sp: context.sp + 1,
env: context.env,
pluck: context.pluck,
action: context.action,
reportFailures: context.reportFailures,
} ),
buildSequence(
processedCount > 1 ? [ op.POP_N, processedCount ] : [ op.POP ],
[ op.POP_CURR_POS ],
[ op.PUSH_FAILED ],
),
),
);
}
if ( context.pluck.length > 0 )
return buildSequence(
[ op.PLUCK, TOTAL_ELEMENTS + 1, context.pluck.length ],
context.pluck.map( eSP => context.sp - eSP ),
);
if ( context.action )
return buildSequence(
[ op.LOAD_SAVED_POS, TOTAL_ELEMENTS ],
buildCall(
addFunctionConst( // functionIndex
false,
Object.keys( context.env ),
context.action.code,
),
TOTAL_ELEMENTS + 1,
context.env,
context.sp,
),
);
return buildSequence( [ op.WRAP, TOTAL_ELEMENTS ], [ op.NIP ] );
}
return buildSequence(
[ op.PUSH_CURR_POS ],
buildElementsCode( node.elements, {
sp: context.sp + 1,
env: context.env,
pluck: [],
action: context.action,
reportFailures: context.reportFailures,
} ),
);
},
labeled( node, context ) {
let env = context.env;
const label = node.label;
const sp = context.sp + 1;
if ( label !== null ) {
env = util.clone( context.env );
context.env[ label ] = sp;
}
if ( context.pluck && node.pick )
context.pluck.push( sp );
return generate( node.expression, {
sp: context.sp,
env: env,
action: null,
reportFailures: context.reportFailures,
} );
},
text( node, context ) {
return buildSequence(
[ op.PUSH_CURR_POS ],
generate( node.expression, {
sp: context.sp + 1,
env: util.clone( context.env ),
action: null,
reportFailures: context.reportFailures,
} ),
buildCondition(
node.expression.match|0,
[ 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: util.clone( context.env ),
action: null,
reportFailures: context.reportFailures,
} ),
buildCondition(
// If expression always match no need replace FAILED to NULL
-( node.expression.match|0 ),
[ op.IF_ERROR ],
buildSequence( [ op.POP ], [ op.PUSH_NULL ] ),
[],
),
);
},
zero_or_more( node, context ) {
const expressionCode = generate( node.expression, {
sp: context.sp + 1,
env: util.clone( context.env ),
action: null,
reportFailures: context.reportFailures,
} );
return buildSequence(
[ op.PUSH_EMPTY_ARRAY ],
expressionCode,
buildAppendLoop( expressionCode ),
[ op.POP ],
);
},
one_or_more( node, context ) {
const expressionCode = generate( node.expression, {
sp: context.sp + 1,
env: util.clone( context.env ),
action: null,
reportFailures: context.reportFailures,
} );
return buildSequence(
[ op.PUSH_EMPTY_ARRAY ],
expressionCode,
buildCondition(
node.expression.match|0,
[ 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: util.clone( context.env ),
action: null,
reportFailures: context.reportFailures,
} );
},
semantic_and( node, context ) {
return buildSemanticPredicate( node, false, context );
},
semantic_not( node, context ) {
return buildSemanticPredicate( node, true, context );
},
rule_ref( node ) {
return [ op.RULE, ast.indexOfRule( node.name ) ];
},
literal( node, context ) {
if ( node.value.length > 0 ) {
const match = node.match|0;
const needConst = match === 0 || ( match > 0 && ! node.ignoreCase );
const stringIndex = needConst ? addLiteralConst(
node.ignoreCase ? node.value.toLowerCase() : node.value,
) : null;
// Do not generate unused constant, if no need it
const expectedIndex = context.reportFailures ? addExpectedConst( {
type: "literal",
value: node.value,
ignoreCase: node.ignoreCase,
} ) : null;
// 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 buildSequence(
context.reportFailures ? [ op.EXPECT, expectedIndex ] : [],
buildCondition(
match,
node.ignoreCase
? [ op.MATCH_STRING_IC, stringIndex ]
: [ op.MATCH_STRING, stringIndex ],
node.ignoreCase
? [ op.ACCEPT_N, node.value.length ]
: [ op.ACCEPT_STRING, stringIndex ],
[ op.PUSH_FAILED ],
),
);
}
return [ op.PUSH_EMPTY_STRING ];
},
class( node, context ) {
const match = node.match|0;
const classIndex = match === 0 ? addClassConst( node ) : null;
// Do not generate unused constant, if no need it
const expectedIndex = context.reportFailures ? addExpectedConst( {
type: "class",
value: node.parts,
inverted: node.inverted,
ignoreCase: node.ignoreCase,
} ) : null;
return buildSequence(
context.reportFailures ? [ op.EXPECT, expectedIndex ] : [],
buildCondition(
match,
[ op.MATCH_CLASS, classIndex ],
[ op.ACCEPT_N, 1 ],
[ op.PUSH_FAILED ],
),
);
},
any( node, context ) {
// Do not generate unused constant, if no need it
const expectedIndex = context.reportFailures
? addExpectedConst( { type: "any" } )
: null;
return buildSequence(
context.reportFailures ? [ op.EXPECT, expectedIndex ] : [],
buildCondition(
node.match|0,
[ op.MATCH_ANY ],
[ op.ACCEPT_N, 1 ],
[ op.PUSH_FAILED ],
),
);
},
} );
generate( ast );
}
module.exports = generateBytecode;

File diff suppressed because it is too large Load Diff

@ -0,0 +1,169 @@
"use strict";
// Inference match result of the rule. Can be:
// -1: negative result, always fails
// 0: neutral result, may be fail, may be match
// 1: positive result, always match
function inferenceMatchResult( ast, session ) {
let inference;
function sometimesMatch( node ) {
node.match = 0;
return node.match;
}
function alwaysMatch( node ) {
inference( node.expression );
node.match = 1;
return node.match;
}
function inferenceExpression( node ) {
node.match = inference( node.expression );
return node.match;
}
function inferenceElements( elements, forChoice ) {
const length = elements.length;
let always = 0;
let never = 0;
for ( let i = 0; i < length; ++i ) {
const result = inference( elements[ i ] );
if ( result > 0 ) {
++always;
}
if ( result < 0 ) {
++never;
}
}
if ( always === length ) {
return 1;
}
if ( forChoice ) {
return never === length ? -1 : 0;
}
return never > 0 ? -1 : 0;
}
inference = session.buildVisitor( {
rule( node ) {
let oldResult;
let count = 0;
if ( typeof node.match === "undefined" ) {
node.match = 0;
do {
oldResult = node.match;
node.match = inference( node.expression );
// 6 == 3! -- permutations count for all transitions from one match
// state to another.
// After 6 iterations the cycle with guarantee begins
// istanbul ignore next
if ( ++count > 6 ) {
session.error(
"Infinity cycle detected when trying to evaluate node match result",
node.location,
);
}
} while ( oldResult !== node.match );
}
return node.match;
},
named: inferenceExpression,
choice( node ) {
node.match = inferenceElements( node.alternatives, true );
return node.match;
},
action: inferenceExpression,
sequence( node ) {
node.match = inferenceElements( node.elements, false );
return node.match;
},
labeled: inferenceExpression,
text: inferenceExpression,
simple_and: inferenceExpression,
simple_not( node ) {
node.match = -inference( node.expression );
return node.match;
},
optional: alwaysMatch,
zero_or_more: alwaysMatch,
one_or_more: inferenceExpression,
group: inferenceExpression,
semantic_and: sometimesMatch,
semantic_not: sometimesMatch,
rule_ref( node ) {
const rule = ast.findRule( node.name );
node.match = inference( rule );
return node.match;
},
literal( node ) {
// Empty literal always match on any input
node.match = node.value.length === 0 ? 1 : 0;
return node.match;
},
class( node ) {
// Empty character class never match on any input
node.match = node.parts.length === 0 ? -1 : 0;
return node.match;
},
// |any| not match on empty input
any: sometimesMatch,
} );
inference( ast );
}
module.exports = inferenceMatchResult;

@ -0,0 +1,42 @@
"use strict";
// Removes proxy rules -- that is, rules that only delegate to other rule.
function removeProxyRules( ast, session, options ) {
function isProxyRule( node ) {
return node.type === "rule" && node.expression.type === "rule_ref";
}
const replaceRuleRefs = session.buildVisitor( {
rule_ref( node, proxy, real ) {
if ( node.name === proxy ) node.name = real;
},
} );
const allowedStartRules = options.allowedStartRules;
const rules = [];
ast.rules.forEach( rule => {
if ( isProxyRule( rule ) ) {
replaceRuleRefs( ast, rule.name, rule.expression.name );
if ( allowedStartRules.indexOf( rule.name ) < 0 ) return;
}
rules.push( rule );
} );
ast.rules = rules;
}
module.exports = removeProxyRules;

@ -0,0 +1,70 @@
"use strict";
const util = require( "../../util" );
const __hasOwnProperty = Object.prototype.hasOwnProperty;
// Checks that each label is defined only once within each scope.
function reportDuplicateLabels( ast, session ) {
let check;
function checkExpressionWithClonedEnv( node, env ) {
check( node.expression, util.clone( env ) );
}
check = session.buildVisitor( {
rule( node ) {
check( node.expression, {} );
},
choice( node, env ) {
node.alternatives.forEach( alternative => {
check( alternative, util.clone( env ) );
} );
},
action: checkExpressionWithClonedEnv,
labeled( node, env ) {
const label = node.label;
if ( label && __hasOwnProperty.call( env, label ) ) {
const start = env[ label ].start;
session.error(
`Label "${ label }" is already defined at line ${ start.line }, column ${ start.column }.`,
node.location,
);
}
check( node.expression, env );
if ( label ) env[ 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;

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

Loading…
Cancel
Save