Skip to content

Commit e790680

Browse files
authored
Merge pull request swiftlang#42161 from hamishknight/update-string-processing
2 parents 6af7324 + 51130bf commit e790680

File tree

5 files changed

+30
-49
lines changed

5 files changed

+30
-49
lines changed

test/IDE/complete_regex.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// RUN: %target-swift-ide-test -enable-experimental-string-processing -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t
55

66
func testLiteral() {
7-
re'foo'.#^RE_LITERAL_MEMBER^#
7+
#/foo/#.#^RE_LITERAL_MEMBER^#
88
// RE_LITERAL_MEMBER: Begin completions
99
// RE_LITERAL_MEMBER-DAG: Keyword[self]/CurrNominal: self[#Regex<Substring>#];
1010
// RE_LITERAL_MEMBER: End completions

test/SourceKit/Sema/sema_regex.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
public func retRegex() -> Regex<Substring> {
2-
re'foo'
2+
#/foo/#
33
}
44

55
// REQUIRES: swift_in_compiler

test/StringProcessing/Parse/regex.swift

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,19 @@
22
// REQUIRES: swift_in_compiler
33

44
_ = #/abc/#
5-
_ = #|abc|#
6-
_ = re'abc'
5+
_ = ##/abc/##
76

87
func foo<T>(_ x: T...) {}
9-
foo(#/abc/#, #|abc|#, re'abc')
8+
foo(#/abc/#, ##/abc/##)
109

11-
let arr = [#/abc/#, #|abc|#, re'abc']
10+
let arr = [#/abc/#, ##/abc/##]
1211

1312
_ = #/\w+/#.self
14-
_ = #|\w+|#.self
15-
_ = re'\w+'.self
13+
_ = ##/\w+/##.self
1614

1715
_ = #/#/\/\#\\/#
18-
_ = #|#|\|\#\\|#
19-
_ = re're\r\e\'\\'
16+
_ = ##/#|\|\#\\/##
2017

2118
_ = (#/[*/#, #/+]/#, #/.]/#)
2219
// expected-error@-1 {{cannot parse regular expression: quantifier '+' must appear after expression}}
2320
// expected-error@-2 {{cannot parse regular expression: expected ']'}}
24-
25-
// Make sure we can skip over `'` characters in the regex body.
26-
_ = re'(?'xA0_-y1'x)'
27-
_ = re'(?('xA0_')\')'
28-
_ = re'\'(?('-20'))'
29-
_ = re'\k'+2-1'\''
30-
_ = re'\g'xA0_''
31-
_ = re'(?C'9,3, pg(')'
Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,38 @@
11
// RUN: %target-typecheck-verify-swift -enable-experimental-string-processing
22
// REQUIRES: swift_in_compiler
33

4-
_ = re'(' // expected-error {{expected ')'}}
4+
_ = #/(/# // expected-error {{expected ')'}}
55

66
// FIXME: Should be 'group openings'
7-
_ = re')' // expected-error {{closing ')' does not balance any groups openings}}
7+
_ = #/)/# // expected-error {{closing ')' does not balance any groups openings}}
88

99
_ = #/\\/''/ // expected-error {{unterminated regex literal}}
10-
_ = #|\| // expected-error {{unterminated regex literal}}
10+
_ = #/\| // expected-error {{unterminated regex literal}}
1111
_ = #// // expected-error {{unterminated regex literal}}
12-
_ = re'x // expected-error {{unterminated regex literal}}
1312

1413
_ = #/xy // expected-error {{unterminated regex literal}}
1514

16-
_ = re'(?' // expected-error {{expected group specifier}}
15+
_ = #/(?/# // expected-error {{expected group specifier}}
16+
_ = #/(?'/# // expected-error {{expected group name}}
17+
_ = #/(?'abc/# // expected-error {{expected '''}}
18+
_ = #/(?'abc /# // expected-error {{expected '''}}
1719

18-
_ = re'(?'' // expected-error {{unterminated regex literal}}
19-
// expected-error@-1 {{expected group name}}
20+
do {
21+
_ = #/(?'a
22+
// expected-error@-1 {{unterminated regex literal}}
23+
// expected-error@-2 {{cannot parse regular expression: expected '''}}
24+
}
2025

21-
_ = re'(?'abc' // expected-error {{unterminated regex literal}}
22-
// expected-error@-1 {{expected ')'}}
26+
_ = #/\(?'abc/#
2327

24-
// TODO: Maybe change "unterminated string literal" to "unterminated single quote"?
25-
_ = re'(?'abc ' // expected-error {{unterminated string literal}}
26-
// expected-error@-1 {{expected group specifier}}
27-
// expected-error@-2 {{consecutive statements on a line must be separated by ';'}}
28-
29-
_ = re'(?'a // expected-error {{expected group specifier}}
30-
// expected-error@-1 {{cannot find 'a' in scope}}
31-
// expected-error@-2 {{consecutive statements on a line must be separated by ';'}}
32-
33-
_ = re'\(?'abc' // expected-error {{unterminated string literal}}
34-
// expected-error@-1 {{consecutive statements on a line must be separated by ';'}}
35-
36-
_ = re'\
37-
'
28+
_ = #/\
29+
/#
3830
// expected-error@-2 {{unterminated regex literal}}
3931
// expected-error@-3 {{expected escape sequence}}
40-
// expected-error@-3 {{unterminated string literal}}
32+
// expected-error@-3 {{expected expression}}
4133

4234
func foo<T>(_ x: T, _ y: T) {}
43-
foo(re'(?', re'abc') // expected-error {{expected group specifier}}
44-
foo(re'(?C', re'abc') // expected-error {{expected ')'}}
35+
foo(#/(?/#, #/abc/#) // expected-error {{expected group specifier}}
36+
foo(#/(?C/#, #/abc/#) // expected-error {{expected ')'}}
4537

46-
foo(re'(?'', re'abc') // expected-error {{expected group name}}
47-
// expected-error@-1 {{unterminated string literal}}
48-
// expected-error@-2 {{expected ',' separator}}
38+
foo(#/(?'/#, #/abc/#) // expected-error {{expected group name}}

test/StringProcessing/Runtime/regex_basic.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extension String {
1212
file: String = #file,
1313
line: UInt = #line
1414
) -> Regex<T>.Match {
15-
guard let result = match(regex) else {
15+
guard let result = matchWhole(regex) else {
1616
expectUnreachable("Failed match", file: file, line: line)
1717
fatalError()
1818
}
@@ -35,7 +35,9 @@ RegexBasicTests.test("Basic") {
3535
RegexBasicTests.test("Modern") {
3636
let input = "aabccd"
3737

38-
let match1 = input.expectMatch(#|a a bc c /*hello*/ .|#)
38+
let match1 = input.expectMatch(#/
39+
a a bc c (?#hello) . # comment
40+
/#)
3941
expectEqual("aabccd", match1.0)
4042
expectTrue("aabccd" == match1.output)
4143
}

0 commit comments

Comments
 (0)