Skip to content

[5.7] Update to match Unicode proposal #551

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
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
6 changes: 1 addition & 5 deletions Sources/RegexBuilder/CharacterClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,10 @@ extension RegexComponent where Self == CharacterClass {
.init(DSLTree.CustomCharacterClass(members: [.atom(.any)]))
}

public static var anyGrapheme: CharacterClass {
public static var anyGraphemeCluster: CharacterClass {
.init(unconverted: .anyGrapheme)
}

public static var anyUnicodeScalar: CharacterClass {
.init(unconverted: .anyUnicodeScalar)
}

public static var whitespace: CharacterClass {
.init(unconverted: .whitespace)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/_RegexParser/Regex/Parse/Sema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,14 @@ extension RegexValidator {
_ esc: AST.Atom.EscapedBuiltin, at loc: SourceLocation
) {
switch esc {
case .resetStartOfMatch, .singleDataUnit,
case .resetStartOfMatch, .singleDataUnit, .trueAnychar,
// '\N' needs to be emitted using 'emitAny'.
.notNewline:
error(.unsupported("'\\\(esc.character)'"), at: loc)

// Character classes.
case .decimalDigit, .notDecimalDigit, .whitespace, .notWhitespace,
.wordCharacter, .notWordCharacter, .graphemeCluster, .trueAnychar,
.wordCharacter, .notWordCharacter, .graphemeCluster,
.horizontalWhitespace, .notHorizontalWhitespace,
.verticalTab, .notVerticalTab:
break
Expand Down
6 changes: 3 additions & 3 deletions Tests/RegexBuilderTests/AlgorithmsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class AlgorithmsResultBuilderTests: XCTestCase {
func testStartsAndContains() throws {
let fam = "👨‍👩‍👧‍👦👨‍👨‍👧‍👧 we Ⓡ family"
let startsWithGrapheme = fam.starts {
OneOrMore(.anyGrapheme)
OneOrMore(.anyGraphemeCluster)
OneOrMore(.whitespace)
}
XCTAssertEqual(startsWithGrapheme, true)
Expand All @@ -272,7 +272,7 @@ class AlgorithmsResultBuilderTests: XCTestCase {

let content = {
Regex {
OneOrMore(.anyGrapheme)
OneOrMore(.anyGraphemeCluster)
OneOrMore(.whitespace)
}
}
Expand Down Expand Up @@ -321,7 +321,7 @@ class AlgorithmsResultBuilderTests: XCTestCase {

var mutable = "👨‍👩‍👧‍👦 we Ⓡ family"
mutable.trimPrefix {
.anyGrapheme
.anyGraphemeCluster
ZeroOrMore(.whitespace)
}
XCTAssertEqual(mutable, "we Ⓡ family")
Expand Down
2 changes: 1 addition & 1 deletion Tests/RegexTests/MatchTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1786,7 +1786,7 @@ extension RegexTests {
match: eDecomposed,
xfail: true
)
firstMatchTest(#"\O"#, input: eComposed, match: eComposed)
firstMatchTest(#"\O"#, input: eComposed, match: eComposed, xfail: true)
firstMatchTest(#"\O"#, input: eDecomposed, match: nil,
xfail: true)

Expand Down
2 changes: 2 additions & 0 deletions Tests/RegexTests/ParseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,8 @@ extension RegexTests {
parseTest(#"\M-\C--"#, atom(.keyboardMetaControl("-")), unsupported: true)
parseTest(#"\M-a"#, atom(.keyboardMeta("a")), unsupported: true)

parseTest(#"\O"#, escaped(.trueAnychar), unsupported: true)

// MARK: Comments

parseTest(
Expand Down