Fixed error message for invalid character range + added test

redux
David Majda 14 years ago
parent f9ea46ef15
commit 7fdf0492c7

@ -2061,7 +2061,7 @@ PEG.grammarParser = (function(){
? (function($1, $2, $3) {
if ($1.data.charCodeAt(0) > $3.data.charCodeAt(0)) {
throw new this.SyntaxError(
"Invalid character range: " + $1.rawText + "-" + $2.rawText + "."
"Invalid character range: " + $1.rawText + "-" + $3.rawText + "."
);
}

@ -160,7 +160,7 @@ class "character class": "[" "^"? (classCharacterRange / classCharacter)* "]" __
classCharacterRange: classCharacter "-" classCharacter {
if ($1.data.charCodeAt(0) > $3.data.charCodeAt(0)) {
throw new this.SyntaxError(
"Invalid character range: " + $1.rawText + "-" + $2.rawText + "."
"Invalid character range: " + $1.rawText + "-" + $3.rawText + "."
);
}

@ -12,6 +12,10 @@ global.grammarParserDoesNotParse = function(input) {
global.doesNotParse(PEG.grammarParser, input);
}
global.grammarParserDoesNotParseWithMessage = function(input, message) {
global.doesNotParseWithMessage(PEG.grammarParser, input, message);
}
/* ===== Grammar Parser ===== */
module("Grammar Parser");
@ -352,7 +356,10 @@ test("parses class", function() {
test("parses classCharacterRange", function() {
grammarParserParses("start: [a-d]", classGrammar(false, [["a", "d"]], "[a-d]"));
grammarParserParses("start: [a-a]", classGrammar(false, [["a", "a"]], "[a-a]"));
grammarParserDoesNotParse("start: [b-a]");
grammarParserDoesNotParseWithMessage(
"start: [b-a]",
"Invalid character range: b-a."
);
});
/* Canonical classCharacter is "a". */

Loading…
Cancel
Save