Add tests for nullable quantifiers in RegExps (#4185)

* Add tests for nullable quantifiers in RegExps

The JavaScript semantics for a quantifier matching the empty
string are different from other regex languages.
This adds a test that documents this JavaScript-specific
behavior.

This is part of my work at the SYSTEMF lab at EPFL.

* Update nullable-quantifier.js
This commit is contained in:
Aurèle 2024-08-05 22:02:50 +02:00 committed by GitHub
parent feb400c685
commit ea37a19a4a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,21 @@
// Copyright (C) 2024 Aurèle Barrière. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-runtime-semantics-repeatmatcher-abstract-operation
description: JavaScript nullable quantifiers have special semantics, optional iterations are not allowed to match the empty string. Point 2.b below shows that after each optional (min=0) iteration of a quantifier, if the iteration matched the empty string (y.[[EndIndex]] = x.[[EndIndex]]), then the iteration is discarded. In particular, for (a?b??)* on "ab", it is possible to do two iterations of the star, one matching "a" and the other matching "b".
info: |
RepeatMatcher ( m, min, max, greedy, x, c, parenIndex, parenCount )
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:
b. If min = 0 and y.[[EndIndex]] = x.[[EndIndex]], return failure.
author: Aurèle Barrière
---*/
let input = "ab";
let regex = /(a?b??)*/;
let match = regex.exec(input);
let expected = "ab";
assert.sameValue(match[0], expected, "The regex is expected to match the whole string");