112 Commits (abf33d3feb7a0d488b13b895b7d6b7827bc29b45)

Author SHA1 Message Date
David Majda d35b21e9b2 Simplify the |indent| function in /test/run 12 years ago
David Majda 9d5990f80a Update code formatting in /test/run to match conventions I use elsewhere 12 years ago
David Majda 6d624a89bd Update bundled QUnit to version 1.5.0 12 years ago
David Majda 52d7ec2224 Implement |trackLineAndColumn| option for |PEG.buildParser|
This option makes the generated parser track line and column during
parsing. Tracked line and column are made available inside actions and
predicates as |line| and |column| variables.

Note that in actions these variables denote start position of the
action's expression while in predicates they denote the current
position. The slightly different behavior is motivated by expected
usage.
12 years ago
David Majda f2f88b87ea Make current parse position visible in actions and predicates
The speed/size impact is insignificant.

Speed impact
------------
Before:     214.11 kB/s
After:      214.87 kB/s
Difference: 0.35%

Size impact
-----------
Before:     1042691 b
After:      1046731 b
Difference: 0.38%

(Measured by /tools/impact with Node.js v0.6.6 on x86_64 GNU/Linux.)
12 years ago
David Majda f47da5c682 Fix a bug in param name fixup code for sequences 12 years ago
David Majda 4d5b1d58aa AST: Store rules in an array instead of an object
This simplifies the code a bit and makes the AST more regular (each node
type has a fixed set of properties). The latter may get useful later
when generalizing visitors.
12 years ago
David Majda a2af1fe612 Semantic predicates now have access to preceding labels
Part of a fix for GH-69.
12 years ago
David Majda 4cf50bcf9f Move param computations from the emitter into a separate pass
This has two main benefits:

  1. The knowledge about scoping params in at one designated place,
     making all future adjustments in this area easier.

  2. Action-related code does not handle sequences specially anymore.
     Such knowledge/behavior doesn't belong there.
12 years ago
David Majda efc38eef9b Consolidate all variable name computations into one compiler pass
Before this change, knowledge about variable names was spread between
the |computeStackDepths| pass and the code emitter code. For example,
the fact that the |&...| expression needs one variable to store a
position was represented in both places.

This changes consolidates that knowledge and introduces a new
|computeVarNames| pass. This pass replaces old |computeStackDepths|
pass, does all computations realted to variable names and stores the
results in the AST. Note that some knowledge about variables
(inevitably) remained in emitter code templates.

Beside DRYing things up, this change simplifies the emitter
significantly. By storing variable names in the AST it also allows
introduction of a pass that will identify parameters passed to actions
using proper symbol tables. Right now, this is done in a hackish way
directly in the emitter, which won't work well with changes planned in
GH-69.
12 years ago
David Majda 46b2eaf3e3 Add |expected| and |found| properties to exceptions thrown by parsers
Based on a patch by Marcin Stefaniuk (marcin@stefaniuk.info).
12 years ago
David Majda 21c6d9ccd3 Add |offset| property to exceptions thrown by parsers
Based on a patch by Marcin Stefaniuk (marcin@stefaniuk.info).
12 years ago
David Majda fb5028eb90 Use |util| module instead of |sys|
|sys| emits a warning in Node.js 0.6.x.
12 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 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 9c3da347cc Fix string parsing tests
The tests were wrong because the |string| rule is not used to parse
literals but rule names.
13 years ago
David Majda 3421bdb813 Test trailing characters for strings and literals at correct places 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 88c50a3e33 Add tests for zero- and one-char literals
We optimize these cases in the emitter so we should better test them.
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 cb2415a4fd Fix output printed during test failures
Expected value was being printed instead of the actual one.

Original patch by Wolfgang Kluge:

  1e875d4479
13 years ago
David Majda 17f62ae9e3 test/parser-test.js: Replace "\0" with "\x00"
Fixes the following JSHint errors:

  ./test/parser-test.js: line 353, col 54, Bad escapement.
  ./test/parser-test.js: line 384, col 54, Bad escapement.
  ./test/parser-test.js: line 436, col 60, Bad escapement.
  ./test/parser-test.js: line 437, col 60, Bad escapement.
  ./test/parser-test.js: line 472, col 50, Bad escapement.
13 years ago
David Majda 934bfa5eef test/parser-test.js: Fix missing/unnecessary semicolons
Fixes the following JSHint errors:

  ./test/parser-test.js: line 49, col 4, Missing semicolon.
  ./test/parser-test.js: line 58, col 4, Missing semicolon.
  ./test/parser-test.js: line 77, col 2, Unnecessary semicolon.
  ./test/parser-test.js: line 137, col 23, Missing semicolon.
13 years ago
David Majda d84f38c64b test/parser-test.js: Fix comments that look like nested to JSHint
Fixes the following JSHint errors:

  ./test/parser-test.js: line 521, col 29, Nested comment.
  ./test/parser-test.js: line 521, col 29, Stopping, unable to continue. (87% scanned).
13 years ago
David Majda 34d19a7dc6 test/passes-test.js: Add missing semicolons
Fixes the following JSHint errors:

  ./test/passes-test.js: line 12, col 6, Missing semicolon.
  ./test/passes-test.js: line 25, col 4, Missing semicolon.
  ./test/passes-test.js: line 229, col 41, Missing semicolon.
13 years ago
David Majda 0fe5769024 test/checks-test.js: Avoid function definitions in loops
Fixes the following JSHint errors:

  ./test/checks-test.js: line 26, col 8, Don't make functions within a loop.
  ./test/checks-test.js: line 31, col 5, Don't make functions within a loop.
  ./test/checks-test.js: line 59, col 8, Don't make functions within a loop.
  ./test/checks-test.js: line 64, col 5, Don't make functions within a loop.
13 years ago
David Majda 96192417d8 test/compiler-test.js: Remove extra comma
Fixes the following JSHint error:

  ./test/compiler-test.js: line 498, col 49, Extra comma.
13 years ago
David Majda e93eaa0e0e test/compiler-test.js: Add missing semicolon
Fixes the following JSHint error:

  ./test/compiler-test.js: line 420, col 47, Missing semicolon.
13 years ago
David Majda a92676edce Upgrade QUnit to the current master
Exact commit ID: 96e42601cadcba989f80bd4c294b7e0ee4ff1d29
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 8b2edd3c41 Remove trailing comma in parser tests (IE compatibility) 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 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
13 years ago
David Majda 3e7d31559d Do not pass |global| into wrapping functions in tests, it's useless 13 years ago
David Majda cfc6041041 Remove function wrapping and all |global| refrences from helpers.js
Originally I wanted to be very explicit with accesses to global object,
but since all this file is about extending it, the |global.| qualifier
seems more like noise.
13 years ago
David Majda 918dcf6ed2 Test and benchmark command-line runners can be run from any directory 13 years ago
David Majda 8f005c027b Fix encoding in |fs.readFileSync| calls ("utf-8" -> "utf8") 13 years ago
David Majda d0c074e2f8 Small style fixes 13 years ago
David Majda afcceb127f Add command-line runner for the test suite
The output format and code is heavily inspired by Nodeunit and code in
QUnit's "cli" branch.
13 years ago
David Majda 0e9d58ea96 Upgrade QUnit to the current master (c532d183664118fc2ca1) 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 d493a4d143 Move test helper into its own file + reorder test file includes 14 years ago
David Majda fea6d85194 Little compiler tests clean-up 14 years ago