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.
This commit is contained in:
David Majda 2010-05-22 17:43:32 +02:00
parent 11c67b0507
commit d1fc16c373
2 changed files with 8 additions and 0 deletions

View file

@ -915,6 +915,10 @@ PEG.Compiler = {
" },", " },",
" ", " ",
" _matchFailed: function(failure) {", " _matchFailed: function(failure) {",
" if (this._pos < this._rightmostMatchFailuresPos) {",
" return;",
" }",
" ",
" if (this._pos > this._rightmostMatchFailuresPos) {", " if (this._pos > this._rightmostMatchFailuresPos) {",
" this._rightmostMatchFailuresPos = this._pos;", " this._rightmostMatchFailuresPos = this._pos;",
" this._rightmostMatchFailuresExpected = [];", " this._rightmostMatchFailuresExpected = [];",

View file

@ -36,6 +36,10 @@ PEG.grammarParser = (function(){
}, },
_matchFailed: function(failure) { _matchFailed: function(failure) {
if (this._pos < this._rightmostMatchFailuresPos) {
return;
}
if (this._pos > this._rightmostMatchFailuresPos) { if (this._pos > this._rightmostMatchFailuresPos) {
this._rightmostMatchFailuresPos = this._pos; this._rightmostMatchFailuresPos = this._pos;
this._rightmostMatchFailuresExpected = []; this._rightmostMatchFailuresExpected = [];