189 Commits (364482dd686fd85ca99170aefd62490748f2f6be)

Author SHA1 Message Date
David Majda 791c495aec Update embedded Codie to version 1.0.1 13 years ago
David Majda 47969a2f61 Replace |for| loop iterating over sequence elements with |each| 13 years ago
David Majda a19ea83ffa Replace |for| loop iterating over compiler passes with |each| 13 years ago
David Majda cd5490dee4 Make pass list customizable via |PEG.compiler.appliedPassNames| property 13 years ago
David Majda 8a0276ffb7 Unify checks and passes
There is no real reason to have them separated.
13 years ago
David Majda 6cd5bdc5e6 Passes now do not return anything (they always modify the AST in-place) 13 years ago
David Majda 3983f46d5d Rename |reportMissingReferencedRules| check to |reportMissingRules|
The new name is shorter, there is no real loss of meaning.
13 years ago
David Majda 64d26e5db2 Make names of compiler checks and passes verbs 13 years ago
David Majda 2a82d863e5 Regenerate src/parser.js (forgot to do it in previous commit) 13 years ago
David Majda 8acea01525 Fix reported error position when part of the input is not consumed
Closes GH-48.
13 years ago
David Majda 211a1116e4 Fix stack depth computations for empty sequences
Part of a fix for GH-53.
13 years ago
David Majda afdcb6fc4f Fix |posStackDepth| computation for rules
Rules by themselves do not need any variable for storing position.

Part of a fix for GH-53.
13 years ago
David Majda 756b6fc473 Fix |resultStackDepth| computation for sequences
The |1 + ...| was wrong -- sequence does not need its own variable since
it reuses the one used by the first item.

Part of a fix for GH-53.
13 years ago
David Majda c639c1fc83 PEG.js grammar: Replace two instances of |string / ""| by |string?| 13 years ago
David Majda c04af99df8 Implament case-insensitive class matching 13 years ago
David Majda b540b2d460 Implement case-insensitive literal matching 13 years ago
David Majda 1c11e4aaa3 Split |literal| rule in the PEG.js grammar to |literal| and |string|
This is just a formality now but it will make sense later when literals
(but not strings) will allow "i" flag for case-insensitive matching.
13 years ago
David Majda da12c2f5d4 Compile Codie templates only once 13 years ago
David Majda a5af9611a2 Introduce |context.delta| function to make creating contexts more DRY 13 years ago
David Majda be3b87ec71 Refactor "grammar" emitter function a bit 13 years ago
David Majda 2b09a7116d Refactor "rule" emitter function a bit 13 years ago
David Majda 131b6dd01f Refactor "sequence" emitter function a bit 13 years ago
David Majda f29ff236b8 Refactor "simple_and" emitter function a bit 13 years ago
David Majda 506d8107a1 Refactor "simple_not" emitter function a bit 13 years ago
David Majda 13ae52b2bf Refactor "semantic_and" emitter function a bit 13 years ago
David Majda 9111020ca2 Refactor "semantic_not" emitter function a bit 13 years ago
David Majda cc3bd4f310 Refactor "zero_or_more" emitter function a bit 13 years ago
David Majda 85c1b010b6 Refactor "one_or_more" emitter function a bit 13 years ago
David Majda b5ca96dd48 Refactor "action" emitter function a bit 13 years ago
David Majda 50a0371e2d Refactor "rule_ref" emitter function a bit 13 years ago
David Majda eaba6b8a9d Refactor "literal" emitter function a bit 13 years ago
David Majda 2120c908c7 Refactor "class" emitter function a bit 13 years ago
David Majda 0748fee1d3 Use Codie for code templates
This will allow moving some code into the templates later.
13 years ago
David Majda 38c25efde0 Use single quotes for code in the emitter
Strings with code should use single quotes so that double quotes (which
I generally prefer) could be used in the code itself without escaping.
13 years ago
David Majda 45c99f8f6b Generate more efficient code for empty literals
Original patch by Wolfgang Kluge:

  797173f676
