238 Commits (810567d865930f2ef379aaaffdc6d0e87ca1555c)

Author SHA1 Message Date
David Majda 3333cdd18d Position tracking: Kill the |trackLineAndColumn| option
Getting rid of the |trackLineAndColumn| simplifies the code generator
(by unifying two paths in the code).

The |line| and |column| functions currently always compute all the
position info from scratch, which is horribly ineffective. This will be
improved in later commit(s).
12 years ago
David Majda da8c455640 Position tracking: Make |offset|, |line| and |column| functions
This will allow to compute position data lazily and get rid of the
|trackLineAndColumn| option without affecting performance of generated
parsers that don't use position data.
12 years ago
David Majda 05a6bad989 Kill the |toSource| method, introduce the |output| option
Before this commit, |PEG.buildParser| always returned a parser object.
The only way to get its source code was to call the |toSource| method on
it. While this method worked for parsers produced by |PEG.buildParser|
directly, it didn't work for parsers instantiated by executing their
source code. In other words, it was unreliable.

This commit remvoes the |toSource| method on generated parsers and
introduces a new |output| option to |PEG.buildParser|. It allows callers
to specify whether they want to get back the parser object
(|options.output === "parser"|) or its source code (|options.output ===
"source"|). This is much better and more reliable API.
12 years ago
David Majda 0519d7e3ce Git repo npmization: Make the repo a npm package
Includes:

  * Moving the source code from /src to /lib.
  * Adding an explicit file list to package.json
  * Updating the Makefile.
  * Updating the spec and benchmark suites and their READMEs.

Part of a fix for GH-32.
12 years ago
David Majda 208cc33930 Allowed start rules must be specified explicitly
Before this commit, generated parser were able to start parsing from any
rule. This was nice, but it made rule code inlining impossible.

Since this commit, the list of allowed start rules has to be specified
explicitly using the |allowedStartRules| option of the |PEG.buildParser|
method (or the --allowed-start-rule option on the command-line). These
rules will be excluded from inlining when it's implemented.
12 years ago
David Majda 75a78c083c Fix typo in testcase description 12 years ago
David Majda 98ff2eb83f Allow passing options to the parser
This commit replaces the |startRule| parameter of the |parse| method in
generated parsers with more generic |options| -- an options object. This
options object can be used to pass custom options to the parser because
it is visible as the |options| variable inside parser code.

The start rule can now be specified as the |startRule| option. This
means you have to replace all calls like:

  parser.parse("input", "myStartRule");

with

  parser.parse("input", { startRule: "myStartRule" });

Closes GH-37.
12 years ago
David Majda e90aacd934 Specs: Whitespace fix + add semicolon in tested parser code 12 years ago
David Majda 7134b09e50 Merge |allocateRegisters| and |computeParams| passes
The purpose of this change is to avoid the need to index register
variables storing match results of sequences whose elements are labeled.
The indexing happened when match results of labeled elements were passed
to action/predicate functions.

In order to avoid indexing, the register allocator needs to ensure that
registers storing match results of any labeled sequence elements are
still "alive" after finishing parsing of the sequence. They should not
be used to store anything else at least until code of all actions and
predicates that can see the labels is executed. This requires that the
|allocateRegisters| pass has the knowledge of scoping. Because that
knowledge was already implicitly embedded in the |coputeParams| pass,
the logical step to prevent duplication was to merge it with the
|allocateRegisters| pass. This is what this commit does.

As a part of the merge the tests of both passes were largely refactored.
This is both to accomodate the merge and to make the tests in sync with
the code again (the tests became a bit out-of-sync during the last few
commits -- they tested more than was needed).

The speed/size impact is slightly positive:

Speed impact
------------
Before:     849.86 kB/s
After:      858.16 kB/s
Difference: 0.97%

Size impact
-----------
Before:     876618 b
After:      875602 b
Difference: -0.12%

(Measured by /tools/impact with Node.js v0.6.18 on x86_64 GNU/Linux.)
12 years ago
David Majda 2d36ebeb59 Mental model change: Variables do not form a stack, they are registers
This commit changes the model underlying parser variables used to store
match results and parse positions. Until now they were treated as a
stack, now they are thought of as registers. The actual behavior does
not change (yet), only the terminology.

More specifically, this commit:

  * Changes parser variable names from |result0|, |result1|, etc. to
    |r0|, |r1|, etc.

  * Changes various internal names and comments to match the new model.

  * Renames the |computeVarIndices| pass to |allocateRegisters|.
12 years ago
David Majda 2f3dd951e9 Do not store result variable indices, just the counts 12 years ago
David Majda 42d4fc6dd4 Get rid of two parser variable stacks
One stack is conceptually simpler, requires less code and will make a
transition to a register-based machine easier.

Note that the stack variables are now named a bit incorrectly
(|result0|, |result1|, etc. even when they store also parse positions).
I didn't bother with renaming because a transition to a register-based
machine will follow soon and the names will change anyway.

