70 Commits (1dd1487f9be8ca80dcdfb21be3879758d188bf97)

Author SHA1 Message Date
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 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
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
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 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 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 fd07f64637 Code style: Fix ESLint "indent" 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 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 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 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 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 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 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 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 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 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 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 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 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 5a4d04fa90 Construct expectations using functions
Until now, expectations were constructed using object literals. This
commit changes the construction to use factory functions.

This change makes generated parsers slightly smaller because property
names don't have to be repeated many times and factory function calls
are more amenable to minifying.

Some numbers based on the aggregate size of parsers generated from
examples/*.pegjs:

  Optimization   Minified?   Size before   Size after   Saving
  ------------------------------------------------------------
  speed          no               719066       716063    0.42%
  speed          yes              188998       180202    4.65%
  size           no               194810       197813    1.52%
  size           yes              108782        99947    8.12%

(Minification was done using "uglify --mangle --compress" with
uglify-js 2.4.24.)
8 years ago
David Majda 8639cf6d61 Expectation refactoring 6/7: Move "buildMessage" to SyntaxError
The "buildMessage" utility function, which was previously internal, is
now exposed as SyntaxError.buildMessage in generated parsers.

The motivation behind this is two-fold:

  1. Building of a syntax error message is a responsibility of the
     SyntaxError class, meaning the code should be placed there.

  2. By exposing the message building code, parser users can use it to
     generate customized error messages without duplicating PEG.js's code.

Note that helper functions inside "buildMessage" ("describeExpected",
"describeFound", etc.) currently aren't exposed. They may become exposed
in the future if there is enough demand.
8 years ago