Permalink
Browse files

Correct error messages.

  • Loading branch information...
cweider committed Nov 13, 2011
1 parent a3d5e6a commit ea251f2b9308f432eaa55b4ac33ec9c478622de0
Showing with 7 additions and 5 deletions.
  1. +7 −5 lexer.js
View
@@ -48,7 +48,7 @@ var Lexer = function (rules) {
var type = rule[1];
if ((typeof type != 'string' || type.length == 0)
&& type !== null) {
- throw new Error("Expected String or null instead found \""
+ throw new Error("Expected String or null instead found "
+ JSON.stringify(String(type))
+ " for type of rule at index " + i + ".");
}
@@ -105,8 +105,9 @@ Lexer.prototype = new function () {
while (tokenMatch = tokenRegExp.exec(text)) {
// Throw if character is skipped.
if (tokenMatch.index != index) {
- throw new Error("Unexpected character found '"
- + text.charAt(index) + "' at index " + index + ".");
+ throw new Error("Unexpected character found "
+ + JSON.stringify(String(text.charAt(index))) + " at index "
+ + index + ".");
}
index += tokenMatch[0].length;
@@ -148,8 +149,9 @@ Lexer.prototype = new function () {
// Throw if all input isn't consumed.
if (text.length != index) {
- throw new Error("Unexpected character found' "
- + text.charAt(index) + "' at index " + index + ".");
+ throw new Error("Unexpected character found "
+ + JSON.stringify(String(text.charAt(index))) + " at index "
+ + index + ".");
}
return tokens;

0 comments on commit ea251f2

Please sign in to comment.