File tree Expand file tree Collapse file tree 4 files changed +43
-11
lines changed
Sources/_StringProcessing Expand file tree Collapse file tree 4 files changed +43
-11
lines changed Original file line number Diff line number Diff line change @@ -99,12 +99,16 @@ extension Compiler.ByteCodeGen {
99
99
}
100
100
101
101
case . textSegment:
102
- // This we should be able to do!
103
- throw Unsupported ( #"\y (text segment)"# )
102
+ builder. buildAssert { ( input, pos, _) in
103
+ // FIXME: Grapheme or word based on options
104
+ input. isOnGraphemeClusterBoundary ( pos)
105
+ }
104
106
105
107
case . notTextSegment:
106
- // This we should be able to do!
107
- throw Unsupported ( #"\Y (not text segment)"# )
108
+ builder. buildAssert { ( input, pos, _) in
109
+ // FIXME: Grapheme or word based on options
110
+ !input. isOnGraphemeClusterBoundary ( pos)
111
+ }
108
112
109
113
case . startOfLine:
110
114
builder. buildAssert { ( input, pos, bounds) in
Original file line number Diff line number Diff line change @@ -17,25 +17,31 @@ extension String: RegexProtocol {
17
17
public typealias Match = Substring
18
18
19
19
public var regex : Regex < Match > {
20
- let atoms = self . map { atom ( . char( $0) ) }
21
- return . init( ast: concat ( atoms) )
20
+ . init( node: . quotedLiteral( self ) )
22
21
}
23
22
}
24
23
25
24
extension Substring : RegexProtocol {
26
25
public typealias Match = Substring
27
26
28
27
public var regex : Regex < Match > {
29
- let atoms = self . map { atom ( . char( $0) ) }
30
- return . init( ast: concat ( atoms) )
28
+ . init( node: . quotedLiteral( String ( self ) ) )
31
29
}
32
30
}
33
31
34
32
extension Character : RegexProtocol {
35
33
public typealias Match = Substring
36
34
37
35
public var regex : Regex < Match > {
38
- . init( ast: atom ( . char( self ) ) )
36
+ . init( node: . atom( . char( self ) ) )
37
+ }
38
+ }
39
+
40
+ extension UnicodeScalar : RegexProtocol {
41
+ public typealias Match = Substring
42
+
43
+ public var regex : Regex < Match > {
44
+ . init( node: . atom( . scalar( self ) ) )
39
45
}
40
46
}
41
47
Original file line number Diff line number Diff line change @@ -877,7 +877,8 @@ extension RegexTests {
877
877
#"\d+\b"# ,
878
878
( " 123 " , " 123 " ) ,
879
879
( " 123 " , " 123 " ) ,
880
- ( " 123 456 " , " 123 " ) )
880
+ ( " 123 456 " , " 123 " ) ,
881
+ ( " 123A 456 " , " 456 " ) )
881
882
firstMatchTests (
882
883
#"\d+\b\s\b\d+"# ,
883
884
( " 123 " , nil ) ,
@@ -893,7 +894,18 @@ extension RegexTests {
893
894
// TODO: \G and \K
894
895
895
896
// TODO: Oniguruma \y and \Y
896
-
897
+ firstMatchTests (
898
+ #"\u{65}"# , // Scalar 'e' is present in both:
899
+ ( " Cafe \u{301} " , " e " ) , // composed and
900
+ ( " Sol Cafe " , " e " ) ) // standalone
901
+ firstMatchTests (
902
+ #"\u{65}\y"# , // Grapheme boundary assertion
903
+ ( " Cafe \u{301} " , nil ) ,
904
+ ( " Sol Cafe " , " e " ) )
905
+ firstMatchTests (
906
+ #"\u{65}\Y"# , // Grapheme non-boundary assertion
907
+ ( " Cafe \u{301} " , " e " ) ,
908
+ ( " Sol Cafe " , nil ) )
897
909
}
898
910
899
911
func testMatchGroups( ) {
Original file line number Diff line number Diff line change @@ -280,6 +280,16 @@ class RegexDSLTests: XCTestCase {
280
280
Anchor . endOfLine
281
281
}
282
282
283
+ try _testDSLCaptures (
284
+ ( " Cafe \u{301} " , nil ) ,
285
+ ( " Cafe " , " Cafe " ) ,
286
+ matchType: Substring . self, == )
287
+ {
288
+ oneOrMore ( . word)
289
+ UnicodeScalar ( " e " )
290
+ Anchor . textSegmentBoundary
291
+ }
292
+
283
293
try _testDSLCaptures (
284
294
( " aaaaa1 " , " aaaaa1 " ) ,
285
295
( " aaaaa2 " , nil ) ,
You can’t perform that action at this time.
0 commit comments