-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspec.emu
566 lines (496 loc) · 25.1 KB
/
spec.emu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
<!doctype html>
<meta charset="utf8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/github.min.css">
<link rel="spec" href="es2015" />
<pre class="metadata">
title: Regular Expression Atomic Operators for ECMAScript
stage: 0
contributors: Ron Buckton, Ecma International
</pre>
<emu-biblio href="node_modules/@tc39/ecma262-biblio/biblio.json"></emu-biblio>
<emu-intro id="sec-intro">
<h1>Introduction</h1>
<p>See <a href="https://github.com/rbuckton/proposal-regexp-atomic-operators#readme">the proposal repository</a> for background material and discussion.</p>
</emu-intro>
<emu-clause id="sec-text-processing">
<h1>Text Processing</h1>
<emu-clause id="sec-regexp-regular-expression-objects">
<h1>RegExp (Regular Expression) Objects</h1>
<emu-clause id="sec-patterns">
<h1>Patterns</h1>
<p>The RegExp constructor applies the following grammar to the input pattern String. An error occurs if the grammar cannot interpret the String as an expansion of |Pattern|.</p>
<h2>Syntax</h2>
<emu-grammar type="definition">
Pattern[UnicodeMode, N] ::
Disjunction[?UnicodeMode, ?N]
Disjunction[UnicodeMode, N] ::
Alternative[?UnicodeMode, ?N]
Alternative[?UnicodeMode, ?N] `|` Disjunction[?UnicodeMode, ?N]
Alternative[UnicodeMode, N] ::
[empty]
Alternative[?UnicodeMode, ?N] Term[?UnicodeMode, ?N]
Term[UnicodeMode, N] ::
Assertion[?UnicodeMode, ?N]
Atom[?UnicodeMode, ?N]
Atom[?UnicodeMode, ?N] Quantifier
Assertion[UnicodeMode, N] ::
`^`
`$`
`\` `b`
`\` `B`
`(` `?` `=` Disjunction[?UnicodeMode, ?N] `)`
`(` `?` `!` Disjunction[?UnicodeMode, ?N] `)`
`(` `?` `<=` Disjunction[?UnicodeMode, ?N] `)`
`(` `?` `<!` Disjunction[?UnicodeMode, ?N] `)`
Quantifier ::
QuantifierPrefix
QuantifierPrefix `?`
<ins>QuantifierPrefix `+`</ins>
QuantifierPrefix ::
`*`
`+`
`?`
`{` DecimalDigits[~Sep] `}`
`{` DecimalDigits[~Sep] `,` `}`
`{` DecimalDigits[~Sep] `,` DecimalDigits[~Sep] `}`
Atom[UnicodeMode, N] ::
PatternCharacter
`.`
`\` AtomEscape[?UnicodeMode, ?N]
CharacterClass[?UnicodeMode]
`(` GroupSpecifier[?UnicodeMode]? Disjunction[?UnicodeMode, ?N] `)`
`(` `?` `:` Disjunction[?UnicodeMode, ?N] `)`
<ins>`(` `?` `>` Disjunction[?UnicodeMode, ?N] `)`
SyntaxCharacter :: one of
`^` `$` `\` `.` `*` `+` `?` `(` `)` `[` `]` `{` `}` `|`
PatternCharacter ::
SourceCharacter but not SyntaxCharacter
AtomEscape[UnicodeMode, N] ::
DecimalEscape
CharacterClassEscape[?UnicodeMode]
CharacterEscape[?UnicodeMode]
[+N] `k` GroupName[?UnicodeMode]
CharacterEscape[UnicodeMode] ::
ControlEscape
`c` ControlLetter
`0` [lookahead ∉ DecimalDigit]
HexEscapeSequence
RegExpUnicodeEscapeSequence[?UnicodeMode]
IdentityEscape[?UnicodeMode]
ControlEscape :: one of
`f` `n` `r` `t` `v`
// emu-format ignore
ControlLetter :: one of
`a` `b` `c` `d` `e` `f` `g` `h` `i` `j` `k` `l` `m` `n` `o` `p` `q` `r` `s` `t` `u` `v` `w` `x` `y` `z`
`A` `B` `C` `D` `E` `F` `G` `H` `I` `J` `K` `L` `M` `N` `O` `P` `Q` `R` `S` `T` `U` `V` `W` `X` `Y` `Z`
GroupSpecifier[UnicodeMode] ::
`?` GroupName[?UnicodeMode]
GroupName[UnicodeMode] ::
`<` RegExpIdentifierName[?UnicodeMode] `>`
RegExpIdentifierName[UnicodeMode] ::
RegExpIdentifierStart[?UnicodeMode]
RegExpIdentifierName[?UnicodeMode] RegExpIdentifierPart[?UnicodeMode]
RegExpIdentifierStart[UnicodeMode] ::
IdentifierStartChar
`\` RegExpUnicodeEscapeSequence[+UnicodeMode]
[~UnicodeMode] UnicodeLeadSurrogate UnicodeTrailSurrogate
RegExpIdentifierPart[UnicodeMode] ::
IdentifierPartChar
`\` RegExpUnicodeEscapeSequence[+UnicodeMode]
[~UnicodeMode] UnicodeLeadSurrogate UnicodeTrailSurrogate
RegExpUnicodeEscapeSequence[UnicodeMode] ::
[+UnicodeMode] `u` HexLeadSurrogate `\u` HexTrailSurrogate
[+UnicodeMode] `u` HexLeadSurrogate
[+UnicodeMode] `u` HexTrailSurrogate
[+UnicodeMode] `u` HexNonSurrogate
[~UnicodeMode] `u` Hex4Digits
[+UnicodeMode] `u{` CodePoint `}`
UnicodeLeadSurrogate ::
> any Unicode code point in the inclusive range 0xD800 to 0xDBFF
UnicodeTrailSurrogate ::
> any Unicode code point in the inclusive range 0xDC00 to 0xDFFF
</emu-grammar>
<p>Each `\\u` |HexTrailSurrogate| for which the choice of associated `u` |HexLeadSurrogate| is ambiguous shall be associated with the nearest possible `u` |HexLeadSurrogate| that would otherwise have no corresponding `\\u` |HexTrailSurrogate|.</p>
<emu-grammar type="definition">
HexLeadSurrogate ::
Hex4Digits [> but only if the MV of |Hex4Digits| is in the inclusive range 0xD800 to 0xDBFF]
HexTrailSurrogate ::
Hex4Digits [> but only if the MV of |Hex4Digits| is in the inclusive range 0xDC00 to 0xDFFF]
HexNonSurrogate ::
Hex4Digits [> but only if the MV of |Hex4Digits| is not in the inclusive range 0xD800 to 0xDFFF]
IdentityEscape[UnicodeMode] ::
[+UnicodeMode] SyntaxCharacter
[+UnicodeMode] `/`
[~UnicodeMode] SourceCharacter but not UnicodeIDContinue
DecimalEscape ::
NonZeroDigit DecimalDigits[~Sep]? [lookahead ∉ DecimalDigit]
CharacterClassEscape[UnicodeMode] ::
`d`
`D`
`s`
`S`
`w`
`W`
[+UnicodeMode] `p{` UnicodePropertyValueExpression `}`
[+UnicodeMode] `P{` UnicodePropertyValueExpression `}`
UnicodePropertyValueExpression ::
UnicodePropertyName `=` UnicodePropertyValue
LoneUnicodePropertyNameOrValue
UnicodePropertyName ::
UnicodePropertyNameCharacters
UnicodePropertyNameCharacters ::
UnicodePropertyNameCharacter UnicodePropertyNameCharacters?
UnicodePropertyValue ::
UnicodePropertyValueCharacters
LoneUnicodePropertyNameOrValue ::
UnicodePropertyValueCharacters
UnicodePropertyValueCharacters ::
UnicodePropertyValueCharacter UnicodePropertyValueCharacters?
UnicodePropertyValueCharacter ::
UnicodePropertyNameCharacter
DecimalDigit
UnicodePropertyNameCharacter ::
ControlLetter
`_`
CharacterClass[UnicodeMode] ::
`[` [lookahead != `^`] ClassRanges[?UnicodeMode] `]`
`[` `^` ClassRanges[?UnicodeMode] `]`
ClassRanges[UnicodeMode] ::
[empty]
NonemptyClassRanges[?UnicodeMode]
NonemptyClassRanges[UnicodeMode] ::
ClassAtom[?UnicodeMode]
ClassAtom[?UnicodeMode] NonemptyClassRangesNoDash[?UnicodeMode]
ClassAtom[?UnicodeMode] `-` ClassAtom[?UnicodeMode] ClassRanges[?UnicodeMode]
NonemptyClassRangesNoDash[UnicodeMode] ::
ClassAtom[?UnicodeMode]
ClassAtomNoDash[?UnicodeMode] NonemptyClassRangesNoDash[?UnicodeMode]
ClassAtomNoDash[?UnicodeMode] `-` ClassAtom[?UnicodeMode] ClassRanges[?UnicodeMode]
ClassAtom[UnicodeMode] ::
`-`
ClassAtomNoDash[?UnicodeMode]
ClassAtomNoDash[UnicodeMode] ::
SourceCharacter but not one of `\` or `]` or `-`
`\` ClassEscape[?UnicodeMode]
ClassEscape[UnicodeMode] ::
`b`
[+UnicodeMode] `-`
CharacterClassEscape[?UnicodeMode]
CharacterEscape[?UnicodeMode]
</emu-grammar>
<emu-note>
<p>A number of productions in this section are given alternative definitions in section <emu-xref href="#sec-regular-expressions-patterns"></emu-xref>.</p>
</emu-note>
</emu-clause>
<emu-clause id="sec-pattern-semantics">
<h1>Pattern Semantics</h1>
<emu-clause id="sec-compilesubpattern" type="sdo" oldids="sec-disjunction,sec-alternative,sec-term">
<h1>
Runtime Semantics: CompileSubpattern (
_direction_: ~forward~ or ~backward~,
): a Matcher
</h1>
<dl class="header">
</dl>
<emu-note>
<p>This section is amended in <emu-xref href="#sec-compilesubpattern-annexb"></emu-xref>.</p>
</emu-note>
<!-- Disjunction -->
<emu-grammar>Disjunction :: Alternative `|` Disjunction</emu-grammar>
<emu-alg>
1. Let _m1_ be CompileSubpattern of |Alternative| with argument _direction_.
1. Let _m2_ be CompileSubpattern of |Disjunction| with argument _direction_.
1. Return a new Matcher with parameters (_x_, _c_) that captures _m1_ and _m2_ and performs the following steps when called:
1. Assert: _x_ is a State.
1. Assert: _c_ is a Continuation.
1. Let _r_ be _m1_(_x_, _c_).
1. If _r_ is not ~failure~, return _r_.
1. Return _m2_(_x_, _c_).
</emu-alg>
<emu-note>
<p>The `|` regular expression operator separates two alternatives. The pattern first tries to match the left |Alternative| (followed by the sequel of the regular expression); if it fails, it tries to match the right |Disjunction| (followed by the sequel of the regular expression). If the left |Alternative|, the right |Disjunction|, and the sequel all have choice points, all choices in the sequel are tried before moving on to the next choice in the left |Alternative|. If choices in the left |Alternative| are exhausted, the right |Disjunction| is tried instead of the left |Alternative|. Any capturing parentheses inside a portion of the pattern skipped by `|` produce *undefined* values instead of Strings. Thus, for example,</p>
<pre><code class="javascript">/a|ab/.exec("abc")</code></pre>
<p>returns the result *"a"* and not *"ab"*. Moreover,</p>
<pre><code class="javascript">/((a)|(ab))((c)|(bc))/.exec("abc")</code></pre>
<p>returns the array</p>
<pre><code class="javascript">["abc", "a", "a", undefined, "bc", undefined, "bc"]</code></pre>
<p>and not</p>
<pre><code class="javascript">["abc", "ab", undefined, "ab", "c", "c", undefined]</code></pre>
<p>The order in which the two alternatives are tried is independent of the value of _direction_.</p>
</emu-note>
<!-- Alternative -->
<emu-grammar>Alternative :: [empty]</emu-grammar>
<emu-alg>
1. Return a new Matcher with parameters (_x_, _c_) that captures nothing and performs the following steps when called:
1. Assert: _x_ is a State.
1. Assert: _c_ is a Continuation.
1. Return _c_(_x_).
</emu-alg>
<emu-grammar>Alternative :: Alternative Term</emu-grammar>
<emu-alg>
1. Let _m1_ be CompileSubpattern of |Alternative| with argument _direction_.
1. Let _m2_ be CompileSubpattern of |Term| with argument _direction_.
1. If _direction_ is ~forward~, then
1. Return a new Matcher with parameters (_x_, _c_) that captures _m1_ and _m2_ and performs the following steps when called:
1. Assert: _x_ is a State.
1. Assert: _c_ is a Continuation.
1. Let _d_ be a new Continuation with parameters (_y_) that captures _c_ and _m2_ and performs the following steps when called:
1. Assert: _y_ is a State.
1. Return _m2_(_y_, _c_).
1. Return _m1_(_x_, _d_).
1. Else,
1. Assert: _direction_ is ~backward~.
1. Return a new Matcher with parameters (_x_, _c_) that captures _m1_ and _m2_ and performs the following steps when called:
1. Assert: _x_ is a State.
1. Assert: _c_ is a Continuation.
1. Let _d_ be a new Continuation with parameters (_y_) that captures _c_ and _m1_ and performs the following steps when called:
1. Assert: _y_ is a State.
1. Return _m1_(_y_, _c_).
1. Return _m2_(_x_, _d_).
</emu-alg>
<emu-note>
<p>Consecutive |Term|s try to simultaneously match consecutive portions of _Input_. When _direction_ is ~forward~, if the left |Alternative|, the right |Term|, and the sequel of the regular expression all have choice points, all choices in the sequel are tried before moving on to the next choice in the right |Term|, and all choices in the right |Term| are tried before moving on to the next choice in the left |Alternative|. When _direction_ is ~backward~, the evaluation order of |Alternative| and |Term| are reversed.</p>
</emu-note>
<!-- Term -->
<emu-grammar>Term :: Assertion</emu-grammar>
<emu-alg>
1. Return CompileAssertion of |Assertion|.
</emu-alg>
<emu-note>
<p>The resulting Matcher is independent of _direction_.</p>
</emu-note>
<emu-grammar>Term :: Atom</emu-grammar>
<emu-alg>
1. Return CompileAtom of |Atom| with argument _direction_.
</emu-alg>
<emu-grammar>Term :: Atom Quantifier</emu-grammar>
<emu-alg>
1. Let _m_ be CompileAtom of |Atom| with argument _direction_.
1. Let _q_ be CompileQuantifier of |Quantifier|.
1. Assert: _q_.[[Min]] ≤ _q_.[[Max]].
1. Let _parenIndex_ be CountLeftCapturingParensBefore(|Term|).
1. Let _parenCount_ be CountLeftCapturingParensWithin(|Atom|).
1. Return a new Matcher with parameters (_x_, _c_) that captures _m_, _q_, _parenIndex_, and _parenCount_ and performs the following steps when called:
1. Assert: _x_ is a State.
1. Assert: _c_ is a Continuation.
1. <ins>If _q_.[[Atomic]] is *true*, then</ins>
1. <ins>Let _d_ be a new Continuation with parameters (_y_) that performs the following steps when called:</ins>
1. <ins>Assert: _y_ is a State.</ins>
1. <ins>Return _y_.</ins>
1. <ins>Let _r_ be RepeatMatcher(_m_, _q_.[[Min]], _q_.[[Max]], *true*, _x_, _d_, _parenIndex_, _parenCount_).</ins>
1. <ins>If _r_ is ~failure~, return ~failure~.</ins>
1. <ins>Return _c_(_r_).</ins>
1. Return RepeatMatcher(_m_, _q_.[[Min]], _q_.[[Max]], _q_.[[Greedy]], _x_, _c_, _parenIndex_, _parenCount_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-compilequantifier" type="sdo" oldids="sec-quantifier">
<h1>Runtime Semantics: CompileQuantifier ( ): a Record with fields [[Min]] (a non-negative integer), [[Max]] (a non-negative integer or +∞), [[Greedy]] (a Boolean), and <ins>[[Atomic]]</ins> (a Boolean)</h1>
<dl class="header">
</dl>
<emu-grammar>Quantifier :: QuantifierPrefix</emu-grammar>
<emu-alg>
1. Let _qp_ be CompileQuantifierPrefix of |QuantifierPrefix|.
1. Return the Record { [[Min]]: _qp_.[[Min]], [[Max]]: _qp_.[[Max]], [[Greedy]]: *true*<ins>, [[Atomic]]: *false*</ins> }.
</emu-alg>
<emu-grammar>Quantifier :: QuantifierPrefix `?`</emu-grammar>
<emu-alg>
1. Let _qp_ be CompileQuantifierPrefix of |QuantifierPrefix|.
1. Return the Record { [[Min]]: _qp_.[[Min]], [[Max]]: _qp_.[[Max]], [[Greedy]]: *false*<ins>, [[Atomic]]: *false*</ins> }.
</emu-alg>
<ins class="block">
<emu-grammar>Quantifier :: QuantifierPrefix `+`</emu-grammar>
<emu-alg>
1. Let _qp_ be CompileQuantifierPrefix of |QuantifierPrefix|.
1. Return the Record { [[Min]]: _qp_.[[Min]], [[Max]]: _qp_.[[Max]], [[Greedy]]: *true*, [[Atomic]]: *true* }.
</emu-alg>
</ins>
</emu-clause>
<emu-clause id="sec-compileatom" type="sdo" oldids="sec-atom,sec-atomescape,sec-characterescape,sec-decimalescape">
<h1>
Runtime Semantics: CompileAtom (
_direction_: ~forward~ or ~backward~,
): a Matcher
</h1>
<dl class="header">
</dl>
<emu-note>
<p>This section is amended in <emu-xref href="#sec-compileatom-annexb"></emu-xref>.</p>
</emu-note>
<!-- Atom -->
<emu-grammar>Atom :: PatternCharacter</emu-grammar>
<emu-alg>
1. Let _ch_ be the character matched by |PatternCharacter|.
1. Let _A_ be a one-element CharSet containing the character _ch_.
1. Return CharacterSetMatcher(_A_, *false*, _direction_).
</emu-alg>
<emu-grammar>Atom :: `.`</emu-grammar>
<emu-alg>
1. Let _A_ be the CharSet of all characters.
1. If _DotAll_ is not *true*, then
1. Remove from _A_ all characters corresponding to a code point on the right-hand side of the |LineTerminator| production.
1. Return CharacterSetMatcher(_A_, *false*, _direction_).
</emu-alg>
<emu-grammar>Atom :: CharacterClass</emu-grammar>
<emu-alg>
1. Let _cc_ be CompileCharacterClass of |CharacterClass|.
1. Return CharacterSetMatcher(_cc_.[[CharSet]], _cc_.[[Invert]], _direction_).
</emu-alg>
<emu-grammar>Atom :: `(` GroupSpecifier? Disjunction `)`</emu-grammar>
<emu-alg>
1. Let _m_ be CompileSubpattern of |Disjunction| with argument _direction_.
1. Let _parenIndex_ be CountLeftCapturingParensBefore(|Atom|).
1. Return a new Matcher with parameters (_x_, _c_) that captures _direction_, _m_, and _parenIndex_ and performs the following steps when called:
1. Assert: _x_ is a State.
1. Assert: _c_ is a Continuation.
1. Let _d_ be a new Continuation with parameters (_y_) that captures _x_, _c_, _direction_, and _parenIndex_ and performs the following steps when called:
1. Assert: _y_ is a State.
1. Let _cap_ be a copy of _y_'s _captures_ List.
1. Let _xe_ be _x_'s _endIndex_.
1. Let _ye_ be _y_'s _endIndex_.
1. If _direction_ is ~forward~, then
1. Assert: _xe_ ≤ _ye_.
1. Let _r_ be the Range (_xe_, _ye_).
1. Else,
1. Assert: _direction_ is ~backward~.
1. Assert: _ye_ ≤ _xe_.
1. Let _r_ be the Range (_ye_, _xe_).
1. Set _cap_[_parenIndex_ + 1] to _r_.
1. Let _z_ be the State (_ye_, _cap_).
1. Return _c_(_z_).
1. Return _m_(_x_, _d_).
</emu-alg>
<emu-grammar>Atom :: `(` `?` `:` Disjunction `)`</emu-grammar>
<emu-alg>
1. Return CompileSubpattern of |Disjunction| with argument _direction_.
</emu-alg>
<ins class="block">
<emu-grammar>Atom :: `(` `?` `>` Disjunction `)`</emu-grammar>
<emu-alg>
1. Let _m_ be CompileSubpattern of |Disjunction| with argument _direction_.
1. Return a new Matcher with parameters (_x_, _c_) that captures _m_ and performs the following steps when called:
1. Assert: _x_ is a State.
1. Assert: _c_ is a Continuation.
1. Let _d_ be a new Continuation with parameters (_y_) that performs the following steps when called:
1. Assert: _y_ is a State.
1. Return _y_.
1. Let _r_ be _m_(_x_, _d_).
1. If _r_ is ~failure~, return ~failure~.
1. Return _c_(_r_).
</emu-alg>
</ins>
<!-- AtomEscape -->
<emu-grammar>AtomEscape :: DecimalEscape</emu-grammar>
<emu-alg>
1. Let _n_ be the CapturingGroupNumber of |DecimalEscape|.
1. Assert: _n_ ≤ _NcapturingParens_.
1. Return BackreferenceMatcher(_n_, _direction_).
</emu-alg>
<emu-note>
<p>An escape sequence of the form `\\` followed by a non-zero decimal number _n_ matches the result of the _n_<sup>th</sup> set of capturing parentheses (<emu-xref href="#sec-notation"></emu-xref>). It is an error if the regular expression has fewer than _n_ capturing parentheses. If the regular expression has _n_ or more capturing parentheses but the _n_<sup>th</sup> one is *undefined* because it has not captured anything, then the backreference always succeeds.</p>
</emu-note>
<emu-grammar>AtomEscape :: CharacterEscape</emu-grammar>
<emu-alg>
1. Let _cv_ be the CharacterValue of |CharacterEscape|.
1. Let _ch_ be the character whose character value is _cv_.
1. Let _A_ be a one-element CharSet containing the character _ch_.
1. Return CharacterSetMatcher(_A_, *false*, _direction_).
</emu-alg>
<emu-grammar>AtomEscape :: CharacterClassEscape</emu-grammar>
<emu-alg>
1. Let _A_ be CompileToCharSet of |CharacterClassEscape|.
1. Return CharacterSetMatcher(_A_, *false*, _direction_).
</emu-alg>
<emu-grammar>AtomEscape :: `k` GroupName</emu-grammar>
<emu-alg>
1. Let _matchingGroupSpecifiers_ be GroupSpecifiersThatMatch(|GroupName|).
1. Assert: _matchingGroupSpecifiers_ contains a single |GroupSpecifier|.
1. Let _groupSpecifier_ be the sole element of _matchingGroupSpecifiers_.
1. Let _parenIndex_ be CountLeftCapturingParensBefore(_groupSpecifier_).
1. Return BackreferenceMatcher(_parenIndex_, _direction_).
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
</emu-clause>
<emu-annex id="sec-additional-ecmascript-features-for-web-browsers" namespace="annexB" normative>
<h1>Additional ECMAScript Features for Web Browsers</h1>
<emu-annex id="sec-additional-syntax">
<h1>Additional Syntax</h1>
<emu-annex id="sec-regular-expressions-patterns">
<h1>Regular Expressions Patterns</h1>
<emu-grammar type="definition">
Term[UnicodeMode, N] ::
[+UnicodeMode] Assertion[+UnicodeMode, ?N]
[+UnicodeMode] Atom[+UnicodeMode, ?N] Quantifier
[+UnicodeMode] Atom[+UnicodeMode, ?N]
[~UnicodeMode] QuantifiableAssertion[?N] Quantifier
[~UnicodeMode] Assertion[~UnicodeMode, ?N]
[~UnicodeMode] ExtendedAtom[?N] Quantifier
[~UnicodeMode] ExtendedAtom[?N]
Assertion[UnicodeMode, N] ::
`^`
`$`
`\` `b`
`\` `B`
[+UnicodeMode] `(` `?` `=` Disjunction[+UnicodeMode, ?N] `)`
[+UnicodeMode] `(` `?` `!` Disjunction[+UnicodeMode, ?N] `)`
[~UnicodeMode] QuantifiableAssertion[?N]
`(` `?` `<=` Disjunction[?UnicodeMode, ?N] `)`
`(` `?` `<!` Disjunction[?UnicodeMode, ?N] `)`
QuantifiableAssertion[N] ::
`(` `?` `=` Disjunction[~UnicodeMode, ?N] `)`
`(` `?` `!` Disjunction[~UnicodeMode, ?N] `)`
ExtendedAtom[N] ::
`.`
`\` AtomEscape[~UnicodeMode, ?N]
`\` [lookahead == `c`]
CharacterClass[~UnicodeMode]
`(` GroupSpecifier[~UnicodeMode]? Disjunction[~UnicodeMode, ?N] `)`
`(` `?` `:` Disjunction[~UnicodeMode, ?N] `)`
<ins>`(` `?` `>` Disjunction[~UnicodeMode, ?N] `)`</ins>
InvalidBracedQuantifier
ExtendedPatternCharacter
InvalidBracedQuantifier ::
`{` DecimalDigits[~Sep] `}`
`{` DecimalDigits[~Sep] `,` `}`
`{` DecimalDigits[~Sep] `,` DecimalDigits[~Sep] `}`
ExtendedPatternCharacter ::
SourceCharacter but not one of `^` `$` `\` `.` `*` `+` `?` `(` `)` `[` `|`
AtomEscape[UnicodeMode, N] ::
[+UnicodeMode] DecimalEscape
[~UnicodeMode] DecimalEscape [> but only if the CapturingGroupNumber of |DecimalEscape| is ≤ CountLeftCapturingParensWithin(the |Pattern| containing |DecimalEscape|)]
CharacterClassEscape[?UnicodeMode]
CharacterEscape[?UnicodeMode, ?N]
[+N] `k` GroupName[?UnicodeMode]
CharacterEscape[UnicodeMode, N] ::
ControlEscape
`c` ControlLetter
`0` [lookahead ∉ DecimalDigit]
HexEscapeSequence
RegExpUnicodeEscapeSequence[?UnicodeMode]
[~UnicodeMode] LegacyOctalEscapeSequence
IdentityEscape[?UnicodeMode, ?N]
IdentityEscape[UnicodeMode, N] ::
[+UnicodeMode] SyntaxCharacter
[+UnicodeMode] `/`
[~UnicodeMode] SourceCharacterIdentityEscape[?N]
SourceCharacterIdentityEscape[N] ::
[~N] SourceCharacter but not `c`
[+N] SourceCharacter but not one of `c` or `k`
ClassAtomNoDash[UnicodeMode, N] ::
SourceCharacter but not one of `\` or `]` or `-`
`\` ClassEscape[?UnicodeMode, ?N]
`\` [lookahead == `c`]
ClassEscape[UnicodeMode, N] ::
`b`
[+UnicodeMode] `-`
[~UnicodeMode] `c` ClassControlLetter
CharacterClassEscape[?UnicodeMode]
CharacterEscape[?UnicodeMode, ?N]
ClassControlLetter ::
DecimalDigit
`_`
</emu-grammar>
</emu-annex>
</emu-annex>
</emu-annex>