From 7fdf0492c775622ddbbff068954d455a062d84bc Mon Sep 17 00:00:00 2001 From: David Majda Date: Mon, 31 May 2010 16:30:02 +0200 Subject: [PATCH] Fixed error message for invalid character range + added test --- lib/metagrammar.js | 2 +- lib/metagrammar.pegjs | 2 +- test/metagrammar-test.js | 9 ++++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/metagrammar.js b/lib/metagrammar.js index bc2817f..e00b36c 100644 --- a/lib/metagrammar.js +++ b/lib/metagrammar.js @@ -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 + "." ); } diff --git a/lib/metagrammar.pegjs b/lib/metagrammar.pegjs index 2379372..d8ded8c 100644 --- a/lib/metagrammar.pegjs +++ b/lib/metagrammar.pegjs @@ -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 + "." ); } diff --git a/test/metagrammar-test.js b/test/metagrammar-test.js index 2b2dbf7..9b6aae5 100644 --- a/test/metagrammar-test.js +++ b/test/metagrammar-test.js @@ -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". */