56 Commits (fb72c430e6b4581d88c6c10ab036033960b77888)

Author SHA1 Message Date
David Majda fb72c430e6 PEG.js grammar: Fix line continuation handling
Before this commit, a line continuation (backslash followed by a line
terminator character) contributed a character to a string or a character
class it was used in. In JavaScript and many other languages, line
continuation doesn't contribute anything.

This commit aligns PEG.js line continuation behavior with JavaScript.
10 years ago
David Majda 3dbec0b30d PEG.js grammar: Fix how |rawText| is created
Before this commit, the value of the |rawText| property of "class" AST
nodes was created in a hackish way from processed input and it didn't
always exactly represent the actual input text.

This commit changes the code so that the value of the |rawText| property
is created using the |text| function. This is a clean way which also
resolves the exact representation problem.
10 years ago
David Majda df154daafb PEG.js grammar: Disallow empty sequences
Empty sequences are useless and they only confused users. Let's disallow
them.
10 years ago
David Majda 95fd64ec15 .jshintrc: Add the "forin" option & fix fallout
Also added few missing |hasOwnProperty| calls that JSHint didn't detect
because it only looks whether there is an |if| statement wrapping the
loop body.
11 years ago
David Majda fbcefdf523 Fix |oneRuleGrammar| invocation
At one call site, the |oneRuleGrammar| was called with 3 parameters but
it only accepts 2. This commit removes the additional parameter.
11 years ago
David Majda 5942988f66 Remove the |startRule| property from the AST
It's redundant.
11 years ago
David Majda d61fd1792d Fix JSHint errors
Fixes the following JSHint errors (which I think are JSHint bugs):

  spec/parser.spec.js: line 142, col 20, Bad for in variable 'key'.
  spec/generated-parser.spec.js: line 119, col 20, Bad for in variable 'key'.
11 years ago
David Majda 5e146fce38 Text nodes: Implement text nodes
Implement a new syntax to extract matched strings from expressions. For
example, instead of:

  identifier = first:[a-zA-Z_] rest:[a-zA-Z0-9_]* { return first + rest.join(""); }

you can now just write:

  identifier = $([a-zA-Z_] [a-zA-Z0-9_]*)

This is useful mostly for "lexical" rules at the bottom of many
grammars.

Note that structured match results are still built for the expressions
prefixed by "$", they are just ignored. I plan to optimize this later
(sometime after the code generator rewrite).
12 years ago
David Majda af20f024c7 Text nodes: Disallow the "$" character in identifiers
The "$" character will mark text nodes in the future.
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 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