13 years ago
David Majda 4de3cc1716 Fix comment typos
Original patch by Wolfgang Kluge:

  07e0cfcc02
13 years ago
David Majda eceda8b5e8 Use correct disjunction operator in |computeErrorPosition|
Original patch by Wolfgang Kluge:

  6b793b33df
13 years ago
David Majda cc4910d9b9 src/compiler.js: Fix variable redefinition
Fixes the following JSHint error:

  ./src/compiler.js: line 23, col 16, 'i' is already defined.
13 years ago
David Majda bc4821581c src/emitter.js: Fix variable redefinitions
Fixes the following JSHint errors:

  ./src/emitter.js: line 95, col 21, 'name' is already defined.
  ./src/emitter.js: line 361, col 35, 'setReportFailuresCode' is already defined.
  ./src/emitter.js: line 362, col 39, 'restoreReportFailuresCode' is already defined.
  ./src/emitter.js: line 363, col 31, 'reportFailureCode' is already defined.
  ./src/emitter.js: line 393, col 38, 'setReportFailuresCode' used out of scope.Fixes the following JSHint errors:
  ./src/emitter.js: line 394, col 38, 'restoreReportFailuresCode' used out of scope.
  ./src/emitter.js: line 395, col 38, 'reportFailureCode' used out of scope.
  ./src/emitter.js: line 666, col 26, 'formalParams' is already defined.
  ./src/emitter.js: line 667, col 26, 'actualParams' is already defined.
  ./src/emitter.js: line 669, col 26, 'formalParams' is already defined.
  ./src/emitter.js: line 670, col 26, 'actualParams' is already defined.
  ./src/emitter.js: line 685, col 27, 'formalParams' used out of scope.
  ./src/emitter.js: line 686, col 27, 'actualParams' used out of scope.
  ./src/emitter.js: line 770, col 20, 'regexp' is already defined.
  ./src/emitter.js: line 784, col 22, 'regexp' used out of scope.
13 years ago
David Majda a52522c7c6 src/emitter.js: Remove unnecessary semicolon
Fixes the following JSHint error:

  ./src/emitter.js: line 77, col 4, Unnecessary semicolon.
13 years ago
David Majda d1b83e4ab3 src/emitter.js: Use strict comparison
Fixes the following JSHint error:

  ./src/emitter.js: line 44, col 48, Expected '!==' and instead saw '!='.
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 67afc788ad src/parser.pegjs: Use radix in |parseInt| calls instead of "0x" prefix
Fixes the following JSHint errors:

  ./src/parser.js: line 2878, col 44, Missing radix parameter.
  ./src/parser.js: line 2949, col 44, Missing radix parameter.
13 years ago
David Majda 13c47d6c4f src/parser.pegjs: Replace "\0" with "\x00"
Fixes the following JSHint error:

  ./src/parser.js: line 2820, col 44, Bad escapement.
13 years ago
David Majda b80cd9cb02 src/parser.pegjs: Use strict comparison
Fixes the following JSHint errors:

  ./src/parser.js: line 460, col 50, Expected '!==' and instead saw '!='.
  ./src/parser.js: line 486, col 42, Expected '!==' and instead saw '!='.
13 years ago
David Majda cc416199be src/parser.pegjs: Add missing semicolons
Fixes the following JSHint errors:

  ./src/parser.js: line 193, col 18, Missing semicolon.
  ./src/parser.js: line 407, col 20, Missing semicolon.
  ./src/parser.js: line 2493, col 18, Missing semicolon.
  ./src/parser.js: line 2759, col 40, Missing semicolon.
13 years ago
David Majda 559db3a812 src/emitter.js: Sync |escape| in generated parsers with utils.js
Fixes the following JSHint errors:

  ./src/parser.js: line 102, col 26, 'escapeChar' is already defined.
  ./src/parser.js: line 103, col 22, 'length' is already defined.
  ./src/parser.js: line 106, col 23, 'escapeChar' used out of scope.
  ./src/parser.js: line 106, col 86, 'length' used out of scope.
