57 Commits (917cf1cf2a85d3069e10a2d17caa19c2cfcac92a)

Author SHA1 Message Date
David Majda 917cf1cf2a Start rule of the grammar is now implicitly its first rule
Before this change, the start rule was the one named "start" and there
was an option to override that. This is now impossible.

The goal of this change is to contain all information for the parser
generation in the grammar itself.

In the future, some override directive for the start rule (like Bison's
"%start") may be added to the grammar.
14 years ago
David Majda 70cf4cd94d Reset generated variable names for each rule parsing function
Little change in the source grammar now does not change variables in all
the generated code. This is helpful especially when one has the
generated grammar stored in a VCS (this is true e.g. for our
metagrammar).
14 years ago
David Majda 66de889f4b Implement initializers 14 years ago
David Majda 718bcf5f87 Rename the |action| property of action AST nodes to |code| 14 years ago
David Majda c0f0d56975 Fix incorrect comment 14 years ago
David Majda 8a2e21fa3f Inlined the |initialContext| variable 14 years ago
David Majda 439c815e48 Move lot of stuff in generated parsers into the |parse| method
We want to have the rule parsing functions inside the |parse| method
because we want them to share a common environment. In the future,
initializers will be executed in this enviromnent and thus functions and
variables defined by them will be accessible to the rule parsing
functions.

Moving various private properties from the parser object into the
|parse| method was not strictly necessary, but it was a natural step
after moving the functions.
14 years ago
David Majda 1daf1448e5 Get rid of the |_startRule| property in generated parsers. 14 years ago
David Majda 7d4911ec53 Emit little bit less whitespace in actions 14 years ago
David Majda ee8c121676 Use labeled expressions and variables instead of $1, $2, etc.
Labeled expressions lead to more maintainable code and also will allow
certain optimizations (we can ignore results of expressions not passed
to the actions).

This does not speed up the benchmark suite execution statistically
significantly on V8.

Detailed results (benchmark suite totals):

---------------------------------
 Test #     Before       After
---------------------------------
      1   28.43 kB/s   28.46 kB/s
      2   28.38 kB/s   28.56 kB/s
      3   28.22 kB/s   28.58 kB/s
      4   28.76 kB/s   28.55 kB/s
      5   28.57 kB/s   28.48 kB/s
---------------------------------
Average   28.47 kB/s   28.53 kB/s
---------------------------------

Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.55 Safari/533.4
14 years ago
David Majda 52704593cd Allow labeled expressions in the metagrammar (without any meaning yet) 14 years ago
David Majda d1fc16c373 Fix bug causing incorrect error messages
The bug could cause the list of expected strings in an error message to
contain strings that shouldn't be there.

Closes #2.
14 years ago
David Majda 90ed4712e9 Add compiler optimization: Remove proxy rules
This shouldn't have measurable effect on the benchmarks as there are no
proxy rules in the grammars the benchamrk uses. However the effect on
generated parsers' speed should be positive generally.
14 years ago
David Majda 33a1a7c1e9 Clean up class handling in the metagrammar and compiler
The class AST node now contains structured data and a raw text which is
used for error messages.
14 years ago
David Majda 137a4b4f53 Renamed |characters| -> |chars| (shorter, no loss of expressivity) 14 years ago
David Majda 4e968892be Guard against redefinition of |undefined|
In most cases, code pattern

  x === undefined

was transformed to

  typeof(x) === "undefined"

and similarly with |!==|.

