Commit graph

193 commits

Author SHA1 Message Date
David Majda 1682a25b0d Move emitter utility functions out of |PEG.Compiler| 2010-08-14 17:48:55 +02:00
David Majda e5a5572a87 Factored the code emitter out of the compiler 2010-08-14 17:48:47 +02:00
David Majda 2622f432bd Move compiler checks and passes out of |PEG.Compiler| definition
This allows splitting them into separate files in the future. It also
decreases indentation level in the code.
2010-08-14 17:48:39 +02:00
David Majda d7d1a0b28c Remove unused |PEG.ArrayUtils.range| utility function 2010-08-14 17:48:26 +02:00
David Majda 98da358ef4 Found a neater trick how to defend against |undefined| redefinition 2010-08-14 17:48:17 +02:00
David Majda c3b5c2131a Benchmark: Factor benchmark into several functions run using |setTimeout|
We do this for two reasons:

  1. To avoid bowser mechanism for interrupting long-running scripts to
     kick-in (or at least to not kick-in that often).

  2. To ensure progressive rendering of results in the browser (some
     browsers do not render at all when running JavaScript code).

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

Detailed results (benchmark suite totals):

---------------------------------
 Test #     Before       After
---------------------------------
      1   31.04 kB/s   31.18 kB/s
      2   31.26 kB/s   30.89 kB/s
      3   31.15 kB/s   31.19 kB/s
      4   30.52 kB/s   31.21 kB/s
      5   31.00 kB/s   30.73 kB/s
---------------------------------
Average   30.99 kB/s   31.04 kB/s
---------------------------------

Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.99 Safari/533.4
2010-07-24 14:48:12 +02:00
David Majda 647e7be1fd Benchmark: Users can specify the number of runs 2010-07-21 22:38:44 +02:00
David Majda 4cae3f9b48 Benchmark: Make results table fixed-width, center everything 2010-07-21 21:53:09 +02:00
David Majda 1cdce63878 Updated version to 0.5 2010-06-10 09:54:23 +02:00
David Majda 374cf3644b CHANGELOG: Fix 0.5 release date 2010-06-10 09:53:14 +02:00
David Majda b30f4a9c34 README.md tweaks 2010-06-10 09:43:08 +02:00
David Majda 61fff6c70f Updated CHANGELOG 2010-06-09 10:28:36 +02:00
David Majda 08ea5e49d6 README.md: Fix example code 2010-06-09 09:44:33 +02:00
David Majda a616b00c83 Improve README.md 2010-06-09 09:40:22 +02:00
David Majda 5f810f803b Make example grammars compatible with Rhino 2010-06-08 17:01:54 +02:00
David Majda a93ad0a5b8 README.md: Make the "Compatibility" section a bulleted list 2010-06-08 15:06:21 +02:00
David Majda af1968054b Implement semantic predicates 2010-06-08 14:49:13 +02:00
David Majda 4895f4f8e4 Treat the whole grammar as an AST node 2010-06-08 12:46:16 +02:00
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.
2010-06-08 11:03:28 +02:00
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).
2010-06-08 09:35:58 +02:00
David Majda 66de889f4b Implement initializers 2010-06-08 09:15:09 +02:00
David Majda 718bcf5f87 Rename the |action| property of action AST nodes to |code| 2010-06-07 16:47:17 +02:00
David Majda c0f0d56975 Fix incorrect comment 2010-06-07 16:06:50 +02:00
David Majda 8a2e21fa3f Inlined the |initialContext| variable 2010-06-07 16:04:21 +02:00
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.
2010-06-07 15:22:29 +02:00
David Majda 1daf1448e5 Get rid of the |_startRule| property in generated parsers. 2010-06-07 11:43:02 +02:00
David Majda 95735f2c97 Allow trailing semicolon (";") for rules 2010-06-07 10:59:14 +02:00
David Majda 7d4911ec53 Emit little bit less whitespace in actions 2010-06-07 10:45:26 +02:00
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
2010-06-07 09:23:04 +02:00
David Majda 52704593cd Allow labeled expressions in the metagrammar (without any meaning yet) 2010-05-31 16:35:03 +02:00
David Majda 409ddf2ae8 Formatted all grammars more consistently and transparently
This is purely cosmetical change, no functionality was affected
(hopefully).
2010-05-31 16:35:03 +02:00
David Majda 698564a3c2 Replace ":" after a rule name with "="
I'll introduce labelled expressions shortly and I want to use ":" as a
label-expression separator. This change avoids conflict between the two
meanings of ":". (What would e.g. "foo: 'bar'" mean?  Rule "foo"
matching string "bar", or string "bar" labelled "foo"?)
2010-05-31 16:31:45 +02:00
David Majda 7fdf0492c7 Fixed error message for invalid character range + added test 2010-05-31 16:30:02 +02:00
David Majda f9ea46ef15 Fix string literal parsing in the JavaScript grammar 2010-05-31 15:26:35 +02:00
David Majda 570658756a Remove useless action from the metagrammar 2010-05-31 12:48:43 +02:00
David Majda 9bf86b89a6 Fix stupid mistakes in metagrammar-test.js
The mistakes weren't caught because the first one introduces a syntax
error, causing the whole test suite not to load. Unfortunately, QUnit
didn't complain so I missed this.

The real commit these changes belong to is
33a1a7c1e9.
2010-05-22 18:58:41 +02:00
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.
2010-05-22 17:43:32 +02:00
David Majda 11c67b0507 Remove trailing whitespace 2010-05-22 13:15:20 +02:00
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.
2010-05-22 13:11:15 +02:00
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.
2010-05-22 10:55:12 +02:00
David Majda 137a4b4f53 Renamed |characters| -> |chars| (shorter, no loss of expressivity) 2010-05-21 21:18:33 +02:00
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).
2010-05-21 21:02:33 +02:00
David Majda d85bfcb2e9 Fix comment typo 2010-05-21 20:34:17 +02:00
David Majda 76ed63c86e AST refactoring 6/6: Get rid of the |Grammar| namespace 2010-05-21 19:00:00 +02:00
David Majda b4bf49443a AST refactoring 5/6: Make AST classless 2010-05-21 18:54:52 +02:00
David Majda 41abb7ad92 AST refactoring 4/6: Rewrite compilation to not extend the AST nodes 2010-05-21 18:44:18 +02:00
David Majda 5885a34dde AST refactoring 3/6: Rewrite checks to not extend the AST nodes 2010-05-21 18:43:40 +02:00
David Majda c59516541f AST refactoring 2/6: Add |type| property to AST nodes 2010-05-21 16:22:16 +02:00
David Majda 4e99a2bda7 AST refactoring 1/6: Make properties of AST nodes public
Removed undescore prefix of the properties and deleted getters.
2010-05-21 16:21:04 +02:00
David Majda 1c7c5bb5da Correct variable name: "choice" -> "optional". 2010-05-15 19:56:50 +02:00