The speed/size impact is insignificant.

Speed impact
------------
Before:     839.05 kB/s
After:      839.67 kB/s
Difference: 0.07%

Size impact
-----------
Before:     949783 b
After:      961578 b
Difference: 1.24%

(Measured by /tools/impact with Node.js v0.6.18 on x86_64 GNU/Linux.)
12 years ago
David Majda 2c8b323ade Replace variable name computations by computations of indices
This commit replaces all variable name computations in |computeVarNames|
and |computeParams| passes by computations of indices. The actual names
are computed later in the |generateCode| pass.

This change makes the code generator the only place that deals with the
actual variable names, making them easier to change for example.

The code generator code seems bit more complicated after the change, but
this complexity will pay off (and mostly disappear) later.
12 years ago
David Majda 725927e05f Change ordering of "action" code
Places all code that does something with "action" AST nodes under code
handling "choice" nodes.

This ordering is logical because now all the node handling code matches
the sequence in which various node types usually appear when descending
through the AST tree.
12 years ago
David Majda cdf23e0a49 Change ordering of "literal", "class" and "any" code
Changes all code that does something with "literal", "class" or "any"
AST nodes so that the code deals with these in the follwing order:

  1. literal
  2. class
  3. any

Previously the code used this ordering:

  1. literal
  2. any
  3. class

The new ordering is more logical because the nodes are handled from the
most specific to the most generic.
12 years ago
David Majda eb4badab24 Refactor named rules AST representation
PEG.js grammar rules are represented by |rule| nodes in the AST. Until
now, all such nodes had a |displayName| property which was either |null|
or stored rule's human-readable name. This commit gets rid of the
|displayName| property and starts representing rules with a
human-readable name using a new |named| node (a child of the |rule|
node).

