diff --git a/spec.html b/spec.html index 09aa5ac7dc0..00ad0368a70 100644 --- a/spec.html +++ b/spec.html @@ -29851,11 +29851,23 @@

Runtime Semantics: GetSubstitution ( _matched_, _str_, _position_, _captures 1. Assert: _position_ ≤ _stringLength_. 1. Assert: _captures_ is a possibly empty List of Strings. 1. Assert: Type(_replacement_) is String. + 1. Let _replacementLength_ be the number of code units in _replacement_. 1. Let _tailPos_ be _position_ + _matchLength_. 1. Let _m_ be the number of elements in _captures_. 1. If _namedCaptures_ is not *undefined*, then 1. Set _namedCaptures_ to ? ToObject(_namedCaptures_). - 1. Let _result_ be the String value derived from _replacement_ by copying code unit elements from _replacement_ to _result_ while performing replacements as specified in . These `$` replacements are done left-to-right, and, once such a replacement is performed, the new replacement text is not subject to further replacements. + 1. Let _result_ be the empty String. + 1. Let _k_ be 0. + 1. Repeat, while _k_ < _replacementLength_ + 1. Let _replaceablePattern_ be the longest sequence of consecutive code units from _replacement_ beginning with the code unit at index _k_ such that _replaceablePattern_ matches the “Code units” column of a row in . + 1. If _replaceablePattern_ is not empty, + 1. Let _patternReplacement_ be the result of the “Replacement text” column of the corresponding row. + 1. Set _result_ to the string-concatenation of _result_ and _patternReplacement_. + 1. Let _patternLength_ be the number of code units in _replaceablePattern_. + 1. Set _k_ to _k_ + _patternLength_. + 1. Else, + 1. Set _result_ to the string-concatenation of _result_ and the code unit from _replacement_ at index _k_. + 1. Set _k_ to _k_ + 1. 1. Return _result_. @@ -29918,68 +29930,68 @@

Runtime Semantics: GetSubstitution ( _matched_, _str_, _position_, _captures - 0x0024, N -
- Where -
- 0x0031 ≤ N ≤ 0x0039 + 0x0024, 0x0030 - `$n` where -
- `n` is one of `1 2 3 4 5 6 7 8 9` and `$n` is not followed by a decimal digit + `$0` - The _n_th element of _captures_, where _n_ is a single digit in the range 1 to 9. If _n_ ≤ _m_ and the _n_th element of _captures_ is *undefined*, use the empty String instead. If _n_ > _m_, no replacement is done. + `$0` - 0x0024, N, N -
- Where + 0x0024, N
- 0x0030 ≤ N ≤ 0x0039 + where 0x0031 ≤ N ≤ 0x0039 - `$nn` where -
- `n` is one of `0 1 2 3 4 5 6 7 8 9` + `$`_n_ + where _n_ is an expansion of |NonZeroDigit| - The _nn_th element of _captures_, where _nn_ is a two-digit decimal number in the range 01 to 99. If _nn_ ≤ _m_ and the _nn_th element of _captures_ is *undefined*, use the empty String instead. If _nn_ is 00 or _nn_ > _m_, no replacement is done. + If the MV of _n_ > _m_, the replacement is the matched code units (equivalent to no replacement). +
+ Otherwise, if the element in _captures_ at index equal to the MV of _n_ minus 1 is *undefined*, the replacement is the empty String. +
+ Otherwise, the replacement is the element in _captures_ at index equal to the MV of _n_ minus 1. - 0x0024, 0x003C + 0x0024, N1, N2 +
+ where 0x0030 ≤ N1 ≤ 0x0039 and 0x0030 ≤ N2 ≤ 0x0039 - `$<` + `$`_nn_ + where _nn_ is a two-element expansion of |DecimalDigits| - - 1. If _namedCaptures_ is *undefined*, the replacement text is the String `"$<"`. - 1. Else, - 1. Scan until the next `>` U+003E (GREATER-THAN SIGN). - 1. If none is found, the replacement text is the String `"$<"`. - 1. Else, - 1. Let _groupName_ be the enclosed substring. - 1. Let _capture_ be ? Get(_namedCaptures_, _groupName_). - 1. If _capture_ is *undefined*, replace the text through `>` with the empty string. - 1. Otherwise, replace the text through `>` with ? ToString(_capture_). - + If _nn_ is `00` or the MV of _nn_ > _m_, the replacement is the string-concatenation of the replacement for the first two matched code units (i.e., a replacement specified by one of the two preceding rows) and the remaining matched code units (i.e., a single |DecimalDigit|). +
+ Otherwise, if the element in _captures_ at index equal to the MV of _nn_ minus 1 is *undefined*, the replacement is the empty String. +
+ Otherwise, the replacement is the element in _captures_ at index equal to the MV of _nn_ minus 1. - 0x0024 + 0x0024, 0x003C, any sequence of code units not containing 0x003E, 0x003E - `$` in any context that does not match any of the above. + `$<` _groupName_ `>` + where _groupName_ is a sequence of code units that does not contain a `>` U+003E (GREATER-THAN SIGN) - `$` + + 1. Set _groupName_ to the String value whose code units are the code units of _groupName_. + 1. If _namedCaptures_ is *undefined*, then + 1. The replacement is the string-concatenation of the String `"$<"`, ! GetSubstitution(_matched_, _str_, _position_, _captures_, _namedCaptures_, _groupName_), and the String `">"`. + 1. Else, + 1. Let _capture_ be ? Get(_namedCaptures_, _groupName_). + 1. If _capture_ is *undefined*, the replacement is the empty String. Otherwise, the replacement is ? ToString(_capture_). +