From a3cdc53330b5f0b367fdce43b5299c8f89d36717 Mon Sep 17 00:00:00 2001 From: Tangent Wantwight Date: Sat, 29 Jul 2023 01:45:34 -0400 Subject: [PATCH] Add End to Peg --- peg.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/peg.js b/peg.js index 55d8a8a..c8545f3 100644 --- a/peg.js +++ b/peg.js @@ -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} pattern * @return {Peg.Pattern} @@ -106,4 +106,16 @@ var Peg = { } }; }, + + /** + * Pattern that matches the end of input + * @type {Peg.Pattern} + */ + End(source, index) { + if (source.length == index) { + return [true, index]; + } else { + return null; + } + }, };