426 Commits (b81396a904fef4992ecd9fdc2b77a0226e2d7ee4)

Author SHA1 Message Date
Futago-za Ryuu d3cbbee592 Added .d.ts declaration files (#519) 6 years ago
Mingun 3e89534bb7 Auto-add `allowedStartRules` to test options for `changeAST` and `reportError` methods if it not defined 6 years ago
Mingun f0e5eebe1a Add code coverage by Intanbul 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 b4e5b97a2e Disabled eslint rule 'prefer-spread' 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 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
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 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 55bcaa46ef Updated ESLint configuration files
- added "root" option to main config
- moved "env.commonjs" to root
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
fatfisz e3b7f0c3a9 Change "esm" to "es" 7 years ago
fatfisz aab928de91 Add support for ES modules 7 years ago
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.
8 years ago
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
8 years ago
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.
8 years ago
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.
8 years ago
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.
8 years ago
David Majda 80a9e03614 Code style: Fix ESLint "no-empty-function" errors
Part of #407.
8 years ago
David Majda fd07f64637 Code style: Fix ESLint "indent" errors
Part of #407.
8 years ago
David Majda e61ae59681 Code style: Fix ESLint "default-case" errors
Part of #407.
8 years ago
David Majda 364482dd68 Code style: Fix ESLint "no-prototype-builtins" errors
Part of #407.
8 years ago
David Majda 1870308afb Code style: Fix ESLint "object-shorthand" errors
Part of #407.
8 years ago
David Majda 5dd8e797f7 Code style: Do not lint lib/parser.js
The idea behind linting lib/parser.js was that it would improve quality
of code generated by PEG.js in general. However, there is a couple of
problems with it:

  1. Code in lib/parser.js is ES5 while the rest of the code is ES2015.
     This would mean a separate ESLint configuration and a separate set
     of code style rules just for lib/parser.js once code style checks
     are added.

  2. Code in lib/parser.js is generated. This means that even today it
     violates checks like "no-unused-var", which have to be disabled.
     This would get worse once code style checks are added, again
     requiring a separate ESLint configuration just for lib/parser.js.

  3. Linting lib/parser.js checks only small portion of possible code
     generator output. For example, code generated when optimizing for
     size or when tracing is not checked at all. Thus, linting
     lib/parser.js gives a false sense of security.

Because of these problems I decided not to lint lib/parser.js at all and
rely on ad-hoc linting of parser files produced by PEG.js with ignoring
false-positives. I consider this more of a pragmatic cost vs. benefits
decision than a principial one.

Part of #407.
8 years ago
David Majda f82d9872ba Replace stray "var" by "let"
Likely missed in bdf91b5941.
8 years ago
David Majda 7495e6e03f Add missing semicolons 8 years ago
David Majda b81afb1471 Do not quote the "class" key
Quoting reserved words in property names is not needed since dropping
support of IE < 9.
8 years ago
David Majda ec3f7f5bb0 Remove extra indentation 8 years ago
David Majda 7ca229a432 Improve indentation of variable declarations
Before this commit, continuation lines of multi-line values in variable
declaration initializers were aligned with the variable name:

  let foo = {
        a: 5,
        b: 6
      };

This was highly irregular, maintenance intensive, and made declarations
look different from assignments.

This commit changes the indentation to be more regular and similar to
assignments:

  let foo = {
    a: 5,
    b: 6
  };
8 years ago
David Majda e29d62558d Do not prepend the "eslint-env" directive to lib/parser.js
The lib/parser.js file is a CommonJS module like all the other files in
lib/, so setting the environment explicitly is not needed. Besides, the
environment set by "eslint-env" was wrong (since transitioning from the
AMD format).
8 years ago
David Majda 9648ca53d7 Use the "eslint-disable" directive instead of "eslint"
The "eslint-disable" directive is more specific.
8 years ago
David Majda 60821bb80b Sort "require" calls by variable names and group them
This makes things consistent and reduces thinking about "require"
ordering.
8 years ago
David Majda ff7193776e Avoid aligning "="
The only exception left are instances where aligning "=" helps to
express symmetry between lines.

See #443.
8 years ago
David Majda 400a3cfa3c Avoid aligning object keys
The only exception left are objects representing a mapping with simple
keys and values -- essentially tables written as object literals.

See #443.
8 years ago
David Majda 12112310f2 Use only double quotes for strings
See #443
8 years ago
David Majda 6294bb5b13 Use only "//" comments
See #443.
8 years ago
David Majda 1da6abc458 Use one var/let/const per variable (fixup)
Fix few instances in generated code which I missed in the previous
commit.

See #443.
8 years ago
David Majda 516023546d Use one var/let/const per variable (for initialized variables)
Use one var/let/const per variable, but only for initialized variables.
Uninitialized variables are still grouped into one var/let/const
declaration as I don't see any value in separating them. This approach
reflects the fact that initialized and uninitialized var/let/const
declarations are really two different things.

See #443.
8 years ago
David Majda 7f01db2fb8 Get rid of for-in loops
The for-in statement in JavaScript iterates also over inherited
properties. This is typically not desired and requires adding a
check using Object.prototype.hasOwnProperty inside the loop.

This commit replaces all for-in statements and related checks inside
them with iteration over Object.keys(...). The iteration is performed
using either Array.prototype.forEach of a plain for loop.
8 years ago
David Majda b2a9dabcff Remove now unused lib/utils/objects.js
See #442.
8 years ago
David Majda 5fbb557f80 Don't use "objects" in lib/peg.js
The "objects" module will be removed.

See #442.
8 years ago
David Majda 66ca7e2168 Don't use "objects" in lib/compiler/visitor.js
The "objects" module will be removed.

See #442.
8 years ago
David Majda 76e70c3923 Don't use "objects" in lib/compiler/passes/report-duplicate-labels.js
The "objects" module will be removed.

See #442.
8 years ago
David Majda d2569b9bf3 Don't use "objects" in lib/compiler/passes/generate-js.js
The "objects" module will be removed.

See #442.
8 years ago
David Majda 8a75d19468 Don't use "objects" in lib/compiler/passes/generate-bytecode.js
The "objects" module will be removed.

See #442.
8 years ago
David Majda 97d92c9d8b Don't use "objects" in lib/compiler/index.js
The "objects" module will be removed.

See #442.
8 years ago
David Majda c344460855 Remove now unused lib/utils/arrays.js
See #442.
8 years ago
David Majda f81ae1845b Don't use "arrays" in lib/compiler/passes/report-infinite-recursion.js
The "arrays" module will be removed.

See #442.
8 years ago
David Majda 71ef4c9b91 Don't use "arrays" in lib/compiler/passes/remove-proxy-rules.js
The "arrays" module will be removed.

See #442.
8 years ago
David Majda 8f8484b1a1 Don't use "arrays" in lib/compiler/passes/generate-js.js
The "arrays" module will be removed.

See #442.
8 years ago
David Majda 33f23ee4be Don't use "arrays" in lib/compiler/passes/generate-bytecode.js
The "arrays" module will be removed.

See #442.
8 years ago
David Majda 4dec5e52ba Don't use "arrays" in lib/compiler/asts.js
The "arrays" module will be removed.

See #442.
8 years ago
David Majda 5822596ab8 Replace classes.subclass with native classes
See #442.
8 years ago
David Majda 6fa8ad63f9 Replace some functions with arrow functions
Because arrow functions work rather differently than normal functions (a
bad design mistake if you ask me), I decided to be conservative with the
conversion.

I converted:

  * event handlers
  * callbacks
  * arguments to Array.prototype.map & co.
  * small standalone lambda functions

I didn't convert:

  * functions assigned to object literal properties (the new shorthand
    syntax would be better here)
  * functions passed to "describe", "it", etc. in specs (because Jasmine
    relies on dynamic "this")

See #442.
8 years ago
David Majda d00e9526c3 Minimize variable scope
Where possible, move "let" statements into inner blocks, loop headers,
etc.

See #442.
8 years ago
David Majda bdf91b5941 Replace "var" with "let" & "const"
This is purely a mechanical change, not taking advantage of block scope
of "let" and "const". Minimizing variable scope will come in the next
commit.

In general, "var" is converted into "let" and "const" is used only for
immutable variables of permanent character (generally spelled in
ALL_CAPS). Using it for any immutable variable regardless on its
permanence would feel confusing.

Any code which is not transpiled and needs to run in ES6 environment
(examples, code in grammars embedded in specs, ...) is kept unchanged.
This is also true for code generated by PEG.js.

See #442.
8 years ago
David Majda c3e7072fa2 Remove unused arrays.pluck function 8 years ago
David Majda 062c6ae706 Escape backspace in regexp classes as "\b", not "\x08"
The "\x08" escaping is necessary only outside of classes (where "\b"
means "word boundary").
8 years ago
David Majda bd62ddf846 Use "[]" & "[^]" for empty character classes, not "(?!)" & "[\\S\\s]"
See #441.
8 years ago
David Majda 9c04c94c85 Escape vertical tab as "\v", not "\x0B"
See #441.
8 years ago
David Majda f36a667376 Remove "undefined" redefinition protection
See #441.
8 years ago
David Majda fad4ab74d1 Replace suitable for loops with Array methods (in /lib)
See #441.
8 years ago
David Majda 3e8bcbea73 Replace suitable for loops with Array methods (in /src)
See #441.
8 years ago
David Majda 1c3fbf6cb0 Replace "... instanceof Array" with "Array.isArray(...)"
See #441.
8 years ago
David Majda d346d2a66d Replace objects.keys with Object.keys
See #441.
8 years ago
David Majda 0059cc3bdd Replace arrays.some with Array.prototype.some
See #441.
8 years ago
David Majda d162fe1cfc Replace arrays.every with Array.prototype.every
See #441.
8 years ago
David Majda 5f65de92bc Replace arrays.map with Array.prototype.map
See #441.
8 years ago
David Majda b044a021c4 Replace arrays.each with Array.prototype.forEach
See #441.
8 years ago
David Majda 671166bbe8 Update version to 0.10.0 8 years ago
David Majda 8003edafc9 Rename the "node" module format to "commonjs"
Parsers generated in this format use module.exports, so they are not
strictly CommonJS, but this is a common extension and the original name
would be confusing once Node.js implements ES2015 modules.
8 years ago
David Majda 8962dcfd16 Rename the "global" module format to "globals"
I think the new name is more widely used when describing the pattern.
8 years ago
David Majda b77d33ca05 generate-js.js: Quote the "class" key in DESCRIBE_EXPECTATION_FNS
"class" is a reserved word. Having it as a key unquoted broke IE 8 (both
in standards and quirks mode) and IE 9 (in quirks mode).
8 years ago
David Majda 67d85f2de8 Align names of compiler passes that detect infinite loops
Rename compiler passes as follows:

  reportLeftRecursion -> reportInfiniteRecursion
  reportInfiniteLoops -> reportInfiniteRepetition

This reflects the fact that both passes detect different ways of causing
the same problem (possible infinite loop when parsing).
8 years ago
David Majda 9717dc3417 Talk about "undefined rules" instead of "missing rules" internally
The new terminology is more precise and in line with commonly used
programming languages.

The change involves mainly renaming related compiler pass and files
associated with it.
8 years ago
David Majda e9cb23608d Split peg$buildException into two separate functions
This change reflects the fact that PEG.js-generated parsers really
produce two kinds of syntax errors:

  Structured errors

    Caused by match failures, trailing input, or calls of the "expected"
    function in parser code. Their messages have fixed format ("Expected
    ... but ... found.").

  Simple errors

    Caused by calls of the "error" function in parser code. Their
    messages don't have any fixed format.

Each kind of error now has a separate helper function which builds its
instances.
8 years ago
David Majda e03d92488a Set the "found" property of syntax errors produced by "error" to null
The property doesn't correspond to anything in the error's message.
8 years ago
David Majda 6ca546a44e Regenerate lib/parser.js 8 years ago
David Majda db9920e3ca peg.generate: Implement { format: "global" } 8 years ago
David Majda 61c11ee1b4 peg.generate: Implement { format: "amd" } 8 years ago
David Majda f633f697c9 peg.generate: Implement { format: "node" } 8 years ago
David Majda 9454c11c59 generate-js.js: Fix "=" alignment 8 years ago
David Majda e546af5543 Regenerate lib/parser.js 8 years ago
David Majda e8be76ee3a Don't expose the "parser" variable in parser code
The "parser" variable allowed access to the parser object. Among other
things, this made it possible to invoke the parser recursively using
"parser.parse".

One problem with the "parser" variable is that it bakes in the idea that
the parser is an *object*, not a *module*. While this is true now, it
won't necessarily be in the future, when parsers may be exported as ES6
modules. Also, people tend to use parsers as modules even today, e.g.
like this:

  var parse = require("parser").parse;
  var result = parse(...);

Such usage broke the "parser" variable (as it was implemented).

For this reasons I decided to remove the "parser" variable. If someone
needs to do tricks like recursive invocation of the parser, he/she must
pass the parser or the "parse" function itself using options.

Related to #433.
8 years ago
David Majda 6aa956452e Don't use "this" inside peg.generate
This change makes it possible to use "generate" as a module function,
e.g. like this:

  var generate = require("pegjs").generate;
  var parser = generate(...);

Fixes #433.
8 years ago
David Majda 65550965c6 Remove extraneous "with" from an error message 8 years ago
David Majda b3a90de020 Syntax error messages: Use Oxford comma
In general PEG.js uses American English, where Oxford comma is
prevalent.

Part of #371.
8 years ago
David Majda ec8ede5bbe Grammar error messages 3/3: Improve the left recursion message
New wording is more explanatory.

Part of #371.
8 years ago
David Majda f5e43f842c Grammar error messages 2/3: Improve the infinite loop message
New wording is more explanatory.

Part of #371.
8 years ago
David Majda 85fb8aaa0e Grammar error messages 1/3: Improve the missing rule message
New wording is more similar to wording used in various programming
languages and it is in line with the duplicate rule message.

Part of #371.
8 years ago
David Majda eb67cbedb4 Report duplicate labels as errors
Resolves #270.
8 years ago
David Majda 2a889535bd Add location to the "Rule ... is already defined" error message
See this discussion:

  eb5875bc6a (commitcomment-17970220)
8 years ago
David Majda eb5875bc6a Report duplicate rule definitions as errors
Based on a pull request by Futago-za Ryuu (@futagoza):

  https://github.com/pegjs/pegjs/pull/329

Resolves #318.
8 years ago