From b2bc16eb22ee2c8d1cbb9fd28e76904580a741fa Mon Sep 17 00:00:00 2001 From: Kevin Gibbons Date: Sat, 2 Apr 2022 20:32:25 -0700 Subject: [PATCH] Normative: allow duplicagte named capture groups --- spec.html | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/spec.html b/spec.html index c13941d522..3fcfe6d20f 100644 --- a/spec.html +++ b/spec.html @@ -34644,7 +34644,7 @@

Static Semantics: Early Errors

It is a Syntax Error if _NcapturingParens_ ≥ 232 - 1.
  • - It is a Syntax Error if |Pattern| contains multiple |GroupSpecifier|s whose enclosed |RegExpIdentifierName|s have the same CapturingGroupName. + It is an Syntax Error if |Pattern| contains a pair of |GroupSpecifier|s (_x_, _y_) whose enclosed RegExpIdentifierNames have the same CapturingGroupName and such that CanBothParticipate(_x_, _y_) is *true*.
  • QuantifierPrefix :: `{` DecimalDigits `,` DecimalDigits `}` @@ -34656,7 +34656,7 @@

    Static Semantics: Early Errors

    AtomEscape :: `k` GroupName AtomEscape :: DecimalEscape @@ -34724,6 +34724,22 @@

    Static Semantics: Early Errors

    + +

    + Static Semantics: CanBothParticipate ( + _x_: a Parse Node, + _y_: a Parse Node, + ): a Boolean +

    +
    +
    + + 1. Assert: _x_ and _y_ have the same enclosing |Pattern|. + 1. If the enclosing |Pattern| contains a |Disjunction :: Alternative `|` Disjuction| Parse Node such that either _x_ is contained within the |Alternative| and _y_ is contained within the derived |Disjuction|, or _x_ is contained within the derived |Disjuction| and _y_ is contained within the |Alternative|, return *false*. + 1. Return *true*. + +
    +

    Static Semantics: CapturingGroupNumber ( ): a positive integer

    @@ -35566,7 +35582,7 @@

    AtomEscape :: `k` GroupName - 1. Search the enclosing |Pattern| for an instance of a |GroupSpecifier| containing a |RegExpIdentifierName| which has a CapturingGroupName equal to the CapturingGroupName of the |RegExpIdentifierName| contained in |GroupName|. + 1. Search the enclosing |Pattern| for an instance of a |GroupSpecifier| containing a |RegExpIdentifierName| which has a CapturingGroupName equal to the CapturingGroupName of the |RegExpIdentifierName| contained in |GroupName|, and such that CanBothParticipate(|AtomEscape|, |GroupSpecifier|) is *true*. 1. Assert: A unique such |GroupSpecifier| is found. 1. Let _parenIndex_ be the number of left-capturing parentheses in the entire regular expression that occur to the left of the located |GroupSpecifier|. This is the total number of Atom :: `(` GroupSpecifier Disjunction `)` Parse Nodes prior to or enclosing the located |GroupSpecifier|, including its immediately enclosing |Atom|. 1. Return BackreferenceMatcher(_parenIndex_, _direction_). @@ -36210,7 +36226,13 @@

    1. Perform ! CreateDataPropertyOrThrow(_A_, ! ToString(𝔽(_i_)), _capturedValue_). 1. If the _i_th capture of _R_ was defined with a |GroupName|, then 1. Let _s_ be the CapturingGroupName of the corresponding |RegExpIdentifierName|. - 1. Perform ! CreateDataPropertyOrThrow(_groups_, _s_, _capturedValue_). + 1. Let _isMatchedElsewhere_ be *false*. + 1. For each integer _j_ such that _j_ ≠ _i_, _j_ ≥ 1, and _j_ ≤ _n_, do + 1. If the _j_th capture of _R_ was defined with a |GroupName|, then + 1. Let _sj_ be the CapturingGroupName of the corresponding |RegExpIdentifierName|. + 1. If _sj_ equals _s_ and the _j_th capture of _R_ is not *undefined*, set _isMatchedElsewhere_ to *true*. + 1. If _isMatchedElsewhere_ is *false, then + 1. Perform ! CreateDataPropertyOrThrow(_groups_, _s_, _capturedValue_). 1. Append _s_ to _groupNames_. 1. Else, 1. Append *undefined* to _groupNames_.