Commit graph

396 commits

Author SHA1 Message Date
Futago-za Ryuu 9d266625b4 Merge ast utils into Grammar class 2018-01-26 07:49:34 +00:00
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
2018-01-24 18:12:13 +00:00
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()
}
```
2018-01-24 18:10:45 +00:00
Futago-za Ryuu d06a5b52ef Restore silentFails guard for rule$expects 2018-01-18 21:52:06 +00:00
Futago-za Ryuu 75a4101622 Some cosmetic changes
- Remove unused '__slice' variable
- Nicely indent a map/concat chain
- 'forEach' instead of 'map' in emitted code
2018-01-18 01:47:13 +00:00
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
2018-01-18 01:24:34 +00:00
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
2018-01-17 16:57:49 +00:00
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
2018-01-16 04:28:27 +00:00
Futago-za Ryuu 27ec5ed9b1 Ensure we are nearly always in fast mode on V8
See: https://stackoverflow.com/a/24989927/1518408
2018-01-16 02:57:12 +00:00
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'.
2018-01-16 02:54:14 +00:00
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.
2018-01-16 02:46:41 +00:00
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.
2018-01-14 20:44:53 +00:00
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".
2018-01-07 14:51:06 +00:00
Futago-za Ryuu 93f9068c99 Updated tsd for compiler passes [ci skip] 2018-01-07 01:08:35 +00:00
Mingun 534dc53ac2 Optimize redundant fail checks (#400)
eliminate unnecessary checks for the result of parse, when it can be statically determined
2018-01-05 21:28:09 +00:00
Futago-za Ryuu 06f1565a32 tsd: Added NotExpectation interface 2018-01-02 01:50:38 +00:00
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).
2018-01-01 19:35:59 +00:00
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
2017-12-31 10:59:51 +00:00
Futago-za Ryuu 03cc2eae95 Added 'lib/peg.d.ts' for internal use 2017-12-28 01:23:37 +00:00
Futago-za Ryuu ea688abd02 Fix shadowing issue on UMD format (#499) 2017-12-28 00:01:35 +00:00
Futago-za Ryuu d3cbbee592 Added .d.ts declaration files (#519) 2017-12-27 23:04:05 +00:00
Mingun 3e89534bb7 Auto-add allowedStartRules to test options for changeAST and reportError methods if it not defined 2017-12-19 01:38:26 +05:00
Mingun f0e5eebe1a Add code coverage by Intanbul 2017-12-18 18:53:01 +05:00
Futago-za Ryuu 1dd1487f9b Set version to v0.11.0-dev 2017-12-18 01:23:17 +00:00
Futago-za Ryuu db70215c4a Added 'header' option (#491) 2017-12-18 00:54:47 +00:00
Futago-za Ryuu b4e5b97a2e Disabled eslint rule 'prefer-spread' 2017-10-26 10:20:29 +01:00
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).
2017-10-25 19:19:42 +01:00
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'.
2017-10-25 02:24:11 +01:00
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 */"
2017-10-02 06:32:20 +01:00
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.
2017-09-15 21:36:19 +01:00
felix ee00a1ae6a Check allowedStartRules exist. (#532)
Fixes #524
2017-09-12 21:21:35 +01:00
felix 958e15879d Reimplement offset() and add range(). (#528)
* Reimplement offset()
* Implement range()

Fixes #526, thanks @felix9
2017-09-04 05:48:17 +01:00
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
2017-08-30 17:58:04 +01:00
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
2017-08-24 20:11:49 +01:00
Futago-za Ryuu 57bb28414e Merge pull request #509 from Mingun/simplify-bc
Simplify bytecode: remove unnecessary opcode.
2017-08-24 04:17:45 +01:00
Futago-za Ryuu 55bcaa46ef Updated ESLint configuration files
- added "root" option to main config
- moved "env.commonjs" to root
2017-07-22 15:45:10 +01:00
Mingun c98fee1629 Add location information to group AST node 2017-06-24 23:34:50 +05:00
Mingun 575db38d1f Simplify bytecode: remove unnecessary opcode.
Now generated sources looks little better :)
2017-06-24 22:36:21 +05:00
fatfisz e3b7f0c3a9 Change "esm" to "es" 2017-06-11 18:48:52 +02:00
fatfisz aab928de91 Add support for ES modules 2017-06-11 18:48:52 +02:00
David Majda 266f17d11c Adapt to using HTTPS on PEG.js website
PEG.js website is now served exclusively using HTTPS. Change protocol in
all links to it to avoid redirects.
2016-12-04 11:24:33 +01:00
David Majda a733beb933 Remove unnecessary escaping of "]" in a regexp
This fixes the following ESLint error, which started to appear after
eslint/eslint#7424 was fixed:

  /Users/dmajda/Programming/PEG.js/pegjs/lib/compiler/js.js
    37:17  error  Unnecessary escape character: \]  no-useless-escape

This should fix broken Travis CI builds:

  https://travis-ci.org/pegjs/pegjs/builds/180092802
2016-12-01 16:30:10 +01:00
David Majda ef3abf33b9 Fix error when generating AMD/UMD dependencies
Generating AMD/UMD dependencies lead to an error:

  $ bin/pegjs --format amd --dependency $:jquery examples/arithmetics.pegjs
  dependencyIds is not defined

  $ bin/pegjs --format umd --dependency $:jquery examples/arithmetics.pegjs
  dependencyIds is not defined

This commit fixes the problem, which was caused by a mistake done in
d2569b9bf3.
2016-10-10 14:29:27 +02:00
David Majda 83d748d522 Code style: Make all static "require" calls global
The "global-require" rule is disabled in ESLint configuration used by
PEG.js, but the idea is not bad, so let's make all static "require"
calls global.

Follow-up to #407.
2016-10-10 13:38:39 +02:00
David Majda f4df9ddde1 Code style: Fix some ESLint errors in generated code
Running ESLint on generated code with the configuration used on PEG.js
itself produces a lot of errors. This commit fixes some unnecessary ones
caught by these rules:

  - max-len
  - new-cap
  - newline-before-return
  - no-unused-vars

See also 5dd8e797f7.

Follow-up to #407.
2016-10-10 13:32:33 +02:00
David Majda 80a9e03614 Code style: Fix ESLint "no-empty-function" errors
Part of #407.
2016-10-10 10:58:06 +02:00
David Majda fd07f64637 Code style: Fix ESLint "indent" errors
Part of #407.
2016-10-10 10:58:06 +02:00
David Majda e61ae59681 Code style: Fix ESLint "default-case" errors
Part of #407.
2016-10-10 10:58:06 +02:00
David Majda 364482dd68 Code style: Fix ESLint "no-prototype-builtins" errors
Part of #407.
2016-10-10 10:58:06 +02:00
David Majda 1870308afb Code style: Fix ESLint "object-shorthand" errors
Part of #407.
2016-10-10 10:58:05 +02:00