diff --git a/lib/compiler/passes/generate-js.js b/lib/compiler/passes/generate-js.js index 13fd70f..e70d99e 100644 --- a/lib/compiler/passes/generate-js.js +++ b/lib/compiler/passes/generate-js.js @@ -1068,8 +1068,7 @@ function generateJS(ast, options) { ' function expected(description, location) {', ' location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos)', '', - ' throw peg$buildException(', - ' null,', + ' throw peg$buildStructuredError(', ' [peg$otherExpectation(description)],', ' input.substring(peg$savedPos, peg$currPos),', ' location', @@ -1079,7 +1078,7 @@ function generateJS(ast, options) { ' function error(message, location) {', ' location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos)', '', - ' throw peg$buildException(message, null, null, location);', + ' throw peg$buildSimpleError(message, location);', ' }', '', ' function peg$literalExpectation(text, ignoreCase) {', @@ -1164,9 +1163,13 @@ function generateJS(ast, options) { ' peg$maxFailExpected.push(expected);', ' }', '', - ' function peg$buildException(message, expected, found, location) {', + ' function peg$buildSimpleError(message, location) {', + ' return new peg$SyntaxError(message, null, null, location);', + ' }', + '', + ' function peg$buildStructuredError(expected, found, location) {', ' return new peg$SyntaxError(', - ' message !== null ? message : peg$SyntaxError.buildMessage(expected, found),', + ' peg$SyntaxError.buildMessage(expected, found),', ' expected,', ' found,', ' location', @@ -1205,8 +1208,7 @@ function generateJS(ast, options) { ' peg$fail(peg$endExpectation());', ' }', '', - ' throw peg$buildException(', - ' null,', + ' throw peg$buildStructuredError(', ' peg$maxFailExpected,', ' peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null,', ' peg$maxFailPos < input.length', diff --git a/lib/parser.js b/lib/parser.js index d6b5f9b..666f2f5 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -523,8 +523,7 @@ function peg$parse(input, options) { function expected(description, location) { location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos) - throw peg$buildException( - null, + throw peg$buildStructuredError( [peg$otherExpectation(description)], input.substring(peg$savedPos, peg$currPos), location @@ -534,7 +533,7 @@ function peg$parse(input, options) { function error(message, location) { location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos) - throw peg$buildException(message, null, null, location); + throw peg$buildSimpleError(message, location); } function peg$literalExpectation(text, ignoreCase) { @@ -619,9 +618,13 @@ function peg$parse(input, options) { peg$maxFailExpected.push(expected); } - function peg$buildException(message, expected, found, location) { + function peg$buildSimpleError(message, location) { + return new peg$SyntaxError(message, null, null, location); + } + + function peg$buildStructuredError(expected, found, location) { return new peg$SyntaxError( - message !== null ? message : peg$SyntaxError.buildMessage(expected, found), + peg$SyntaxError.buildMessage(expected, found), expected, found, location @@ -5021,8 +5024,7 @@ function peg$parse(input, options) { peg$fail(peg$endExpectation()); } - throw peg$buildException( - null, + throw peg$buildStructuredError( peg$maxFailExpected, peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null, peg$maxFailPos < input.length