Skip to content

Commit 9624436

Browse files
committed
Remove (?X) and (?u) for now
Parse, but diagnose in Sema
1 parent 32afc43 commit 9624436

File tree

5 files changed

+50
-16
lines changed

5 files changed

+50
-16
lines changed

Sources/_RegexParser/Regex/Parse/Sema.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,13 @@ extension RegexValidator {
106106
case .byteSemantics:
107107
throw error(.unsupported("byte semantic mode"), at: loc)
108108

109+
case .unicodeScalarSemantics:
110+
throw error(.unsupported("unicode scalar semantic mode"), at: loc)
111+
112+
case .graphemeClusterSemantics:
113+
throw error(.unsupported("grapheme semantic mode"), at: loc)
114+
109115
case .caseInsensitive, .possessiveByDefault, .reluctantByDefault,
110-
.unicodeScalarSemantics, .graphemeClusterSemantics,
111116
.singleLine, .multiline, .namedCapturesOnly, .extended, .extraExtended,
112117
.asciiOnlyDigit, .asciiOnlyWord, .asciiOnlySpace, .asciiOnlyPOSIXProps:
113118
break

Tests/RegexTests/CompileTests.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,13 @@ extension RegexTests {
124124
"(?im)(?s).",
125125
matchingOptions(adding: [.caseInsensitive, .multiline, .singleLine]))
126126
try expectInitialOptions(".", matchingOptions())
127-
try expectInitialOptions(
128-
"(?im)(?s).(?u)",
129-
matchingOptions(adding: [.caseInsensitive, .multiline, .singleLine]))
127+
128+
// FIXME: Figure out (?X) and (?u) semantics
129+
try XCTExpectFailure("Figure out (?X) and (?u) semantics") {
130+
try expectInitialOptions(
131+
"(?im)(?s).(?u)",
132+
matchingOptions(adding: [.caseInsensitive, .multiline, .singleLine]))
133+
}
130134

131135
try expectInitialOptions(
132136
"(?i:.)",

Tests/RegexTests/MatchTests.swift

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,10 +1020,12 @@ extension RegexTests {
10201020
#"\u{65}\y"#, // Grapheme boundary assertion
10211021
("Cafe\u{301}", nil),
10221022
("Sol Cafe", "e"))
1023+
1024+
// FIXME: Figure out (?X) and (?u) semantics
10231025
firstMatchTests(
10241026
#"(?u)\u{65}\Y"#, // Grapheme non-boundary assertion
10251027
("Cafe\u{301}", "e"),
1026-
("Sol Cafe", nil))
1028+
("Sol Cafe", nil), xfail: true)
10271029
}
10281030

