| 1 |
// |reftest| shell-option(--enable-regexp-modifiers) skip-if(release_or_beta||!xulRuntime.shell) -- regexp-modifiers is not released yet, requires shell-options |
| 2 |
// Copyright 2023 Ron Buckton. All rights reserved. |
| 3 |
// This code is governed by the BSD license found in the LICENSE file. |
| 4 |
|
| 5 |
/*--- |
| 6 |
author: Ron Buckton |
| 7 |
description: > |
| 8 |
dotAll (`s`) modifier can be added via `(?s:)` or `(?s-:)`. |
| 9 |
info: | |
| 10 |
Runtime Semantics: CompileAtom |
| 11 |
The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. |
| 12 |
|
| 13 |
Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` |
| 14 |
1. Let addModifiers be the source text matched by RegularExpressionFlags. |
| 15 |
2. Let removeModifiers be the empty String. |
| 16 |
3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). |
| 17 |
4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. |
| 18 |
|
| 19 |
UpdateModifiers ( modifiers, add, remove ) |
| 20 |
The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: |
| 21 |
|
| 22 |
1. Let dotAll be modifiers.[[DotAll]]. |
| 23 |
2. Let ignoreCase be modifiers.[[IgnoreCase]]. |
| 24 |
3. Let multiline be modifiers.[[Multiline]]. |
| 25 |
4. If add contains "s", set dotAll to true. |
| 26 |
5. If add contains "i", set ignoreCase to true. |
| 27 |
6. If add contains "m", set multiline to true. |
| 28 |
7. If remove contains "s", set dotAll to false. |
| 29 |
8. If remove contains "i", set ignoreCase to false. |
| 30 |
9. If remove contains "m", set multiline to false. |
| 31 |
10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. |
| 32 |
|
| 33 |
esid: sec-compileatom |
| 34 |
features: [regexp-modifiers] |
| 35 |
---*/ |
| 36 |
|
| 37 |
var re1 = /(?s:^.$)/; |
| 38 |
assert(re1.test("a"), "Pattern character '.' should match non-line terminators in modified group"); |
| 39 |
assert(re1.test("3"), "Pattern character '.' should match non-line terminators in modified group"); |
| 40 |
assert(re1.test("π"), "Pattern character '.' should match non-line terminators in modified group"); |
| 41 |
assert(re1.test("\u2027"), "Pattern character '.' should match non-line terminators in modified group"); |
| 42 |
assert(re1.test("\u0085"), "Pattern character '.' should match non-line terminators in modified group"); |
| 43 |
assert(re1.test("\v"), "Pattern character '.' should match mon-line terminators in modified group"); |
| 44 |
assert(re1.test("\f"), "Pattern character '.' should match mon-line terminators in modified group"); |
| 45 |
assert(re1.test("\u180E"), "Pattern character '.' should match non-line terminators in modified group"); |
| 46 |
assert(!re1.test("\u{10300}"), "Supplementary plane not matched by a single ."); |
| 47 |
assert(re1.test("\n"), "Pattern character '.' should match line terminators in modified group"); |
| 48 |
assert(re1.test("\r"), "Pattern character '.' should match line terminators in modified group"); |
| 49 |
assert(re1.test("\u2028"), "Pattern character '.' should match line terminators in modified group"); |
| 50 |
assert(re1.test("\u2029"), "Pattern character '.' should match line terminators in modified group"); |
| 51 |
assert(re1.test("\uD800"), "Pattern character '.' should match non-line terminators in modified group"); |
| 52 |
assert(re1.test("\uDFFF"), "Pattern character '.' should match non-line terminators in modified group"); |
| 53 |
|
| 54 |
var re2 = new RegExp("(?s:^.$)"); |
| 55 |
assert(re2.test("a"), "Pattern character '.' should match non-line terminators in modified group"); |
| 56 |
assert(re2.test("3"), "Pattern character '.' should match non-line terminators in modified group"); |
| 57 |
assert(re2.test("π"), "Pattern character '.' should match non-line terminators in modified group"); |
| 58 |
assert(re2.test("\u2027"), "Pattern character '.' should match non-line terminators in modified group"); |
| 59 |
assert(re2.test("\u0085"), "Pattern character '.' should match non-line terminators in modified group"); |
| 60 |
assert(re2.test("\v"), "Pattern character '.' should match mon-line terminators in modified group"); |
| 61 |
assert(re2.test("\f"), "Pattern character '.' should match mon-line terminators in modified group"); |
| 62 |
assert(re2.test("\u180E"), "Pattern character '.' should match non-line terminators in modified group"); |
| 63 |
assert(!re2.test("\u{10300}"), "Supplementary plane not matched by a single ."); |
| 64 |
assert(re2.test("\n"), "Pattern character '.' should match line terminators in modified group"); |
| 65 |
assert(re2.test("\r"), "Pattern character '.' should match line terminators in modified group"); |
| 66 |
assert(re2.test("\u2028"), "Pattern character '.' should match line terminators in modified group"); |
| 67 |
assert(re2.test("\u2029"), "Pattern character '.' should match line terminators in modified group"); |
| 68 |
assert(re2.test("\uD800"), "Pattern character '.' should match non-line terminators in modified group"); |
| 69 |
assert(re2.test("\uDFFF"), "Pattern character '.' should match non-line terminators in modified group"); |
| 70 |
|
| 71 |
var re3 = /(?s-:^.$)/; |
| 72 |
assert(re3.test("a"), "Pattern character '.' should match non-line terminators in modified group"); |
| 73 |
assert(re3.test("3"), "Pattern character '.' should match non-line terminators in modified group"); |
| 74 |
assert(re3.test("π"), "Pattern character '.' should match non-line terminators in modified group"); |
| 75 |
assert(re3.test("\u2027"), "Pattern character '.' should match non-line terminators in modified group"); |
| 76 |
assert(re3.test("\u0085"), "Pattern character '.' should match non-line terminators in modified group"); |
| 77 |
assert(re3.test("\v"), "Pattern character '.' should match mon-line terminators in modified group"); |
| 78 |
assert(re3.test("\f"), "Pattern character '.' should match mon-line terminators in modified group"); |
| 79 |
assert(re3.test("\u180E"), "Pattern character '.' should match non-line terminators in modified group"); |
| 80 |
assert(!re3.test("\u{10300}"), "Supplementary plane not matched by a single ."); |
| 81 |
assert(re3.test("\n"), "Pattern character '.' should match line terminators in modified group"); |
| 82 |
assert(re3.test("\r"), "Pattern character '.' should match line terminators in modified group"); |
| 83 |
assert(re3.test("\u2028"), "Pattern character '.' should match line terminators in modified group"); |
| 84 |
assert(re3.test("\u2029"), "Pattern character '.' should match line terminators in modified group"); |
| 85 |
assert(re3.test("\uD800"), "Pattern character '.' should match non-line terminators in modified group"); |
| 86 |
assert(re3.test("\uDFFF"), "Pattern character '.' should match non-line terminators in modified group"); |
| 87 |
|
| 88 |
var re4 = new RegExp("(?s-:^.$)"); |
| 89 |
assert(re4.test("a"), "Pattern character '.' should match non-line terminators in modified group"); |
| 90 |
assert(re4.test("3"), "Pattern character '.' should match non-line terminators in modified group"); |
| 91 |
assert(re4.test("π"), "Pattern character '.' should match non-line terminators in modified group"); |
| 92 |
assert(re4.test("\u2027"), "Pattern character '.' should match non-line terminators in modified group"); |
| 93 |
assert(re4.test("\u0085"), "Pattern character '.' should match non-line terminators in modified group"); |
| 94 |
assert(re4.test("\v"), "Pattern character '.' should match mon-line terminators in modified group"); |
| 95 |
assert(re4.test("\f"), "Pattern character '.' should match mon-line terminators in modified group"); |
| 96 |
assert(re4.test("\u180E"), "Pattern character '.' should match non-line terminators in modified group"); |
| 97 |
assert(!re4.test("\u{10300}"), "Supplementary plane not matched by a single ."); |
| 98 |
assert(re4.test("\n"), "Pattern character '.' should match line terminators in modified group"); |
| 99 |
assert(re4.test("\r"), "Pattern character '.' should match line terminators in modified group"); |
| 100 |
assert(re4.test("\u2028"), "Pattern character '.' should match line terminators in modified group"); |
| 101 |
assert(re4.test("\u2029"), "Pattern character '.' should match line terminators in modified group"); |
| 102 |
assert(re4.test("\uD800"), "Pattern character '.' should match non-line terminators in modified group"); |
| 103 |
assert(re4.test("\uDFFF"), "Pattern character '.' should match non-line terminators in modified group"); |
| 104 |
|
| 105 |
var re5 = /a.(?s:b.b).c/; |
| 106 |
assert(re5.test("a,b,b,c"), "Pattern character '.' should match non-line terminators in modified group"); |
| 107 |
assert(re5.test("a,b\nb,c"), "Pattern character '.' should match line terminators in modified group"); |
| 108 |
assert(!re5.test("a\nb\nb,c"), "Pattern character '.' should not match line terminators outside modified group"); |
| 109 |
assert(!re5.test("a,b\nb\nc"), "Pattern character '.' should not match line terminators outside modified group"); |
| 110 |
assert(!re5.test("a\nb\nb\nc"), "Pattern character '.' should not match line terminators outside modified group"); |
| 111 |
|
| 112 |
var re6 = new RegExp("a.(?s:b.b).c"); |
| 113 |
assert(re6.test("a,b,b,c"), "Pattern character '.' should match non-line terminators in modified group"); |
| 114 |
assert(re6.test("a,b\nb,c"), "Pattern character '.' should match line terminators in modified group"); |
| 115 |
assert(!re6.test("a\nb\nb,c"), "Pattern character '.' should not match line terminators outside modified group"); |
| 116 |
assert(!re6.test("a,b\nb\nc"), "Pattern character '.' should not match line terminators outside modified group"); |
| 117 |
assert(!re6.test("a\nb\nb\nc"), "Pattern character '.' should not match line terminators outside modified group"); |
| 118 |
|
| 119 |
reportCompare(0, 0); |