diff --git a/lib/runtime.js b/lib/runtime.js index e45394e..22d28d9 100644 --- a/lib/runtime.js +++ b/lib/runtime.js @@ -124,6 +124,7 @@ PEG.Parser.prototype = { case 1: return failuresExpected[0]; default: + failuresExpected.sort(); return failuresExpected.slice(0, failuresExpected.length - 1).join(", ") + " or " + failuresExpected[failuresExpected.length - 1]; diff --git a/test/compiler-test.js b/test/compiler-test.js index 0d05ddc..3e7e61e 100644 --- a/test/compiler-test.js +++ b/test/compiler-test.js @@ -463,6 +463,13 @@ test("error messages", function() { "", 'Expected "a" but end of input found.' ); + + var unsortedErrorsParser = PEG.buildParser('start: "b" / "a"'); + doesNotParseWithMessage( + unsortedErrorsParser, + "", + 'Expected "a" or "b" but end of input found.' + ); }); test("error positions", function() {