Attempt to merge applicable multiple expecteds at the same spot.
Avoid counting a successful capture as an error at the current locaiton.
This commit is contained in:
parent
0c90b45d3a
commit
1c04d8dece
1 changed files with 6 additions and 2 deletions
8
peg.js
8
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];
|
||||
|
|
Loading…
Reference in a new issue