13 years ago
David Majda e0ef7e1abb src/passes.js: Add missing semicolon
Fixes the following JSHint error:

  ./src/passes.js: line 98, col 8, Missing semicolon.
13 years ago
David Majda 2f671e0022 src/peg.js: Prevent redefinition of |undefined| differently
Fixes the following JSHint error:

  ./src/peg.js: line 5, col 5, Expected an identifier and instead saw 'undefined' (a reserved word).
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 468597be27 Use |charCodeAt| instead of |charCode| when matching one-character literals
The speedup is marginal (if any) but let's have this anyway.

Speed impact
------------
Before:     212.49 kB/s
After:      213.01 kB/s
Difference: 0.24%

Size impact
-----------
Before:     1056976 b
After:      1058314 b
Difference: 0.12%

(Measured by /tools/impact with Node.js v0.4.8 on x86_64 GNU/Linux.)

Closes GH-50.
13 years ago
David Majda d3aff0c66a Use |charAt| instead of |substr| when matching classes
Speed impact
------------
Before:     131.36 kB/s
After:      213.59 kB/s
Difference: 62.59%

Size impact
-----------
Before:     1056976 b
After:      1056976 b
Difference: 0.00%

(Measured by /tools/impact with Node.js v0.4.8 on x86_64 GNU/Linux.)

Closes GH-49.
13 years ago
David Majda 0a1cea5f12 Use |charAt| instead of |substr| when matching one-character literals
Speed impact
------------
Before:     130.62 kB/s
After:      133.76 kB/s
Difference: 2.40%

Size impact
-----------
Before:     1058371 b
After:      1056976 b
Difference: -0.14%

(Measured by /tools/impact with Node.js v0.4.8 on x86_64 GNU/Linux.)
13 years ago
David Majda 2fc877e875 Match literals using |RegExp.prototype.test|
This is little faster than |String.prototype.match| in successful cases
since return value of |test| is just a boolean, not a special array as
with |match|.

Speed impact
------------
Before:     130.75 kB/s
After:      131.81 kB/s
Difference: 0.81%

Size impact
-----------
Before:     1059811 b
After:      1058371 b
Difference: -0.14%

(Measured by /tools/impact with Node.js v0.4.8 on x86_64 GNU/Linux.)
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 bb83b2189a Change how disabling failure reporting works in generated parsers
Disabling failure reporting is driven by the |reportFailures| variable.
So far it was a boolean and its value was saved before changing and
restored afterwards (requiring additional variable in few places). This
patch changes it to an integer where value 0 means "report errors" and
anything > 0 means "do not report errors".  Instead of saving/restoring
we can now simple increment/decrement (avoiding the additional
variable and simplifying the code).

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

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

-----------------------------------
 Test #      Before        After
-----------------------------------
      1   129.26 kB/s   128.28 kB/s
      2   127.34 kB/s   127.53 kB/s
      3   126.72 kB/s   129.01 kB/s
      4   126.89 kB/s   128.05 kB/s
      5   126.46 kB/s   127.98 kB/s
-----------------------------------
Average   127.33 kB/s   128.17 kB/s
-----------------------------------
13 years ago
David Majda c6243fd872 Replace "MatchFailure" by "Failure" in many identifiers
Shorter identifier without much loss of meaning.
13 years ago
David Majda 8f3e2d9344 Update version to 0.6.2 13 years ago
David Majda 747cb8afaa Reset parser position when action returns |null|
The change does not change the benchmark suite execution speed
statistically significantly.

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

-----------------------------------
 Test #      Before        After
-----------------------------------
      1   128.20 kB/s   128.03 kB/s
      2   130.36 kB/s   128.73 kB/s
      3   126.53 kB/s   129.72 kB/s
      4   127.46 kB/s   127.48 kB/s
      5   127.63 kB/s   128.53 kB/s
