diff --git a/peg.js b/peg.js index cb5f5b1..f1136c9 100644 --- a/peg.js +++ b/peg.js @@ -79,7 +79,7 @@ Peg.Regex = function (regex) { regex.lastIndex = index; const matches = regex.exec(source); return matches - ? [[matches, regex.lastIndex], regex.lastIndex, pattern.expectLabel] + ? [[matches, regex.lastIndex], -1, pattern.expectLabel] : [null, index, pattern.expectLabel]; }).expects(regex.source); return pattern; @@ -105,6 +105,8 @@ Peg.Choose = function (...patterns) { } else if (furthest > furthestFound) { furthestFound = furthest; furthestExpected = expected; + } else if (furthest == furthestFound) { + furthestExpected = furthestExpected + " | " + expected; } } return [null, furthestFound, furthestExpected]; @@ -128,9 +130,11 @@ Peg.Sequence = function (...patterns) { let furthestExpected = genericExpected; for (const pattern of patterns) { const [value, furthest, expected] = pattern(source, index); - if (furthest >= furthestFound) { + if (furthest > furthestFound) { furthestFound = furthest; furthestExpected = expected; + } else if (furthest == furthestFound) { + furthestExpected = furthestExpected + " | " + expected; } if (value == null) { return [null, furthestFound, furthestExpected];