Remove Hint hack

This commit is contained in:
Tangent Wantwight 2023-08-04 19:25:57 -04:00
parent 797d3cc6b2
commit 0c90b45d3a
2 changed files with 1 additions and 24 deletions

View file

@ -6,7 +6,7 @@
*/
var Notcl = (() => {
const { AtLeast, Choose, End, Regex, Sequence, Use, Hint } = Peg;
const { AtLeast, Choose, End, Regex, Sequence, Use } = Peg;
const InterCommandWhitespace = Regex(/\s+/y).expects("whitespace");

23
peg.js
View file

@ -198,26 +198,3 @@ Peg.End = () => {
}).expects("<eof>");
return end;
};
/**
* Creates a pattern that never succeeds, but reports how far its wrapped pattern could match before failing.
*
* This is a hack, meant to improve error messages after an AtLeast(). Maybe this can be removed by patterns returning both success and failure
*
* Never consumes input, and fails with zero length if the pattern succeeds.
* @param {Peg.Pattern<unknown>} pattern
* @return {Peg.Pattern<never>}
*/
Peg.Hint = function (pattern) {
return /** @type {Peg.Pattern<never>} */ (
Peg.WrapPattern(function (source, index) {
const [value, furthest, expected] = pattern(source, index);
if (value) {
console.log("oops match", value, furthest, expected);
return [null, index, pattern.expectLabel];
} else {
return [value, furthest, expected];
}
})
).expects(pattern.expectLabel);
};