Skip to content

Commit f2e7433

Browse files
committed
Small parseCustomCharacterClass cleanup
We can do the semantic members check up-front.
1 parent 8688296 commit f2e7433

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Sources/_RegexParser/Regex/Parse/Parse.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,12 @@ extension Parser {
502502
var members: Array<Member> = []
503503
try parseCCCMembers(into: &members)
504504

505+
// Make sure we have at least one semantic member.
506+
if members.none(\.isSemantic) {
507+
throw Source.LocatedError(
508+
ParseError.expectedCustomCharacterClassMembers, start.location)
509+
}
510+
505511
// If we have a binary set operator, parse it and the next members. Note
506512
// that this means we left associate for a chain of operators.
507513
// TODO: We may want to diagnose and require users to disambiguate, at least
@@ -511,16 +517,12 @@ extension Parser {
511517
var rhs: Array<Member> = []
512518
try parseCCCMembers(into: &rhs)
513519

514-
if members.none(\.isSemantic) || rhs.none(\.isSemantic) {
520+
if rhs.none(\.isSemantic) {
515521
throw Source.LocatedError(
516522
ParseError.expectedCustomCharacterClassMembers, start.location)
517523
}
518524
members = [.setOperation(members, binOp, rhs)]
519525
}
520-
if members.none(\.isSemantic) {
521-
throw Source.LocatedError(
522-
ParseError.expectedCustomCharacterClassMembers, start.location)
523-
}
524526
try source.expect("]")
525527
return CustomCC(start, members, loc(start.location.start))
526528
}

0 commit comments

Comments
 (0)