This change simplifies code generation code a bit as tests for
|displayName| can be removed (see changes in generate-code.js). It also
separates different concerns from each other nicely.
12 years ago
David Majda a59516f89b Small reordering of properties when creating |class| nodes
General rule: Least important things/flags go last.
12 years ago
David Majda 55a255a882 Add forgotten tests for |nonBraceCharacter| & |nonBraceCharacters| rules 12 years ago
David Majda 7900b66c70 Fix |braced| rule in the PEG.js grammar
This fix does not change the behavior, it just makes the
|nonBraceCharacters| rule un-dead (as originally intended).
12 years ago
David Majda 8ef5f08c90 Jasmine: Convert |removeProxyRules| compiler pass tests 12 years ago
David Majda eaf2af8e7b Jasmine: Convert |computeParams| compiler pass tests 12 years ago
David Majda 4edc9982cc Jasmine: Convert |computeVarNames| compiler pass tests 12 years ago
David Majda 1471df9a69 Jasmine: Convert |reportLeftRecursion| compiler pass tests 12 years ago
David Majda 2889ca72fc Jasmine: Convert |reportMissingRules| compiler pass tests 12 years ago
David Majda ef25ec08c2 Extract |varyAll| calls one level up
DRY + less code.
12 years ago
David Majda 112e4122d0 Jasmine: Convert remaining error reporting tests 12 years ago
David Majda 94aaf4ec75 Jasmine: Convert error position reporting tests 12 years ago
David Majda 1825dd4a42 Jasmine: Convert start rule tests 12 years ago
David Majda f61813238d Jasmine: Convert complex example tests 12 years ago
David Majda 022a51f94e Jasmine: Convert cache tests 12 years ago
David Majda e9f7255d47 Jasmine: Convert initializer tests 12 years ago
David Majda f5f40f68d2 Jasmine: Convert choice matching tests 12 years ago
David Majda 1b0789fbae Jasmine: Convert sequence matching tests 12 years ago
David Majda ae8a89c9e4 Jasmine: Convert labeled matching tests 12 years ago
David Majda b013ba8cc9 Jasmine: Convert simple and matching tests 12 years ago
David Majda 343e9db525 Jasmine: Convert simple not matching tests 12 years ago
David Majda 2bb25efa44 Jasmine: Convert semantic and code tests 12 years ago
David Majda f04096189f Jasmine: Convert semantic not code tests 12 years ago
David Majda ccf31f8822 Jasmine: Convert optional matching tests 12 years ago
David Majda 669668fc1b Jasmine: Convert zero or more matching tests 12 years ago
David Majda 1ab06ff906 Jasmine: Convert one or more matching tests 12 years ago
David Majda 03716a562d Jasmine: Convert action code tests 12 years ago
David Majda b06bd774f5 Jasmine: Convert rule reference matching tests 12 years ago
David Majda 14c11b4dfc Jasmine: Convert class matching tests 12 years ago
David Majda 75ab03dc85 Jasmine: Convert any matching tests 12 years ago
David Majda ec48742032 Jasmine: Convert literal matching tests 12 years ago
David Majda 94205ab639 Jasmine: Convert tests of parser's "grammar" rule 12 years ago
David Majda f746189f2b Jasmine: Convert tests of parser's "initializer" rule 12 years ago
David Majda a49674b05f Jasmine: Change |oneRuleGrammar| parameter handling
This change makes code using |oneRuleGrammar| less verbose + prepares
for passing of the initializer (will be used by code added in the next
few commits).
12 years ago
David Majda 171d62fce4 Jasmine: Convert tests of parser's "rule" rule 12 years ago
David Majda e17d4de7ae Jasmine: Convert tests of parser's "expression" rule 12 years ago
David Majda cc22086a09 Jasmine: Convert tests of parser's "choice" rule 12 years ago
David Majda 434abdb272 Jasmine: Convert tests of parser's "sequence" rule 12 years ago
David Majda ec8889f85d Jasmine: Convert tests of parser's "labeled" rule 12 years ago
David Majda bf6d412a4f Jasmine: Convert tests of parser's "prefixed" rule 12 years ago
David Majda 3e083cc51b Jasmine: Convert tests of parser's "suffixed" rule 12 years ago
David Majda 45f825c24f Jasmine: Convert tests of parser's "primary" rule 12 years ago
David Majda 57bbcd71e5 Jasmine: Convert tests of parser's "action" rule 12 years ago
David Majda 35771e15bc Jasmine: Convert tests of parser's "braced" rule 12 years ago
David Majda b1cb214e8b Jasmine: Convert non-tests of parser's character class rules 12 years ago
David Majda 4f5b78b372 Jasmine: Convert tests of parser's "identifier" rule 12 years ago
David Majda a3d93f000f Jasmine: Convert tests of parser's "literal" rule 12 years ago
David Majda 573db92583 Jasmine: Convert tests of parser's "string" rule 12 years ago
David Majda fa65018b15 Jasmine: Convert tests of parser's "doubleQuotedString" rule 12 years ago
David Majda 0e384b31f4 Jasmine: Convert tests of parser's "doubleQuotedCharacter" rule 12 years ago
David Majda 2f5f8d5932 Jasmine: Convert tests of parser's "simpleDoubleQuotedCharacter" rule 12 years ago
David Majda fb01f48c97 Jasmine: Convert tests of parser's "singleQuotedString" rule 12 years ago
David Majda d3b3fe9b78 Jasmine: Convert tests of parser's "singleQuotedCharacter" rule 12 years ago
David Majda 124e45606c Jasmine: Convert tests of parser's "simpleSingleQuotedCharacter" rule 12 years ago
David Majda ba68919b0a Jasmine: Convert tests of parser's "class" rule 12 years ago
David Majda 5fb59b05f2 Jasmine: Convert tests of parser's "classCharacterRange" rule 12 years ago
David Majda d29a753b8d Jasmine: Convert tests of parser's "classCharacter" rule 12 years ago
David Majda b9ae8f9561 Jasmine: Convert tests of parser's "bracketDelimitedCharacter" rule 12 years ago
David Majda da4ac8bb92 Jasmine: Convert tests of parser's "simpleBracketDelimitedCharacter" rule 12 years ago
David Majda 2bb266bbaf Jasmine: Convert tests of parser's "simpleEscapeSequence" rule 12 years ago
David Majda 2619becb9d Jasmine: Convert tests of parser's "zeroEscapeSequence" rule 12 years ago
David Majda 2b43f8ebb8 Jasmine: Convert tests of parser's "hexEscapeSequence" rule 12 years ago
David Majda 0bbca136a2 Jasmine: Convert tests of parser's "unicodeEscapeSequence" rule 12 years ago
David Majda a27dc5ae4a Jasmine: Convert tests of parser's "eolEscapeSequence" rule 12 years ago
David Majda 4f91286013 Jasmine: Convert non-tests of parser's character class rules 12 years ago
David Majda 3bc61c4c50 Jasmine: Convert tests of parser's "__" rule 12 years ago
David Majda fadaef84dd Jasmine: Convert tests of parser's "comment" rule 12 years ago
David Majda b5ccaed491 Jasmine: Convert tests of parser's "singleLineComment" rule 12 years ago
David Majda dac3b0d8d9 Jasmine: Convert tests of parser's "multiLineComment" rule 12 years ago
David Majda 328edf667c Jasmine: Convert tests of parser's "eol" rule 12 years ago
David Majda b4cffee9d4 Jasmine: Convert tests of parser's "eolChar" rule 12 years ago
David Majda a46b9c197b Jasmine: Convert tests of parser's "whitespace" rule 12 years ago
David Majda c27b96051a Jasmine: Initial infrastructure
This is the first of many commits that gradually convert PEG.js's test
suite from QUnit to Jasmine, cleaning it up on the way.

Main reason for the change is that Jasmine allows nested contexts,
allowing to structure the tests in a better way than QUnit. Moreover,
the tests needed to be cleaned up a bit.
12 years ago