601 Commits (df154daafb9c6c952351493af02d3a55e0b05c59)
 

Author SHA1 Message Date
David Majda df154daafb PEG.js grammar: Disallow empty sequences
Empty sequences are useless and they only confused users. Let's disallow
them.
10 years ago
David Majda 2005345976 Complete rewrite of the CSS example grammar
This is a complete rewrite of the CSS example grammar. It is now based
on CSS 2.1 *including the errata* and the generated parser builds a
nicer syntax tree. There is also a number of cleanups, formatting
changes, naming changes, and bug fixes.

Beside this, the rewrite reflects how I write grammars today (as opposed
to few years ago) and what style I would recommend to others.
10 years ago
David Majda 18f92c5647 Complete rewrite of the JavaScript example grammar
This is a complete rewrite of the JavaScript example grammar. It is now
based on ECMA-262, 5.1 Edition and the generated parser builds a syntax
tree compatible with Mozilla SpiderMonkey Parser API. There is also a
number of cleanups, formatting changes, naming changes, and bug fixes.

Beside this, the rewrite reflects how I write grammars today (as opposed
to few years ago) and what style I would recommend to others.
10 years ago
David Majda fba70833dd Complete rewrite of the JSON example grammar
This is a complete rewrite of the JSON example grammar. It is now based
on RFC 7159 instead of an informal description at the JSON website.

Beside this, the rewrite reflects how I write grammars today (as opposed
to few years ago) and what style I would recommend to others.
10 years ago
David Majda f5443d2bf1 Complete rewrite of the arithmetics example grammar
This is a complete rewrite of the arithmetics example grammar. It now
allows whitespace between tokens, supports "-" and "/" operators, and
gets the operator associativity right. Also, rule names now match the usual
conventions (term, factor,...).

Beside this, the rewrite reflects how I write grammars today (as opposed
to few years ago) and what style I would recommend to others.
10 years ago
David Majda 93d3c6a250 Update .travis.yml
Remove a directive to test in Node.js 0.6. Add a directive to test in
Node.js 0.10.

Should fix broken Travis CI builds:

  https://travis-ci.org/dmajda/pegjs/builds/15922026
10 years ago
David Majda 2263a30034 Update version to 0.8.0 10 years ago
David Majda 7d761e9aae Update CHANGELOG.md 10 years ago
David Majda d74f9df7dd Make CHANGELOG.md less dense
While the additional spacing makes lists with one-line items uglier, it
also makes lists with multi-line items much more readable.
10 years ago
David Majda 4fe0167a70 Convert CHANGELOG to Markdown
* Convert CHANGELOG to Markdown.
  * Improve formatting a bit.
  * Add links to GitHub issues
  * Fix typos.
10 years ago
David Majda a449f12efe Require Node.js >= 0.8.0 10 years ago
David Majda ff0beb5a8c benchmark/run: Always parse the -n/--run-count value as decimal integer 10 years ago
David Majda e73adafbf6 Add license to all vendored libraries where it was missing
Fixes #207.
10 years ago
David Majda e7e4543bb4 .jshintrc: Remove the "sub" option 10 years ago
David Majda e20e907d8c .jshintrc: Add the "trailing" option 10 years ago
David Majda 4402f7fd86 .jshintrc: Add the "noarg" option 10 years ago
David Majda af54963233 .jshintrc: Add the "latedef" option 10 years ago
David Majda 4362ba190c .jshintrc: Add the "immed" option 10 years ago
David Majda 43eeabf03a .jshintrc: Add the "freeze" option 10 years ago
David Majda 95fd64ec15 .jshintrc: Add the "forin" option & fix fallout
Also added few missing |hasOwnProperty| calls that JSHint didn't detect
because it only looks whether there is an |if| statement wrapping the
loop body.
10 years ago
David Majda f22d7aabb5 Fix JSHint errors in bin/pegjs
Fixes the following JSHint errors:

  bin/pegjs: line 66, col 14, 'extraOptions' used out of scope.
  bin/pegjs: line 70, col 19, 'extraOptions' used out of scope.
  bin/pegjs: line 71, col 20, 'extraOptions' used out of scope.
  bin/pegjs: line 80, col 10, Wrap the /regexp/ literal in parens to disambiguate the slash operator.
  bin/pegjs: line 128, col 43, Missing semicolon.
  bin/pegjs: line 128, col 45, Don't make functions within a loop.
  bin/pegjs: line 150, col 13, Redefinition of 'module'.
  bin/pegjs: line 217, col 34, Expected '===' and instead saw '=='.
  bin/pegjs: line 243, col 44, 'source' used out of scope.
  bin/pegjs: line 243, col 61, 'source' used out of scope.
