Skip to content

Commit be1fac0

Browse files
committed
Simplify consumption of ellipsis
1 parent 15e4e8f commit be1fac0

File tree

2 files changed

+3
-23
lines changed

2 files changed

+3
-23
lines changed

Sources/SwiftParser/Declarations.swift

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -407,22 +407,6 @@ extension Parser {
407407
}
408408

409409
extension Parser {
410-
/// Attempt to consume an ellipsis prefix, splitting the current token if
411-
/// necessary.
412-
mutating func tryConsumeEllipsisPrefix() -> RawTokenSyntax? {
413-
// It is not sufficient to check currentToken.isEllipsis here, as we may
414-
// have something like '...>'.
415-
// TODO: Recovery for different numbers of dots (which also needs to be
416-
// done for regular variadics).
417-
guard self.at(anyIn: Operator.self) != nil else { return nil }
418-
let text = self.currentToken.tokenText
419-
guard text.hasPrefix("...") else { return nil }
420-
return self.consumePrefix(
421-
SyntaxText(rebasing: text.prefix(3)),
422-
as: .ellipsis
423-
)
424-
}
425-
426410
mutating func parseGenericParameters() -> RawGenericParameterClauseSyntax {
427411
if let remainingTokens = remainingTokensIfMaximumNestingLevelReached() {
428412
return RawGenericParameterClauseSyntax(
@@ -453,7 +437,7 @@ extension Parser {
453437

454438
// Parse the unsupported ellipsis for a type parameter pack 'T...'.
455439
let unexpectedBetweenNameAndColon: RawUnexpectedNodesSyntax?
456-
if let ellipsis = tryConsumeEllipsisPrefix() {
440+
if let ellipsis = self.consume(ifPrefix: "...", as: .ellipsis) {
457441
unexpectedBetweenNameAndColon = RawUnexpectedNodesSyntax([ellipsis], arena: self.arena)
458442
if each == nil {
459443
each = missingToken(.each)
@@ -923,7 +907,7 @@ extension Parser {
923907
}
924908

925909
// Detect an attempt to use (early syntax) type parameter pack.
926-
let ellipsis = tryConsumeEllipsisPrefix()
910+
let ellipsis = self.consume(ifPrefix: "...", as: .ellipsis)
927911

928912
// Parse optional inheritance clause.
929913
let inheritance: RawTypeInheritanceClauseSyntax?

Sources/SwiftParser/Types.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ extension Parser.Lookahead {
650650
return false
651651
}
652652

653-
if self.currentToken.isEllipsis {
653+
if self.atContextualPunctuator("...") {
654654
self.consumeAnyToken()
655655
}
656656

@@ -1067,10 +1067,6 @@ extension Lexer.Lexeme {
10671067
|| self.rawTokenKind == .prefixOperator
10681068
}
10691069

1070-
var isEllipsis: Bool {
1071-
return self.isAnyOperator && self.tokenText == "..."
1072-
}
1073-
10741070
var isGenericTypeDisambiguatingToken: Bool {
10751071
switch self.rawTokenKind {
10761072
case .rightParen,

0 commit comments

Comments
 (0)