70 Commits (0dab14d652dce2c247c2b1d3cd4be472e9a54ef1)

Author SHA1 Message Date
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 4cda79951a Git repo npmization: Compose PEG.js from Node.js modules
PEG.js source code becomes a set of Node.js modules that include each
other as needed. The distribution version is built by bundling these
modules together, wrapping them inside a bit of boilerplate code that
makes |module.exports| and |require| work.

Part of a fix for GH-32.
12 years ago
David Majda a4df483159 s/Modelled/Modeled/
"modelled" is a British variant, "modeled" an US one. PEG.js officially
uses American English.

Based on pull request by John Gietzen:

  https://github.com/dmajda/pegjs/pull/102
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 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 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 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 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 98cbd57ead Add two missing |var|s (fix global namespace pollution) 13 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