lookahead-quantifier-match-groups.js (1618B)
1 // Copyright (C) 2023 Kevin Gibbons. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-runtime-semantics-repeatmatcher-abstract-operation 6 description: 0-length matches update the captures list if and only if they are not followed by a quantifier which allows them to match 0 times. 7 info: | 8 RepeatMatcher 9 1. If max = 0, return c(x). 10 2. Let d be a new MatcherContinuation with parameters (y) that captures m, min, max, greedy, x, c, parenIndex, and parenCount and performs the following steps when called: 11 [...] 12 b. If min = 0 and y's endIndex = x's endIndex, return failure. 13 c. If min = 0, let min2 be 0; otherwise let min2 be min - 1. 14 d. If max = +∞, let max2 be +∞; otherwise let max2 be max - 1. 15 e. Return RepeatMatcher(m, min2, max2, greedy, y, c, parenIndex, parenCount). 16 3. Let cap be a copy of x's captures List. 17 4. For each integer k in the inclusive interval from parenIndex + 1 to parenIndex + parenCount, set cap[k] to undefined. 18 [...] 19 7. Let xr be the MatchState (Input, e, cap). 20 [...] 21 10. Let z be m(xr, d). 22 11. If z is not failure, return z. 23 12. Return c(x). 24 includes: [compareArray.js] 25 ---*/ 26 27 assert.compareArray("abc".match(/(?:(?=(abc)))a/), ["a", "abc"], "unquantified"); 28 assert.compareArray("abc".match(/(?:(?=(abc)))?a/), ["a", undefined], "? quantifier"); 29 assert.compareArray("abc".match(/(?:(?=(abc))){1,1}a/), ["a", "abc"], "{1,1} quantifier"); 30 assert.compareArray("abc".match(/(?:(?=(abc))){0,1}a/), ["a", undefined], "{0,1} quantifier"); 31 32 reportCompare(0, 0);