From 3bb125dd8c65644fb44164a01596ae89094f4804 Mon Sep 17 00:00:00 2001 From: Tangent Wantwight Date: Fri, 4 Aug 2023 02:17:16 -0400 Subject: [PATCH] Regex pattern returns custom expects() if set --- peg.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/peg.js b/peg.js index 89e5341..44226a9 100644 --- a/peg.js +++ b/peg.js @@ -69,13 +69,15 @@ Peg.Use = function (getPattern) { * @return {Peg.Pattern} */ Peg.Regex = function (regex) { - return Peg.WrapPattern(function (source, index) { + /** @type {Peg.Pattern} */ + const pattern = Peg.WrapPattern(function (source, index) { regex.lastIndex = index; const matches = regex.exec(source); return matches ? [true, matches, regex.lastIndex] - : [false, index, regex.source]; + : [false, index, pattern.expectLabel]; }).expects(regex.source); + return pattern; }; /**