16 Commits (21c6d9ccd387517ebc12e0cd8a52945a0e0e2800)

Author SHA1 Message Date
David Majda 4de3cc1716 Fix comment typos
Original patch by Wolfgang Kluge:

  07e0cfcc02
13 years ago
David Majda f893d47b98 src/utils.js: Make |quoteForRegexpClass| escape control characters
Fixes the following JSHint errors:

  ./src/parser.js: line 3614, col 16, Mixed spaces and tabs.
  ./src/parser.js: line 3614, col 20, Unsafe character.
13 years ago
David Majda ab49197ef1 src/utils.js: Make |quote| escape control characters
Also change |quote| in src/emitter.js so both are in sync.

Fixes the following JSHint errors:

  ./src/parser.js: line 3613, col 27, Mixed spaces and tabs.
  ./src/parser.js: line 3613, col 31, Unsafe character.
  ./src/parser.js: line 3613, col 38, Control character in string: [     .
  ./src/parser.js: line 3613, col 40, Control character in string: [
13 years ago
David Majda 10cca7b69d src/utils.js: Fix unescaped "]" inside a regexp
Fixes the following JSHint error:

  ./src/utils.js: line 124, col 15, Unescaped ']'.
13 years ago
David Majda 6e934fccca src/utils.js: Fix missing/unnecessary semicolons
Fixes the following JSHint errors:

  ./src/utils.js: line 108, col 2, Unnecessary semicolon.
  ./src/utils.js: line 128, col 39, Missing semicolon.
  ./src/utils.js: line 140, col 4, Missing semicolon.
13 years ago
David Majda 938f655ccf src/utils.js: Fix variable redefinition in |escape|
Fixes the following JSHint errors:

  ./src/utils.js: line 76, col 20, 'escapeChar' is already defined.
  ./src/utils.js: line 77, col 16, 'length' is already defined.
  ./src/utils.js: line 80, col 17, 'escapeChar' used out of scope.
  ./src/utils.js: line 80, col 80, 'length' used out of scope.
13 years ago
David Majda d123cf0eda Rewrite variable handling in generated parsers
Before this commit, variables for saving match results and parse
positions in generated parsers were not used efficiently. Each rule
basically used its own variable(s) for storing the data, with names
generated sequentially during code emitting. There was no reuse of
variables and a lot of unnecessary assignments between them.

It is easy to see that both match results and parse positions can
actually be stored on a stack that grows as the parser walks deeper in
the grammar tree and shrinks as it returns. Moreover, if one creates a
new stack for each rule the parser enters, its maximum depth can be
computed statically from the grammar. This allows us to implement the
stack not as an array, but as a set of numbered variables in each
function that handles parsing of a grammar rule, avoiding potentially
slow array accesses.

This commit implements the idea from the previous paragraph, using
separate stack for match results and for parse positions. As a result,
defined variables are reused and unnecessary copying avoided.

Speed implications
------------------

This change speeds up the benchmark suite execution by 2.14%.

Detailed results (benchmark suite totals as reported by "jake benchmark"
on Node.js 0.4.8):

-----------------------------------
 Test #      Before        After
-----------------------------------
      1   129.01 kB/s   131.98 kB/s
      2   129.39 kB/s   130.13 kB/s
      3   128.63 kB/s   132.57 kB/s
      4   127.53 kB/s   129.82 kB/s
      5   127.98 kB/s   131.80 kB/s
-----------------------------------
Average   128.51 kB/s   131.26 kB/s
-----------------------------------

Size implications
-----------------

This change makes a sample of generated parsers 8.60% smaller:

Before:

  $ wc -c src/parser.js examples/*.js
   110867 src/parser.js
    13886 examples/arithmetics.js
   450125 examples/css.js
   632390 examples/javascript.js
    61365 examples/json.js
  1268633 total

After:

  $ wc -c src/parser.js examples/*.js
    99597 src/parser.js
    13077 examples/arithmetics.js
   399893 examples/css.js
   592044 examples/javascript.js
    54797 examples/json.js
  1159408 total
13 years ago
David Majda 13a3621e79 Export the PEG library in simpler and more robust way 13 years ago
David Majda aa2327191f Escape 0xFF still with "\x", not "\u" 13 years ago
David Majda aeb2cb4f1c Make sure quoting functions output only ASCII characters
This patch prevents portability problems. In particular, it fixes a
problem where "SyntaxError: Invalid range in character class." error
appeared when using command-line version on Widnows (see GH-13).
14 years ago
David Majda 2120de36af Behave like CommonJS module in CommonJS context 14 years ago
David Majda 2d38c5cab3 Handle non-unique expected values of match failuers differently
Before this commit, uniqueness was checked when addding the failure. Now
we make the entiries unique when generating the error report, saving a
little time when the parsing is successful. This does not increase the
benchmark numbers too much though.

Results of benchmark with 100 runs on V8:

  Before:  37.25 kB/s
  After:   37.41 kB/s
  Speedup: 0.241 %

Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.3 (KHTML, like
Gecko) Chrome/6.0.472.63 Safari/534.3
14 years ago
David Majda 906488027b Fix stupid mistakes in the |buildNodeVisitor| function 14 years ago
David Majda 4d50a37b14 Extract |buildNodeVisitor| 14 years ago
David Majda 1279e87766 Simplify utility functions structure + do not export them as part of the PEG object 14 years ago
David Majda e59f3ba338 Split the source code into several files, introduce build system
The source code is now in the src directory. The library needs to be
built using "rake", which creates the lib/peg.js file by combining the
source files.
14 years ago