10 years ago
David Majda cc3a9fde2d Fix JSHint error in benchmark/run
Fixes the following JSHint error:

  benchmark/run: line 106, col 10, Wrap the /regexp/ literal in parens to disambiguate the slash operator.
10 years ago
David Majda e321f0c23e Fix JSHint error in lib/compiler/passes/generate-bytecode.js
Fixes the following JSHint error:

  lib/compiler/passes/generate-bytecode.js: line 334, col 71, Expected an assignment or function call and instead saw an expression.
10 years ago
David Majda b3c6a997b0 Use JSHint 2.3.0 10 years ago
David Majda 06a83448df Remove various unused variables and function parameters 10 years ago
David Majda 1ea9a5f340 Use UglifyJS 2.4.7
The |uglifyjs| call had to be adapted because the options changed
significantly in version 2.
10 years ago
David Majda 976328b7d6 Avoid |Array.prototype.splice| call with one parameter
The one-parameter |Array.prototype.splice| call is a SpiderMonkey
extension. Apparently, IE doesn't implement it (unlike other supported
browsers), so we need to replace it with two-parameter version.
10 years ago
David Majda 995ddb8f86 Update bundled jQuery to version 1.10.2
I didn't use the 2.x branch because it doesn't support IE 8 anymore.
10 years ago
David Majda ae5630f23b Update bundled jQuery.ScrollTo to version 1.4.7 10 years ago
David Majda a56d3ac94f Fix error messages in certain cases with trailing input
In case the generated parser parsed successfully part of input and left
some input unparsed (trailing input), the error message produced was
sometimes wrong. The code worked correctly only if there were no match
failures in the successfully parsed part (highly unlikely).

This commit fixes things by explicitly triggering a match failure with the
following expectation at the end of the successfully parsed part of the
input:

  peg$fail({ type: "end", description: "end of input" });

This change also made it possible to simplify the |buildMessage|
function, which can now ignore the case of no expectations.

Fixes #119.
10 years ago
David Majda 44e03187a7 Assert that generated bytecode manipulates stack correctly
There are two invariants in generated bytecode related to the stack:

  1. Branches of a condition must move the stack pointer in the same way.

  2. Body of a loop can't move the stack pointer.

These invariants were always true, but they were not checked. Now we
check them at least when compiling with optimization for speed, because
there we analyze the stack pointer movements statically.
10 years ago
David Majda 0bcf7bc61b Renumber bytecode instructions to make them sequential 10 years ago
David Majda 41d95ad323 Makefile: Add missing period at the ned of a sentence 10 years ago
David Majda 5fa99ccc34 Update copyright years to 2010-2013 10 years ago
David Majda 9f01c4b0c4 spec/generated-parser.spec.js: s/multiple-character/multi-character/ 10 years ago
David Majda da9a32a5f3 Example grammars: Improve |parseInt| invocations
Instead of |parseInt("0x" + digits)| do |parseInt(digits, 16)|, which is
a bit cleaner.
10 years ago
David Majda 68c6452d8a CSS example grammar: Simplify |integer| and |float| rules
It's not necessary to parse |parts| in the |integer| and |float| rule
into integer/float value. Everywhere these rules are used the result is
converted back into string anyway.
10 years ago
David Majda 2d4ecaf39c spec/compiler/passes/generate-bytecode.spec.js: Fix comments 10 years ago
David Majda 9ca5061fcf lib/compiler/opcodes.js: Fix formatting 10 years ago
David Majda fbcefdf523 Fix |oneRuleGrammar| invocation
At one call site, the |oneRuleGrammar| was called with 3 parameters but
it only accepts 2. This commit removes the additional parameter.
10 years ago
David Majda 187f9d6bb0 Remove the |NIP_CURR_POS| bytecode instruction
After the previous commit is is not used anywhere.
10 years ago
David Majda e15c57066c Remove an error check after calling action code
The error check was useful when actions could have returned |null| to
trigger a match failure. This is no longer supported so the check isn't
needed anymore.

Speed impact
------------
Before:     1022.70 kB/s
After:      1035.45 kB/s
Difference: 1.24%

Size impact
-----------
Before:     975434 b
After:      931540 b
Difference: -4.50%

(Measured by /tools/impact with Node.js v0.6.18 on x86_64 GNU/Linux.)
10 years ago
David Majda 2f2152204a Refine error handling further
Before this commit, the |expected| and |error| functions didn't halt the
parsing immediately, but triggered a regular match failure. After they
were called, the parser could backtrack, try another branches, and only
if no other branch succeeded, it triggered an exception with information
possibly based on parameters passed to the |expected| or |error|
function (this depended on positions where failures in other branches
have occurred).

