From 1159660cf78face643daaabbdceb8a33f2a1b7dd Mon Sep 17 00:00:00 2001 From: Futago-za Ryuu Date: Sun, 29 Sep 2019 05:22:52 +0100 Subject: [PATCH] Forward location to buildMessage (closes #608) --- CHANGELOG.md | 1 + packages/pegjs/lib/compiler/passes/generate-js.js | 4 ++-- packages/pegjs/lib/parser.js | 6 +++--- packages/pegjs/typings/generated-parser.d.ts | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fe8034..60b081a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,6 +66,7 @@ * On the CLI added the use of `input` and `output` from the _config file_ instead of passing them as arguments * Updated examples * Upgraded support for Unicode (from _v8_ to _v11_) +* Forward location to `SyntaxError.buildMessage` ([#608](https://github.com/pegjs/pegjs/pull/608)) ### Bugfixes diff --git a/packages/pegjs/lib/compiler/passes/generate-js.js b/packages/pegjs/lib/compiler/passes/generate-js.js index c69c225..14b9dfc 100644 --- a/packages/pegjs/lib/compiler/passes/generate-js.js +++ b/packages/pegjs/lib/compiler/passes/generate-js.js @@ -1047,7 +1047,7 @@ function generateJS( ast, session, options ) { "", "peg$subclass(peg$SyntaxError, Error);", "", - "peg$SyntaxError.buildMessage = function(expected, found) {", + "peg$SyntaxError.buildMessage = function(expected, found, location) {", " var DESCRIBE_EXPECTATION_FNS = {", " literal: function(expectation) {", " return \"\\\"\" + literalEscape(expectation.text) + \"\\\"\";", @@ -1547,7 +1547,7 @@ function generateJS( ast, session, options ) { "", " function peg$buildStructuredError(expected, found, location) {", " return new peg$SyntaxError(", - " peg$SyntaxError.buildMessage(expected, found),", + " peg$SyntaxError.buildMessage(expected, found, location),", " expected,", " found,", " location", diff --git a/packages/pegjs/lib/parser.js b/packages/pegjs/lib/parser.js index 111d468..ccd43a2 100644 --- a/packages/pegjs/lib/parser.js +++ b/packages/pegjs/lib/parser.js @@ -1,4 +1,4 @@ -// Generated by PEG.js v0.11.0-dev, https://pegjs.org/ +// Generated by PEG.js v0.11.0, https://pegjs.org/ /* eslint-disable */ @@ -28,7 +28,7 @@ function peg$SyntaxError(message, expected, found, location) { peg$subclass(peg$SyntaxError, Error); -peg$SyntaxError.buildMessage = function(expected, found) { +peg$SyntaxError.buildMessage = function(expected, found, location) { var DESCRIBE_EXPECTATION_FNS = { literal: function(expectation) { return "\"" + literalEscape(expectation.text) + "\""; @@ -557,7 +557,7 @@ function peg$parse(input, options) { function peg$buildStructuredError(expected, found, location) { return new peg$SyntaxError( - peg$SyntaxError.buildMessage(expected, found), + peg$SyntaxError.buildMessage(expected, found, location), expected, found, location diff --git a/packages/pegjs/typings/generated-parser.d.ts b/packages/pegjs/typings/generated-parser.d.ts index 581aec3..1e6e306 100644 --- a/packages/pegjs/typings/generated-parser.d.ts +++ b/packages/pegjs/typings/generated-parser.d.ts @@ -56,7 +56,7 @@ declare namespace generatedparser { new( message: string, expected: T, found: string | null, location: SourceLocation ): ISyntaxError; readonly prototype: ISyntaxError; - buildMessage( expected: T, found?: string ): string; + buildMessage( expected: T, found?: string, location?: SourceLocation ): string; }