Skip to content

Commit a0fbe9f

Browse files
natecook1000hamishknight
authored andcommitted
Address feedback, expand tests
1 parent 1beb32f commit a0fbe9f

File tree

2 files changed

+54
-27
lines changed

2 files changed

+54
-27
lines changed

Sources/_StringProcessing/Engine/Processor.swift

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,17 @@ extension Processor {
239239
}
240240
}
241241

242+
mutating func clearThrough(_ address: InstructionAddress) {
243+
while let sp = savePoints.popLast() {
244+
if sp.pc == address {
245+
controller.step()
246+
return
247+
}
248+
}
249+
// TODO: What should we do here?
250+
fatalError("Invalid code: Tried to clear save points when empty")
251+
}
252+
242253
mutating func cycle() {
243254
_checkInvariants()
244255
assert(state == .inProgress)
@@ -250,7 +261,6 @@ extension Processor {
250261
}
251262
let (opcode, payload) = fetch().destructure
252263

253-
OpCodeSwitch:
254264
switch opcode {
255265
case .invalid:
256266
fatalError("Invalid program")
@@ -329,15 +339,7 @@ extension Processor {
329339
}
330340

331341
case .clearThrough:
332-
let addr = payload.addr
333-
while let sp = savePoints.popLast() {
334-
if sp.pc == addr {
335-
controller.step()
336-
break OpCodeSwitch
337-
}
338-
}
339-
// TODO: What should we do here?
340-
fatalError("Invalid code: Tried to clear save points when empty")
342+
clearThrough(payload.addr)
341343

342344
case .peek:
343345
fatalError()

Tests/RegexTests/MatchTests.swift

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -917,12 +917,12 @@ extension RegexTests {
917917
input: "Price: 100 pesos", match: "100")
918918

919919
// More complex lookaheads
920-
firstMatchTest(
921-
#"(?=.*e)(?=.*o)(?!.*z)"#,
922-
input: "hello", match: "")
923-
firstMatchTest(
924-
#"^(?=.*e)(?=.*o)(?!.*h)"#,
925-
input: "hello", match: nil)
920+
firstMatchTests(
921+
#"(?=.*e)(?=.*o)(?!.*z)."#,
922+
(input: "hello", match: "h"),
923+
(input: "hzello", match: "e"),
924+
(input: "hezllo", match: nil),
925+
(input: "helloz", match: nil))
926926

927927
firstMatchTest(
928928
#"(?<=USD)\d+"#, input: "Price: USD100", match: "100", xfail: true)
@@ -1069,18 +1069,43 @@ extension RegexTests {
10691069
firstMatchTest(
10701070
#"(?:(?>a)|.b)c"#, input: "123abcacxyz", match: "abc")
10711071

1072-
// Quantifier behavior inside atomic
1073-
firstMatchTest(
1074-
#"^(?>a+?)a$"#, input: "aa", match: "aa")
1075-
firstMatchTest(
1076-
#"^(?>a+?)a$"#, input: "aaa", match: nil)
1077-
firstMatchTest(
1078-
#"(?>a++)a"#, input: "aaa", match: nil)
1072+
// Quantifier behavior inside atomic groups
1073+
1074+
// (?:a+?) matches as few 'a's as possible, after matching the first
1075+
// (?>a+?) always matches exactly one 'a'
1076+
firstMatchTests(
1077+
#"^(?:a+?)a$"#,
1078+
(input: "a", match: nil),
1079+
(input: "aa", match: "aa"),
1080+
(input: "aaa", match: "aaa"))
1081+
firstMatchTests(
1082+
#"^(?>a+?)a$"#,
1083+
(input: "a", match: nil),
1084+
(input: "aa", match: "aa"),
1085+
(input: "aaa", match: nil))
1086+
1087+
// (?:a?+) and (?>a?+) are equivalent: they match one 'a' if available
1088+
firstMatchTests(
1089+
#"^(?:a?+)a$"#,
1090+
(input: "a", match: nil),
1091+
xfail: true)
1092+
firstMatchTests(
1093+
#"^(?:a?+)a$"#,
1094+
(input: "aa", match: "aa"),
1095+
(input: "aaa", match: nil))
1096+
firstMatchTests(
1097+
#"^(?>a?+)a$"#,
1098+
(input: "a", match: nil),
1099+
(input: "aa", match: "aa"),
1100+
(input: "aaa", match: nil))
10791101

1080-
firstMatchTest(
1081-
#"(?>(\d+))\w+\1"#, input: "123x12", match: nil)
1082-
firstMatchTest(
1083-
#"(?>(\d+))\w+\1"#, input: "123x23", match: "23x23",
1102+
firstMatchTests(
1103+
#"(?>(\d+))\w+\1"#,
1104+
(input: "123x12", match: nil))
1105+
firstMatchTests(
1106+
#"(?>(\d+))\w+\1"#,
1107+
(input: "23x23", match: "23x23"),
1108+
(input: "123x23", match: "23x23"),
10841109
xfail: true)
10851110

10861111
// TODO: Test example where non-atomic is significant

0 commit comments

Comments
 (0)