-----------------------------------
Average   128.04 kB/s   125.50 kB/s
-----------------------------------

Closes GH-25.
13 years ago
David Majda c91dc7e54b Update version to 0.6.1 14 years ago
David Majda b399004a90 Update version to 0.6.0 + update release date in CHANGELOG 14 years ago
David Majda 1f89c7746f Quote keys in |parseFunctions| table in generated parsers
IE and Nitro choked when rule names that are JavaScript reserved words
(e.g. "class") were used.
14 years ago
David Majda 827a5ac312 Add PEG.js version information and homepage header to peg.js 14 years ago
David Majda 9917f79991 Add PEG.js version to "Generated by..." line in generated parsers 14 years ago
David Majda cc7ad9739f Add ability to start parsing from any grammar rule
Calling the parsing function could have been done without the ugly table
using |eval|, but this seemed to degrade performance significantly (by
about 3 %). This is probably because engines optimize badly in presence
of |eval|.

The method used in this patch does not change the benchmark suite
execution speed statistically significantly on V8.

Detailed results (benchmark suite totals):

---------------------------------
 Test #     Before       After
---------------------------------
      1   38.24 kB/s   38.28 kB/s
      2   38.35 kB/s   38.15 kB/s
      3   38.43 kB/s   38.40 kB/s
      4   38.53 kB/s   38.20 kB/s
      5   38.25 kB/s   38.39 kB/s
---------------------------------
Average   38.36 kB/s   38.39 kB/s
---------------------------------

Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.151 Safari/534.1
14 years ago
David Majda 13a3621e79 Export the PEG library in simpler and more robust way 14 years ago
David Majda aa2327191f Escape 0xFF still with "\x", not "\u" 14 years ago
David Majda fc1f489165 Save one concatenation when creating cache keys in generated parsers
Results of benchmark with 100 runs on V8:

  Before:  38.06 kB/s
  After:   38.72 kB/s
  Speedup: 1.734 %

Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.10 (KHTML, like
Gecko) Chrome/8.0.552.237 Safari/534.10
14 years ago
David Majda 98cbd57ead Add two missing |var|s (fix global namespace pollution) 14 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 4ea2003b7b Export PEG.VERSION property with PEG.js version
Value of the property is read in build time from the VERSION file.
14 years ago
David Majda e3effab86b Behave correctly in Rhino context (fixes previous commit) 14 years ago
David Majda 2120de36af Behave like CommonJS module in CommonJS context 14 years ago
David Majda 77ec4f7162 Little bit cleaner way to protect against |undefined| redefinition 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 b6288a8d9c Avoid quoting when reporting errors for literals
This is a small win performance-wise.

Results of benchmark with 100 runs on V8:

  Before:  31.65 kB/s
  After:   32.83 kB/s
  Speedup: 3.728 %

Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.4 (KHTML, like
Gecko) Chrome/5.0.375.127 Safari/533.4
14 years ago
David Majda c8836c0312 Remove two unused variables 14 years ago
David Majda 7b03f164b8 Avoid passing |context| in the generated parser
Passing the context is not necessary, global variable is good enough
(passing the context would make more sense if each AST node was
translated into a function call, but this isn't the case).

The performance gain is very small, on the border of statstical error.

Results of benchmark with 100 runs on V8:

  Before:  31.49 kB/s
  After:   31.57 kB/s
  Speedup: 0.254 %

Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.4 (KHTML, like
Gecko) Chrome/5.0.375.127 Safari/533.4
14 years ago
David Majda a42b957573 Remove now mostly useless comment headers from the code 14 years ago
David Majda f82a4ebf28 Compiler checks and passes are named for easier reference from tests 14 years ago
David Majda 906488027b Fix stupid mistakes in the |buildNodeVisitor| function 14 years ago
David Majda f787793848 Rename |node| -> |subnode| to avoid aliasing 14 years ago
David Majda 088c78e88c Fix incorrect variable name on two places 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