While nice in theory, this solution didn't work well in practice. There
were at least two problems:

  1. Action expression could have easily triggered a match failure later
     in the input than the action itself. This resulted in the
     action-triggered failure to be shadowed by the expression-triggered
     one.

     Consider the following example:

       integer = digits:[0-9]+ {
         var result = parseInt(digits.join(""), 10);

         if (result % 2 === 0) {
           error("The number must be an odd integer.");
           return;
         }

         return result;
       }

     Given input "2", the |[0-9]+| expression would record a match
     failure at position 1 (an unsuccessful attempt to parse yet another
     digit after "2"). However, a failure triggered by the |error| call
     would occur at position 0.

     This problem could have been solved by silencing match failures in
     action expressions, but that would lead to severe performance
     problems (yes, I tried and measured). Other possible solutions are
     hacks which I didn't want to introduce into PEG.js.

  2. Triggering a match failure in action code could have lead to
     unexpected backtracking.

     Consider the following example:

       class = "[" (charRange / char)* "]"

       charRange = begin:char "-" end:char {
         if (begin.data.charCodeAt(0) > end.data.charCodeAt(0)) {
           error("Invalid character range: " + begin + "-" + end + ".");
         }

         // ...
       }

       char = [a-zA-Z0-9_\-]

     Given input "[b-a]", the |charRange| rule would fail, but the
     parser would try the |char| rule and succeed repeatedly, resulting
     in "b-a" being parsed as a sequence of three |char|'s, which it is
     not.

     This problem could have been solved by using negative predicates,
     but that would complicate the grammar and still wouldn't get rid of
     unintuitive behavior.

Given these problems I decided to change the semantics of the |expected|
and |error| functions. They don't interact with regular match failure
mechanism anymore, but they cause and immediate parse failure by
throwing an exception. I think this is more intuitive behavior with less
harmful side effects.

The disadvantage of the new approach is that one can't backtrack from an
action-triggered error. I don't see this as a big deal as I think this
will be rarely needed and one can always use a semantic predicate as a
workaround.

Speed impact
------------
Before:     993.84 kB/s
After:      998.05 kB/s
Difference: 0.42%

Size impact
-----------
Before:     1019968 b
After:      975434 b
Difference: -4.37%

(Measured by /tools/impact with Node.js v0.6.18 on x86_64 GNU/Linux.)
10 years ago
David Majda 9fa7301aec Regenerate src/parser.js
Forgot to do it in f8b5e04bba.
10 years ago
David Majda f8b5e04bba Error handling: Use the new |error| function in PEG.js's grammar itself
Implements part of #198.
10 years ago
David Majda 5460a881af Error handling: Implement the |error| function
The |error| function allows users to report custom match failures inside
actions.

If the |error| function is called, and the reported match failure turns
out to be the cause of a parse error, the error message reported by the
parser will be exactly the one specified in the |error| call.

Implements part of #198.

Speed impact
------------
Before:     999.83 kB/s
After:      1000.84 kB/s
Difference: 0.10%

Size impact
-----------
Before:     1017212 b
After:      1019968 b
Difference: 0.27%

(Measured by /tools/impact with Node.js v0.6.18 on x86_64 GNU/Linux.)
10 years ago
David Majda dd74ea4144 Error handling: Build error message out of |SyntaxError|'s constructor
It will be possible to create errors with user-supplied messages soon.
The |SyntaxError| class needs to be ready for that.

Implements part of #198.
10 years ago
David Majda 3fe6aba7e2 Error handling: Extract exception building into its own function
The exception-creating code will get somewhat hairy soon, so let's make
sure them mess will be contained.

Implements part of #198.
10 years ago
David Majda d96eb317fd Error handling: Rename |peg$fail| to |peg$expected|
This is in anticipation of |peg$error|. The |peg$expected| and
|peg$error| internal functions will nicely mirror the |expected| and
|error| functions available to user code in actions.

Implements part of #198.
10 years ago
David Majda af701dcf80 Error handling: Implement the |expected| function
The |expected| function allows users to report regular match failures
inside actions.

If the |expected| function is called, and the reported match failure
turns out to be the cause of a parse error, the error message reported
by the parser will be in the usual "Expected ... but found ..." format
with the description specified in the |expected| call used as part of
the message.

Implements part of #198.

Speed impact
------------
Before:     1146.82 kB/s
After:      1031.25 kB/s
Difference: -10.08%

Size impact
-----------
Before:     950817 b
After:      973269 b
Difference: 2.36%

(Measured by /tools/impact with Node.js v0.6.18 on x86_64 GNU/Linux.)
10 years ago