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
Calling 'vm.runInContext' is slightly more expensive then calling `eval`, but removing the string template and extracting the variable generator helps abit.
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.
* 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
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()
}
```
* 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
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'.
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.
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.
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".
* 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).
* 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
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).
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'.
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 */"