10291031
func testMatchGroups() {
@@ -1594,7 +1596,8 @@ extension RegexTests {
15941596
// a single Unicode scalar value, leaving any other grapheme scalar
15951597
// components to be matched.
15961598

1597-
firstMatchTest(#"(?u:.)"#, input: eDecomposed, match: "e")
1599+
// FIXME: Figure out (?X) and (?u) semantics
1600+
firstMatchTest(#"(?u:.)"#, input: eDecomposed, match: "e", xfail: true)
15981601

15991602
matchTest(
16001603
#".\u{301}"#,
@@ -1605,18 +1608,30 @@ extension RegexTests {
16051608
(eComposed, false),
16061609
(eDecomposed, false))
16071610

1611+
// FIXME: Figure out (?X) and (?u) semantics
16081612
// FIXME: \O is unsupported
1609-
firstMatchTest(#"(?u)\O\u{301}"#, input: eDecomposed, match: eDecomposed)
1610-
firstMatchTest(#"(?u)e\O"#, input: eDecomposed, match: eDecomposed)
1613+
firstMatchTest(
1614+
#"(?u)\O\u{301}"#,
1615+
input: eDecomposed,
1616+
match: eDecomposed,
1617+
xfail: true
1618+
)
1619+
firstMatchTest(
1620+
#"(?u)e\O"#,
1621+
input: eDecomposed,
1622+
match: eDecomposed,
1623+
xfail: true
1624+
)
16111625
firstMatchTest(#"\O"#, input: eComposed, match: eComposed)
16121626
firstMatchTest(#"\O"#, input: eDecomposed, match: nil,
16131627
xfail: true)
16141628

1629+
// FIXME: Figure out (?X) and (?u) semantics
16151630
matchTest(
16161631
#"(?u).\u{301}"#,
16171632
(eComposed, false),
1618-
(eDecomposed, true))
1619-
firstMatchTest(#"(?u).$"#, input: eComposed, match: eComposed)
1633+
(eDecomposed, true), xfail: true)
1634+
firstMatchTest(#"(?u).$"#, input: eComposed, match: eComposed, xfail: true)
16201635

16211636
// Option permutations for 'u' and 's'
16221637
matchTest(
@@ -1629,14 +1644,16 @@ extension RegexTests {
16291644
("e\u{301}ab", false),
16301645
("e\u{301}abc", true),
16311646
("e\u{301}\nab", true))
1647+
1648+
// FIXME: Figure out (?X) and (?u) semantics
16321649
matchTest(
16331650
#"(?u)...."#,
16341651
("e\u{301}ab", true),
1635-
("e\u{301}\na", false))
1652+
("e\u{301}\na", false), xfail: true)
16361653
matchTest(
16371654
#"(?us)...."#,
16381655
("e\u{301}ab", true),
1639-
("e\u{301}\na", true))
1656+
("e\u{301}\na", true), xfail: true)
16401657
}
16411658

16421659
// TODO: Add test for implied grapheme cluster requirement at group boundaries

Tests/RegexTests/ParseTests.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,9 +1060,11 @@ extension RegexTests {
10601060
.singleLine, .reluctantByDefault, .extraExtended, .extended,
10611061
.unicodeWordBoundaries, .asciiOnlyDigit, .asciiOnlyPOSIXProps,
10621062
.asciiOnlySpace, .asciiOnlyWord, .textSegmentGraphemeMode,
1063-
.textSegmentWordMode, .graphemeClusterSemantics, .unicodeScalarSemantics,
1063+
.textSegmentWordMode,
1064+
.graphemeClusterSemantics, .unicodeScalarSemantics,
10641065
.byteSemantics
10651066
]
1067+
10661068
parseTest("(?iJmnsUxxxwDPSWy{g}y{w}Xub-iJmnsUxxxwDPSW)", changeMatchingOptions(
10671069
matchingOptions(adding: allOptions, removing: allOptions.dropLast(5))
10681070
), throwsError: .unsupported)
@@ -2734,8 +2736,9 @@ extension RegexTests {
27342736
diagnosticTest("(?-y{g})", .cannotRemoveTextSegmentOptions)
27352737
diagnosticTest("(?-y{w})", .cannotRemoveTextSegmentOptions)
27362738

2737-
diagnosticTest("(?-X)", .cannotRemoveSemanticsOptions)
2738-
diagnosticTest("(?-u)", .cannotRemoveSemanticsOptions)
2739+
// FIXME: Reenable once we figure out (?X) and (?u) semantics
2740+
//diagnosticTest("(?-X)", .cannotRemoveSemanticsOptions)
2741+
//diagnosticTest("(?-u)", .cannotRemoveSemanticsOptions)
27392742
diagnosticTest("(?-b)", .cannotRemoveSemanticsOptions)
27402743

27412744
diagnosticTest("(?a)", .unknownGroupKind("?a"))

Tests/RegexTests/UTS18Tests.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,12 @@ extension UTS18Tests {
466466

467467
// Matching semantic level
468468
XCTAssertFalse("👩‍👩‍👧‍👦".contains(regex(#".\N{ZERO WIDTH JOINER}"#)))
469-
XCTAssertTrue("👩‍👩‍👧‍👦".contains(regex(#"(?u).\N{ZERO WIDTH JOINER}"#)))
469+
470+
// FIXME: Figure out (?X) and (?u) semantics
471+
XCTExpectFailure("Figure out (?X) and (?u) semantics") {
472+
XCTFail(#"(?u).\N{ZERO WIDTH JOINER}"#)
473+
//XCTAssertTrue("👩‍👩‍👧‍👦".contains(regex(#"(?u).\N{ZERO WIDTH JOINER}"#)))
474+
}
470475
}
471476

472477
func testIndividuallyNamedCharacters_XFail() {

0 commit comments

Comments
 (0)