In the generated code, the condition was simply made less strict to
avoid performance penalty of string comparison (I don't think JavaScript
VMs optimize this specific pattern to avoid it).
14 years ago
David Majda d85bfcb2e9 Fix comment typo 14 years ago
David Majda 76ed63c86e AST refactoring 6/6: Get rid of the |Grammar| namespace 14 years ago
David Majda b4bf49443a AST refactoring 5/6: Make AST classless 14 years ago
David Majda 41abb7ad92 AST refactoring 4/6: Rewrite compilation to not extend the AST nodes 14 years ago
David Majda 5885a34dde AST refactoring 3/6: Rewrite checks to not extend the AST nodes 14 years ago
David Majda c59516541f AST refactoring 2/6: Add |type| property to AST nodes 14 years ago
David Majda 4e99a2bda7 AST refactoring 1/6: Make properties of AST nodes public
Removed undescore prefix of the properties and deleted getters.
14 years ago
David Majda 6f2a188efc Checks refactoring
Changed two things:

  1. Checks are run in |PEG.Compiler.compileParser|, not in
     |PEG.buildParser|.

  2. Checks are extracted into separate functions.
14 years ago
David Majda 85930cbcfe Reorder AST stuff more consistently and sensibly
There is no functional change in this commit.
14 years ago
David Majda f28c52fde2 Rename |_element| to |_expression| in AST
All nodes which have one subexpression store it in the |_expression| property
now.
14 years ago
David Majda cc7f1d96eb Avoid |call| when calling actions with one parameter.
This speeds up the benchmark suite execution by 0.18%, which may just be a
measurement error. (Standrad statistic tests would tell more, but I don't want
to mess with them now.) The code is little bit nicer this way though.

Going further and avoiding |apply| seems to slow thigs down a bit, possibly
because multiple array accesses. I may try improved version without array
accesses (where Action passes the Sequence variable names to save the results
into) sometime later.

Detailed results (benchmark suite totals):

---------------------------------
 Test #     Before       After
---------------------------------
      1   29.08 kB/s   28.91 kB/s
      2   28.72 kB/s   28.75 kB/s
      3   28.78 kB/s   28.88 kB/s
      4   28.57 kB/s   28.90 kB/s
      5   28.84 kB/s   28.81 kB/s
---------------------------------
Average   28.80 kB/s   28.85 kB/s
---------------------------------

Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.9 Safari/533.2
14 years ago
David Majda e3aa4df090 Changed action parameter processing to avoid the arguments object.
The action now computes the number of passed parameters during the code
generation and the parameters are declared directly as $1, $2, etc. in the
generated function.

This does not speed up the benchmark suite execution statistically significantly
on V8.

Detailed results (benchmark suite totals):

---------------------------------
 Test #     Before       After
---------------------------------
      1   28.68 kB/s   29.08 kB/s
      2   28.77 kB/s   28.72 kB/s
      3   28.89 kB/s   28.78 kB/s
      4   28.84 kB/s   28.57 kB/s
      5   28.86 kB/s   28.84 kB/s
---------------------------------
Average   28.81 kB/s   28.80 kB/s
---------------------------------

Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.9 Safari/533.2
14 years ago
David Majda a1dcd245bb Action AST node no longer accepts functions as actions (only strings). 14 years ago
David Majda b2f230fad2 Added Optional AST node.
This does not speed up the benchmark suite execution statistically significantly
on V8.

Detailed results (benchmark suite totals):

---------------------------------
 Test #     Before       After
---------------------------------
      1   28.84 kB/s   28.75 kB/s
      2   28.76 kB/s   28.69 kB/s
      3   28.72 kB/s   28.69 kB/s
      4   28.84 kB/s   28.93 kB/s
      5   28.82 kB/s   28.70 kB/s
---------------------------------
Average   28.80 kB/s   28.75 kB/s
---------------------------------

Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.2 (KHTML, like Gecko)
Chrome/5.0.342.9 Safari/533.2
14 years ago
David Majda e5df8284b5 Added AndPredicate AST node.
This does not speed up the benchmark suite execution statistically significantly
on V8.

Detailed results (benchmark suite totals):

---------------------------------
 Test #     Before       After
---------------------------------
      1   28.72 kB/s   28.84 kB/s
      2   28.84 kB/s   28.76 kB/s
      3   28.83 kB/s   28.72 kB/s
      4   28.81 kB/s   28.84 kB/s
      5   28.76 kB/s   28.82 kB/s
