Fixed PEG.buildParser's documentation and added a test.

redux
David Majda 15 years ago
parent 48da65d08e
commit 3f5cb8850c

@ -15,9 +15,10 @@ function nop() {}
* metagrammar.pegjs file. The start rule may be unspecified, in which case * metagrammar.pegjs file. The start rule may be unspecified, in which case
* "start" is used. * "start" is used.
* *
* Throws |PEG.Grammar.GrammarError| if the grammar contains an error. Note that * Throws |PEG.grammarParser.SyntaxError| if the grammar contains a syntax error
* not all errors are detected during the generation and some may protrude to * or |PEG.Grammar.GrammarError| if it contains a semantic error. Note that not
* the generated parser and cause its malfunction. * all errors are detected during the generation and some may protrude to the
* generated parser and cause its malfunction.
*/ */
PEG.buildParser = function(grammar, startRule) { PEG.buildParser = function(grammar, startRule) {
startRule = startRule || "start"; startRule = startRule || "start";

@ -169,6 +169,13 @@ test("generateUniqueIdentifier", function() {
module("PEG"); module("PEG");
test("buildParser reports syntax errors in the grammar", function() {
throws(
function() { PEG.buildParser(''); },
PEG.grammarParser.SyntaxError
);
});
test("buildParser reports missing start rule", function() { test("buildParser reports missing start rule", function() {
throws( throws(
function() { PEG.buildParser('notStart: "abcd"'); }, function() { PEG.buildParser('notStart: "abcd"'); },

Loading…
Cancel
Save