Skip to content

Commit 99e5e51

Browse files
authored
Merge pull request #578 from hamishknight/internalize-character-model
2 parents 7752047 + 7d5e86d commit 99e5e51

File tree

3 files changed

+50
-295
lines changed

3 files changed

+50
-295
lines changed

Sources/RegexBuilder/CharacterClass.swift

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@ public struct CharacterClass {
2020
self.ccc = ccc
2121
}
2222

23-
init(unconverted model: _CharacterClassModel) {
24-
guard let ccc = model.makeDSLTreeCharacterClass() else {
25-
fatalError("Unsupported character class")
26-
}
27-
self.ccc = ccc
23+
init(unconverted atom: DSLTree._AST.Atom) {
24+
self.ccc = .init(members: [.atom(.unconverted(atom))])
2825
}
2926
}
3027

@@ -49,15 +46,15 @@ extension RegexComponent where Self == CharacterClass {
4946
}
5047

5148
public static var anyGraphemeCluster: CharacterClass {
52-
.init(unconverted: .anyGrapheme)
49+
.init(unconverted: ._anyGrapheme)
5350
}
5451

5552
public static var whitespace: CharacterClass {
56-
.init(unconverted: .whitespace)
53+
.init(unconverted: ._whitespace)
5754
}
5855

5956
public static var digit: CharacterClass {
60-
.init(unconverted: .digit)
57+
.init(unconverted: ._digit)
6158
}
6259

6360
public static var hexDigit: CharacterClass {
@@ -69,19 +66,19 @@ extension RegexComponent where Self == CharacterClass {
6966
}
7067

7168
public static var horizontalWhitespace: CharacterClass {
72-
.init(unconverted: .horizontalWhitespace)
69+
.init(unconverted: ._horizontalWhitespace)
7370
}
7471

7572
public static var newlineSequence: CharacterClass {
76-
.init(unconverted: .newlineSequence)
73+
.init(unconverted: ._newlineSequence)
7774
}
7875

7976
public static var verticalWhitespace: CharacterClass {
80-
.init(unconverted: .verticalWhitespace)
77+
.init(unconverted: ._verticalWhitespace)
8178
}
8279

8380
public static var word: CharacterClass {
84-
.init(unconverted: .word)
81+
.init(unconverted: ._word)
8582
}
8683
}
8784

Sources/_StringProcessing/Regex/DSLTree.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,32 @@ extension DSLTree {
740740
@_spi(RegexBuilder)
741741
public struct Atom {
742742
internal var ast: AST.Atom
743+
744+
// FIXME: The below APIs should be removed once the DSL tree has been
745+
// migrated to use proper DSL atoms for them.
746+
747+
public static var _anyGrapheme: Self {
748+
.init(ast: .init(.escaped(.graphemeCluster), .fake))
749+
}
750+
public static var _whitespace: Self {
751+
.init(ast: .init(.escaped(.whitespace), .fake))
752+
}
753+
public static var _digit: Self {
754+
.init(ast: .init(.escaped(.decimalDigit), .fake))
755+
}
756+
public static var _horizontalWhitespace: Self {
757+
.init(ast: .init(.escaped(.horizontalWhitespace), .fake))
758+
}
759+
public static var _newlineSequence: Self {
760+
// FIXME: newline sequence is not same as \n
761+
.init(ast: .init(.escaped(.newline), .fake))
762+
}
763+
public static var _verticalWhitespace: Self {
764+
.init(ast: .init(.escaped(.verticalTab), .fake))
765+
}
766+
public static var _word: Self {
767+
.init(ast: .init(.escaped(.wordCharacter), .fake))
768+
}
743769
}
744770
}
745771
}

0 commit comments

Comments
 (0)