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:
Hamish Knight
2021-12-17 18:05:31 +00:00
parent 300cbaba31
commit 128f5d4bc6
18 changed files with 173 additions and 110 deletions

View File

@@ -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(