32 Commits (3333cdd18d702e257ddefb90e9230397beef91fc)

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 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 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 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