Skip to content

[5.7] Remove (?X) and (?u) for now #510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Sources/_RegexParser/Regex/Parse/Sema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,13 @@ extension RegexValidator {
case .byteSemantics:
throw error(.unsupported("byte semantic mode"), at: loc)

case .unicodeScalarSemantics:
throw error(.unsupported("unicode scalar semantic mode"), at: loc)

case .graphemeClusterSemantics:
throw error(.unsupported("grapheme semantic mode"), at: loc)

case .caseInsensitive, .possessiveByDefault, .reluctantByDefault,
.unicodeScalarSemantics, .graphemeClusterSemantics,
.singleLine, .multiline, .namedCapturesOnly, .extended, .extraExtended,
.asciiOnlyDigit, .asciiOnlyWord, .asciiOnlySpace, .asciiOnlyPOSIXProps:
break
Expand Down
10 changes: 7 additions & 3 deletions Tests/RegexTests/CompileTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,13 @@ extension RegexTests {
"(?im)(?s).",
matchingOptions(adding: [.caseInsensitive, .multiline, .singleLine]))
try expectInitialOptions(".", matchingOptions())
try expectInitialOptions(
"(?im)(?s).(?u)",
matchingOptions(adding: [.caseInsensitive, .multiline, .singleLine]))

// FIXME: Figure out (?X) and (?u) semantics
try XCTExpectFailure("Figure out (?X) and (?u) semantics") {
try expectInitialOptions(
"(?im)(?s).(?u)",
matchingOptions(adding: [.caseInsensitive, .multiline, .singleLine]))
}

try expectInitialOptions(
"(?i:.)",
Expand Down
33 changes: 25 additions & 8 deletions Tests/RegexTests/MatchTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1020,10 +1020,12 @@ extension RegexTests {
#"\u{65}\y"#, // Grapheme boundary assertion
("Cafe\u{301}", nil),
("Sol Cafe", "e"))

// FIXME: Figure out (?X) and (?u) semantics
firstMatchTests(
#"(?u)\u{65}\Y"#, // Grapheme non-boundary assertion
("Cafe\u{301}", "e"),
("Sol Cafe", nil))
("Sol Cafe", nil), xfail: true)
}

func testMatchGroups() {
Expand Down Expand Up @@ -1586,7 +1588,8 @@ extension RegexTests {
// a single Unicode scalar value, leaving any other grapheme scalar
// components to be matched.

firstMatchTest(#"(?u:.)"#, input: eDecomposed, match: "e")
// FIXME: Figure out (?X) and (?u) semantics
firstMatchTest(#"(?u:.)"#, input: eDecomposed, match: "e", xfail: true)

matchTest(
#".\u{301}"#,
Expand All @@ -1597,18 +1600,30 @@ extension RegexTests {
(eComposed, false),
(eDecomposed, false))

// FIXME: Figure out (?X) and (?u) semantics
// FIXME: \O is unsupported
firstMatchTest(#"(?u)\O\u{301}"#, input: eDecomposed, match: eDecomposed)
firstMatchTest(#"(?u)e\O"#, input: eDecomposed, match: eDecomposed)
firstMatchTest(
#"(?u)\O\u{301}"#,
input: eDecomposed,
match: eDecomposed,
xfail: true
)
firstMatchTest(
#"(?u)e\O"#,
input: eDecomposed,
match: eDecomposed,
xfail: true
)
firstMatchTest(#"\O"#, input: eComposed, match: eComposed)
firstMatchTest(#"\O"#, input: eDecomposed, match: nil,
xfail: true)

// FIXME: Figure out (?X) and (?u) semantics
matchTest(
#"(?u).\u{301}"#,
(eComposed, false),
(eDecomposed, true))
firstMatchTest(#"(?u).$"#, input: eComposed, match: eComposed)
(eDecomposed, true), xfail: true)
firstMatchTest(#"(?u).$"#, input: eComposed, match: eComposed, xfail: true)

// Option permutations for 'u' and 's'
matchTest(
Expand All @@ -1621,14 +1636,16 @@ extension RegexTests {
("e\u{301}ab", false),
("e\u{301}abc", true),
("e\u{301}\nab", true))

// FIXME: Figure out (?X) and (?u) semantics
matchTest(
#"(?u)...."#,
("e\u{301}ab", true),
("e\u{301}\na", false))
("e\u{301}\na", false), xfail: true)
matchTest(
#"(?us)...."#,
("e\u{301}ab", true),
("e\u{301}\na", true))
("e\u{301}\na", true), xfail: true)
}

// TODO: Add test for implied grapheme cluster requirement at group boundaries
Expand Down
9 changes: 6 additions & 3 deletions Tests/RegexTests/ParseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1074,9 +1074,11 @@ extension RegexTests {
.singleLine, .reluctantByDefault, .extraExtended, .extended,
.unicodeWordBoundaries, .asciiOnlyDigit, .asciiOnlyPOSIXProps,
.asciiOnlySpace, .asciiOnlyWord, .textSegmentGraphemeMode,
.textSegmentWordMode, .graphemeClusterSemantics, .unicodeScalarSemantics,
.textSegmentWordMode,
.graphemeClusterSemantics, .unicodeScalarSemantics,
.byteSemantics
]

parseTest("(?iJmnsUxxxwDPSWy{g}y{w}Xub-iJmnsUxxxwDPSW)", changeMatchingOptions(
matchingOptions(adding: allOptions, removing: allOptions.dropLast(5))
), throwsError: .unsupported)
Expand Down Expand Up @@ -2787,8 +2789,9 @@ extension RegexTests {
diagnosticTest("(?-y{g})", .cannotRemoveTextSegmentOptions)
diagnosticTest("(?-y{w})", .cannotRemoveTextSegmentOptions)

diagnosticTest("(?-X)", .cannotRemoveSemanticsOptions)
diagnosticTest("(?-u)", .cannotRemoveSemanticsOptions)
// FIXME: Reenable once we figure out (?X) and (?u) semantics
//diagnosticTest("(?-X)", .cannotRemoveSemanticsOptions)
//diagnosticTest("(?-u)", .cannotRemoveSemanticsOptions)
diagnosticTest("(?-b)", .cannotRemoveSemanticsOptions)

diagnosticTest("(?a)", .unknownGroupKind("?a"))
Expand Down
9 changes: 7 additions & 2 deletions Tests/RegexTests/UTS18Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fileprivate func expectFirstMatch<Output: Equatable>(
}

#if os(Linux)
func XCTExpectFailure(_ message: String? = nil, body: () -> Void) {}
func XCTExpectFailure(_ message: String? = nil, body: () throws -> Void) rethrows {}
#endif

// MARK: - Basic Unicode Support: Level 1
Expand Down Expand Up @@ -466,7 +466,12 @@ extension UTS18Tests {

// Matching semantic level
XCTAssertFalse("👩‍👩‍👧‍👦".contains(regex(#".\N{ZERO WIDTH JOINER}"#)))
XCTAssertTrue("👩‍👩‍👧‍👦".contains(regex(#"(?u).\N{ZERO WIDTH JOINER}"#)))

// FIXME: Figure out (?X) and (?u) semantics
XCTExpectFailure("Figure out (?X) and (?u) semantics") {
XCTFail(#"(?u).\N{ZERO WIDTH JOINER}"#)
//XCTAssertTrue("👩‍👩‍👧‍👦".contains(regex(#"(?u).\N{ZERO WIDTH JOINER}"#)))
}
}

func testIndividuallyNamedCharacters_XFail() {
Expand Down