From d1fc16c3736b8e0f6709731d667df5babece2b53 Mon Sep 17 00:00:00 2001 From: David Majda Date: Sat, 22 May 2010 17:43:32 +0200 Subject: [PATCH] Fix bug causing incorrect error messages The bug could cause the list of expected strings in an error message to contain strings that shouldn't be there. Closes #2. --- lib/compiler.js | 4 ++++ lib/metagrammar.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lib/compiler.js b/lib/compiler.js index 752d647..1dcdcc9 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -915,6 +915,10 @@ PEG.Compiler = { " },", " ", " _matchFailed: function(failure) {", + " if (this._pos < this._rightmostMatchFailuresPos) {", + " return;", + " }", + " ", " if (this._pos > this._rightmostMatchFailuresPos) {", " this._rightmostMatchFailuresPos = this._pos;", " this._rightmostMatchFailuresExpected = [];", diff --git a/lib/metagrammar.js b/lib/metagrammar.js index ea0b4d6..f1566c3 100644 --- a/lib/metagrammar.js +++ b/lib/metagrammar.js @@ -36,6 +36,10 @@ PEG.grammarParser = (function(){ }, _matchFailed: function(failure) { + if (this._pos < this._rightmostMatchFailuresPos) { + return; + } + if (this._pos > this._rightmostMatchFailuresPos) { this._rightmostMatchFailuresPos = this._pos; this._rightmostMatchFailuresExpected = [];