Skip to content

Commit 32fbefd

Browse files
committed
Add error case for unknown '(*...'
Missed this when implementing the rest of the group kinds. Because we don't backtrack, we should throw an error here after consuming a `*` in a group.
1 parent 3c5ba0f commit 32fbefd

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Sources/_MatchingEngine/Regex/Parse/LexicalAnalysis.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,8 @@ extension Source {
516516
src.tryEat(sequence: "atomic_script_run:") {
517517
return .atomicScriptRun
518518
}
519+
520+
throw ParseError.misc("Quantifier '*' must follow operand")
519521
}
520522

521523
// (_:)

Tests/RegexTests/LexTests.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@ extension RegexTests {
8585
"12", base: "U", expectedDigits: 8)
8686
diagnoseUniScalarOverflow("{123456789}", base: "u")
8787
diagnoseUniScalarOverflow("{123456789}", base: "x")
88-
88+
89+
// Test expected group.
90+
diagnose(#"(*"#, expecting: .misc("Quantifier '*' must follow operand")) {
91+
_ = try $0.lexGroupStart()
92+
}
93+
8994
// TODO: want to dummy print out source ranges, etc, test that.
9095
}
9196

0 commit comments

Comments
 (0)