Skip to content

Commit

Permalink
Normative: allow duplicagte named capture groups
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkot committed Apr 3, 2022
1 parent 07c7b5c commit 35b63c0
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -34644,7 +34644,7 @@ <h1>Static Semantics: Early Errors</h1>
It is a Syntax Error if _NcapturingParens_ &ge; 2<sup>32</sup> - 1.
</li>
<li>
It is a Syntax Error if |Pattern| contains multiple |GroupSpecifier|s whose enclosed |RegExpIdentifierName|s have the same CapturingGroupName.
It is a Syntax Error if |Pattern| contains two distinct |GroupSpecifier|s _x_ and _y_ whose enclosed |RegExpIdentifierName|s have the same CapturingGroupName and such that CanBothParticipate(_x_, _y_) is *true*.
</li>
</ul>
<emu-grammar>QuantifierPrefix :: `{` DecimalDigits `,` DecimalDigits `}`</emu-grammar>
Expand All @@ -34656,7 +34656,7 @@ <h1>Static Semantics: Early Errors</h1>
<emu-grammar>AtomEscape :: `k` GroupName</emu-grammar>
<ul>
<li>
It is a Syntax Error if the enclosing |Pattern| does not contain a |GroupSpecifier| with an enclosed |RegExpIdentifierName| whose CapturingGroupName equals the CapturingGroupName of the |RegExpIdentifierName| of this production's |GroupName|.
It is a Syntax Error if the enclosing |Pattern| does not contain a |GroupSpecifier| with an enclosed |RegExpIdentifierName| whose CapturingGroupName equals the CapturingGroupName of the |RegExpIdentifierName| of this production's |GroupName|, and such that CanBothParticipate(|AtomEscape|, |GroupSpecifier|) is *true*.
</li>
</ul>
<emu-grammar>AtomEscape :: DecimalEscape</emu-grammar>
Expand Down Expand Up @@ -34724,6 +34724,22 @@ <h1>Static Semantics: Early Errors</h1>
</ul>
</emu-clause>

<emu-clause id="sec-patterns-static-semantics-can-both-participate" type="abstract operation">
<h1>
Static Semantics: CanBothParticipate (
_x_: a Parse Node,
_y_: a Parse Node,
): a Boolean
</h1>
<dl class="header">
</dl>
<emu-alg>
1. Assert: _x_ and _y_ have the same enclosing |Pattern|.
1. If the enclosing |Pattern| contains a <emu-grammar>Disjunction :: Alternative `|` Disjunction</emu-grammar> Parse Node such that either _x_ is contained within the |Alternative| and _y_ is contained within the derived |Disjunction|, or _x_ is contained within the derived |Disjunction| and _y_ is contained within the |Alternative|, return *false*.
1. Return *true*.
</emu-alg>
</emu-clause>

<emu-clause id="sec-patterns-static-semantics-capturing-group-number" type="sdo">
<h1>Static Semantics: CapturingGroupNumber ( ): a positive integer</h1>
<dl class="header">
Expand Down Expand Up @@ -35566,7 +35582,7 @@ <h1>
</emu-alg>
<emu-grammar>AtomEscape :: `k` GroupName</emu-grammar>
<emu-alg>
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 <emu-grammar>Atom :: `(` GroupSpecifier Disjunction `)`</emu-grammar> Parse Nodes prior to or enclosing the located |GroupSpecifier|, including its immediately enclosing |Atom|.
1. Return BackreferenceMatcher(_parenIndex_, _direction_).
Expand Down Expand Up @@ -36210,7 +36226,13 @@ <h1>
1. Perform ! CreateDataPropertyOrThrow(_A_, ! ToString(𝔽(_i_)), _capturedValue_).
1. If the _i_<sup>th</sup> 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_ &ne; _i_, _j_ &ge; 1, and _j_ &le; _n_, do
1. If the _j_<sup>th</sup> 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_<sup>th</sup> 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_.
Expand Down

0 comments on commit 35b63c0

Please sign in to comment.