Add End to Peg

This commit is contained in:
Tangent Wantwight 2023-07-29 01:45:34 -04:00
parent 347af33bf1
commit a3cdc53330

14
peg.js
View file

@ -84,7 +84,7 @@ var Peg = {
* If the given pattern does not consume input, the matching will be terminated to prevent an eternal loop.
*
* Note that if the minimum run is zero, this pattern will always succeed, but might not consume any input.
* @template {unknown[]} T
* @template {unknown} T
* @param {number} min
* @param {Peg.Pattern<T>} pattern
* @return {Peg.Pattern<T[]>}
@ -106,4 +106,16 @@ var Peg = {
}
};
},
/**
* Pattern that matches the end of input
* @type {Peg.Pattern<true>}
*/
End(source, index) {
if (source.length == index) {
return [true, index];
} else {
return null;
}
},
};