Skip to content

Commit f7da070

Browse files
committed
Remove a last at function that took an array
1 parent f150ce8 commit f7da070

File tree

3 files changed

+44
-19
lines changed

3 files changed

+44
-19
lines changed

Sources/SwiftParser/Expressions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,7 +2225,7 @@ extension Parser {
22252225
public mutating func parseSwitchCases(allowStandaloneStmtRecovery: Bool) -> RawSwitchCaseListSyntax {
22262226
var elements = [RawSwitchCaseListSyntax.Element]()
22272227
var elementsProgress = LoopProgressCondition()
2228-
while !self.at(any: [.eof, .rightBrace, .poundEndifKeyword, .poundElseifKeyword, .poundElseKeyword])
2228+
while !self.at(.eof, .rightBrace) && !self.at(.poundEndifKeyword, .poundElseifKeyword, .poundElseKeyword)
22292229
&& elementsProgress.evaluate(currentToken)
22302230
{
22312231
if self.withLookahead({ $0.isAtStartOfSwitchCase(allowRecovery: false) }) {
@@ -2294,7 +2294,7 @@ extension Parser {
22942294
mutating func parseSwitchCaseBody() -> RawCodeBlockItemListSyntax {
22952295
var items = [RawCodeBlockItemSyntax]()
22962296
var loopProgress = LoopProgressCondition()
2297-
while !self.at(any: [.rightBrace, .poundEndifKeyword, .poundElseifKeyword, .poundElseKeyword])
2297+
while !self.at(.rightBrace) && !self.at(.poundEndifKeyword, .poundElseifKeyword, .poundElseKeyword)
22982298
&& !self.withLookahead({ $0.isStartOfConditionalSwitchCases() }),
22992299
let newItem = self.parseCodeBlockItem(),
23002300
loopProgress.evaluate(currentToken)

Sources/SwiftParser/Statements.swift

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -629,11 +629,48 @@ extension Parser {
629629

630630
extension Parser {
631631
private mutating func isStartOfReturnExpr() -> Bool {
632-
if self.at(any: [
633-
.rightBrace, .keyword(.case), .keyword(.default), .semicolon, .eof,
634-
.poundIfKeyword, .poundEndifKeyword, .poundElseKeyword,
635-
.poundElseifKeyword,
636-
]) {
632+
enum NotReturnExprStart: TokenSpecSet {
633+
case rightBrace
634+
case `case`
635+
case `default`
636+
case semicolon
637+
case poundIfKeyword
638+
case poundEndifKeyword
639+
case poundElseKeyword
640+
case poundElseifKeyword
641+
case eof
642+
643+
init?(lexeme: Lexer.Lexeme) {
644+
switch lexeme {
645+
case TokenSpec(.rightBrace): self = .rightBrace
646+
case TokenSpec(.case): self = .case
647+
case TokenSpec(.default): self = .default
648+
case TokenSpec(.semicolon): self = .semicolon
649+
case TokenSpec(.poundIfKeyword): self = .poundIfKeyword
650+
case TokenSpec(.poundEndifKeyword): self = .poundEndifKeyword
651+
case TokenSpec(.poundElseKeyword): self = .poundElseKeyword
652+
case TokenSpec(.poundElseifKeyword): self = .poundElseifKeyword
653+
case TokenSpec(.eof): self = .eof
654+
default: return nil
655+
}
656+
}
657+
658+
var spec: TokenSpec {
659+
switch self {
660+
case .rightBrace: return .rightBrace
661+
case .case: return .keyword(.case)
662+
case .default: return .keyword(.default)
663+
case .semicolon: return .semicolon
664+
case .poundIfKeyword: return .poundIfKeyword
665+
case .poundEndifKeyword: return .poundEndifKeyword
666+
case .poundElseKeyword: return .poundElseKeyword
667+
case .poundElseifKeyword: return .poundElseifKeyword
668+
case .eof: return .eof
669+
}
670+
}
671+
}
672+
673+
if self.at(anyIn: NotReturnExprStart.self) != nil {
637674
return false
638675
}
639676
// Allowed for if/switch expressions.

Sources/SwiftParser/TokenConsumer.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,6 @@ extension TokenConsumer {
8888
return self.currentToken.isContextualPunctuator(name)
8989
}
9090

91-
/// Returns whether the kind of the current token is any of the given
92-
/// kinds and additionally satisfies `condition`.
93-
///
94-
/// - Parameter kinds: The kinds to test for.
95-
/// - Parameter condition: An additional condition that must be satisfied for
96-
/// this function to return `true`.
97-
/// - Returns: `true` if the current token's kind is in `kinds`.
98-
@inline(__always)
99-
mutating func at(any kinds: [RawTokenKind]) -> Bool {
100-
return kinds.contains(where: { TokenSpec($0) ~= self.currentToken })
101-
}
102-
10391
/// Checks whether the parser is currently positioned at any token in `Subset`.
10492
/// If this is the case, return the `Subset` case that the parser is positioned in
10593
/// as well as a handle to consume that token.

0 commit comments

Comments
 (0)