mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Update regex literal lexing and emission
Update the lexing implementation to defer to the regex library, which will pass back the pointer from to resume lexing, and update the emission to call the new `Regex(_regexString:version:)` overload, that will accept the regex string with delimiters. Because this uses the library's lexing implementation, the delimiters are now `'/.../'` and `'|...|'` instead of plain `'...'`.
This commit is contained in:
@@ -23,21 +23,29 @@ extension String {
|
||||
RegexBasicTests.test("Basic") {
|
||||
let input = "aabccd"
|
||||
|
||||
let match1 = input.expectMatch('aabcc.')
|
||||
let match1 = input.expectMatch('/aabcc./')
|
||||
expectEqual("aabccd", input[match1.range])
|
||||
expectEqual(.empty, match1.captures)
|
||||
|
||||
let match2 = input.expectMatch('a*b.+.')
|
||||
let match2 = input.expectMatch('/a*b.+./')
|
||||
expectEqual("aabccd", input[match2.range])
|
||||
expectEqual(.empty, match2.captures)
|
||||
}
|
||||
|
||||
RegexBasicTests.test("Modern") {
|
||||
let input = "aabccd"
|
||||
|
||||
let match1 = input.expectMatch('|a a bc c /*hello*/ .|')
|
||||
expectEqual("aabccd", input[match1.range])
|
||||
expectEqual(.empty, match1.captures)
|
||||
}
|
||||
|
||||
RegexBasicTests.test("Captures") {
|
||||
let input = """
|
||||
A6F0..A6F1 ; Extend # Mn [2] BAMUM COMBINING MARK KOQNDON..BAMUM \
|
||||
COMBINING MARK TUKWENTIS
|
||||
"""
|
||||
let regex = '([0-9A-F]+)(?:\.\.([0-9A-F]+))?\s+;\s+(\w+).*'
|
||||
let regex = '/([0-9A-F]+)(?:\.\.([0-9A-F]+))?\s+;\s+(\w+).*/'
|
||||
let match1 = input.expectMatch(regex)
|
||||
expectEqual(input[...], input[match1.range])
|
||||
expectEqual(
|
||||
|
||||
Reference in New Issue
Block a user