---------------------------------
Average   28.79 kB/s   28.80 kB/s
---------------------------------

Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.9 Safari/533.2
14 years ago
David Majda c3c1c79665 Added OneOrMore AST node.
This speeds up the benchmark suite execution by 1.08% on V8.

Detailed results (benchmark suite totals):

---------------------------------
 Test #     Before       After
---------------------------------
      1   28.38 kB/s   28.72 kB/s
      2   28.52 kB/s   28.84 kB/s
      3   28.41 kB/s   28.83 kB/s
      4   28.47 kB/s   28.81 kB/s
      5   28.64 kB/s   28.76 kB/s
---------------------------------
Average   28.48 kB/s   28.79 kB/s
---------------------------------

Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.9 Safari/533.2
14 years ago
David Majda 8f59e21c8d Renamed an iterator variable: "key" -> "rule". 14 years ago
David Majda 3f5cb8850c Fixed PEG.buildParser's documentation and added a test. 14 years ago
David Majda 48da65d08e PEG.buildParser now accepts grammars only in string format. 14 years ago
David Majda a86e06a216 Add "Generated by ..." message to the generated parsers. 14 years ago
David Majda 09291d6f0f Use "charAt(...)" instead of "[...]" for accessing string characters (compatibility with IE < 8). 14 years ago
David Majda 4b51e6a6d3 Quote null characters in regexps, IE does not like them. 14 years ago
David Majda 6abda95a99 Made regexps generated for empty character classes ("[]" and "[^]") work in IE. 14 years ago
David Majda e79e869993 Compensate for IE's lack of Array.prototype.indexOf function. 14 years ago
David Majda e63f64a3d5 Make the generated parsers standalone (no runtime is required).
This and also speeds up the benchmark suite execution by 7.83 % on V8.

Detailed results (benchmark suite totals):

---------------------------------
 Test #     Before       After
---------------------------------
      1   26.17 kB/s   28.16 kB/s
      2   26.05 kB/s   28.16 kB/s
      3   25.99 kB/s   28.10 kB/s
      4   26.13 kB/s   28.11 kB/s
      5   26.14 kB/s   28.07 kB/s
---------------------------------
Average   26.10 kB/s   28.14 kB/s
---------------------------------

Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.7 Safari/533.2
14 years ago
David Majda 24d38f74b9 Replaced two-level rule cache with a one-level one.
This leads to simpler code and also speeds up the benchmark suite execution by
5,89 % on V8.

Detailed results (benchmark suite totals):

---------------------------------
 Test #     Before       After
---------------------------------
      1   24,70 kB/s   26,14 kB/s
      2   24,49 kB/s   26,05 kB/s
      3   24,67 kB/s   25,99 kB/s
      4   24,65 kB/s   26,13 kB/s
      5   24,71 kB/s   26,14 kB/s
---------------------------------
Average   24,64 kB/s   26.10 kB/s
---------------------------------

Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.7 Safari/533.2
14 years ago
David Majda 714512f232 Implemented generic AST node extension mechanism. 14 years ago
David Majda 1aa3d8e07e Implemented a nop (no operation) function and used it on few places. 14 years ago
David Majda 16f238a64d Fixed comment heading. 14 years ago
David Majda 20e230ca0e Killed *MatchFailure classes => simpler code. 14 years ago
David Majda 22d2ac8ac2 Rewrote implementation of classes to be regexp-based. 14 years ago
David Majda 56ffa94cc7 PEG.buildParser reports left recursion (both direct and indirect). 14 years ago
David Majda 3a65316416 PEG.buildParser reports missing referenced rules. 14 years ago
David Majda 6f510a0336 The cache does not remember match length but next position after the match.
This leads to simpler and faster code because it avoids one addition and
subtraction.
14 years ago