diff --git a/peg.js b/peg.js index 44226a9..95a8231 100644 --- a/peg.js +++ b/peg.js @@ -90,15 +90,17 @@ Peg.Choose = function (...patterns) { const expected = patterns.map((pattern) => pattern.expectLabel).join(" | "); return Peg.WrapPattern(function (source, index) { let furthest = index; + let furthestExpected = expected; for (const pattern of patterns) { const match = pattern(source, index); if (match[0]) { return match; } else if (match[1] > furthest) { furthest = match[1]; + furthestExpected = match[2]; } } - return [false, furthest, expected]; + return [false, furthest, furthestExpected]; }).expects(expected); };