@@ -257,8 +257,8 @@ extension Parser {
257257 return RawDeclSyntax ( self . parseMacroDeclaration ( attrs: attrs, introducerHandle: handle) )
258258 case nil :
259259 if inMemberDeclList {
260- let isProbablyVarDecl = self . at ( any : [ . identifier, . wildcard] ) && self . peek ( ) . rawTokenKind. is ( any : [ . colon, . equal, . comma] )
261- let isProbablyTupleDecl = self . at ( . leftParen) && self . peek ( ) . rawTokenKind. is ( any : [ . identifier, . wildcard] )
260+ let isProbablyVarDecl = self . at ( . identifier, . wildcard) && self . peek ( ) . rawTokenKind. is ( . colon, . equal, . comma)
261+ let isProbablyTupleDecl = self . at ( . leftParen) && self . peek ( ) . rawTokenKind. is ( . identifier, . wildcard)
262262
263263 if isProbablyVarDecl || isProbablyTupleDecl {
264264 return RawDeclSyntax ( self . parseLetOrVarDeclaration ( attrs, . missing( . keyword( . var) ) ) )
@@ -274,7 +274,7 @@ extension Parser {
274274 )
275275 }
276276
277- let isProbablyFuncDecl = self . at ( any : [ . identifier, . wildcard] ) || self . at ( anyIn: Operator . self) != nil
277+ let isProbablyFuncDecl = self . at ( . identifier, . wildcard) || self . at ( anyIn: Operator . self) != nil
278278
279279 if isProbablyFuncDecl {
280280 return RawDeclSyntax ( self . parseFuncDeclaration ( attrs, . missing( . keyword( . func) ) ) )
@@ -321,7 +321,45 @@ extension Parser {
321321
322322 @_spi ( RawSyntax)
323323 public mutating func parseImportKind( ) -> RawTokenSyntax ? {
324- return self . consume ( ifAny: [ . keyword( . typealias) , . keyword( . struct) , . keyword( . class) , . keyword( . enum) , . keyword( . protocol) , . keyword( . var) , . keyword( . let) , . keyword( . func) ] )
324+ enum ImportKind : RawTokenKindSubset {
325+ case `typealias`
326+ case `struct`
327+ case `class`
328+ case `enum`
329+ case `protocol`
330+ case `var`
331+ case `let`
332+ case `func`
333+
334+ var rawTokenKind : RawTokenKind {
335+ switch self {
336+ case . typealias: return . keyword( . typealias)
337+ case . struct: return . keyword( . struct)
338+ case . class: return . keyword( . class)
339+ case . enum: return . keyword( . enum)
340+ case . protocol: return . keyword( . protocol)
341+ case . var: return . keyword( . var)
342+ case . let: return . keyword( . let)
343+ case . func: return . keyword( . func)
344+ }
345+ }
346+
347+ init ? ( lexeme: Lexer . Lexeme ) {
348+ switch lexeme {
349+ case RawTokenKindMatch ( . typealias) : self = . typealias
350+ case RawTokenKindMatch ( . struct) : self = . struct
351+ case RawTokenKindMatch ( . class) : self = . class
352+ case RawTokenKindMatch ( . enum) : self = . enum
353+ case RawTokenKindMatch ( . protocol) : self = . protocol
354+ case RawTokenKindMatch ( . var) : self = . var
355+ case RawTokenKindMatch ( . let) : self = . let
356+ case RawTokenKindMatch ( . func) : self = . func
357+ default : return nil
358+ }
359+ }
360+ }
361+
362+ return self . consume ( ifAnyIn: ImportKind . self)
325363 }
326364
327365 @_spi ( RawSyntax)
@@ -442,7 +480,7 @@ extension Parser {
442480 let unexpectedBeforeInherited : RawUnexpectedNodesSyntax ?
443481 let inherited : RawTypeSyntax ?
444482 if colon != nil {
445- if self . at ( any : [ . identifier, . keyword( . protocol) , . keyword( . Any) ] ) {
483+ if self . at ( . identifier, . keyword( . protocol) , . keyword( . Any) ) {
446484 unexpectedBeforeInherited = nil
447485 inherited = self . parseType ( )
448486 } else if let classKeyword = self . consume ( if: . keyword( . class) ) {
@@ -769,7 +807,7 @@ extension Parser {
769807 let ( unexpectedBeforeLBrace, lbrace) = self . expect ( . leftBrace)
770808 do {
771809 var loopProgress = LoopProgressCondition ( )
772- while !self . at ( any : [ . eof, . rightBrace] ) && loopProgress. evaluate ( currentToken) {
810+ while !self . at ( . eof, . rightBrace) && loopProgress. evaluate ( currentToken) {
773811 let newItemAtStartOfLine = self . currentToken. isAtStartOfLine
774812 guard let newElement = self . parseMemberDeclListItem ( ) else {
775813 break
@@ -979,7 +1017,7 @@ extension Parser {
9791017
9801018 // Parse the '!' or '?' for a failable initializer.
9811019 let failable : RawTokenSyntax ?
982- if let parsedFailable = self . consume ( ifAny : [ . exclamationMark, . postfixQuestionMark, . infixQuestionMark] ) {
1020+ if let parsedFailable = self . consume ( if : . exclamationMark, . postfixQuestionMark, . infixQuestionMark) {
9831021 failable = parsedFailable
9841022 } else if let parsedFailable = self . consumeIfContextualPunctuator ( " ! " , remapping: . exclamationMark) {
9851023 failable = parsedFailable
@@ -1195,7 +1233,7 @@ extension Parser {
11951233 if !shouldSkipParameterParsing {
11961234 var keepGoing = true
11971235 var loopProgress = LoopProgressCondition ( )
1198- while !self . at ( any : [ . eof, . rightParen] )
1236+ while !self . at ( . eof, . rightParen)
11991237 && keepGoing
12001238 && loopProgress. evaluate ( currentToken)
12011239 {
@@ -1277,7 +1315,7 @@ extension Parser {
12771315 let ( unexpectedBeforeFuncKeyword, funcKeyword) = self . eat ( handle)
12781316 let unexpectedBeforeIdentifier : RawUnexpectedNodesSyntax ?
12791317 let identifier : RawTokenSyntax
1280- if self . at ( anyIn: Operator . self) != nil || self . at ( any : [ . exclamationMark, . prefixAmpersand] ) || self . atRegexLiteralThatCouldBeAnOperator ( ) {
1318+ if self . at ( anyIn: Operator . self) != nil || self . at ( . exclamationMark, . prefixAmpersand) || self . atRegexLiteralThatCouldBeAnOperator ( ) {
12811319 var name = self . currentToken. tokenText
12821320 if name. count > 1 && name. hasSuffix ( " < " ) && self . peek ( ) . rawTokenKind == . identifier {
12831321 name = SyntaxText ( rebasing: name. dropLast ( ) )
@@ -1552,7 +1590,7 @@ extension Parser {
15521590 // Check there is an identifier before consuming
15531591 var look = self . lookahead ( )
15541592 let _ = look. consumeAttributeList ( )
1555- let hasModifier = look. consume ( ifAny : [ . keyword( . mutating) , . keyword( . nonmutating) , . keyword( . __consuming) ] ) != nil
1593+ let hasModifier = look. consume ( if : . keyword( . mutating) , . keyword( . nonmutating) , . keyword( . __consuming) ) != nil
15561594 guard let ( kind, handle) = look. at ( anyIn: AccessorKind . self) ?? forcedKind else {
15571595 return nil
15581596 }
@@ -1563,7 +1601,7 @@ extension Parser {
15631601 // get and set.
15641602 let modifier : RawDeclModifierSyntax ?
15651603 if hasModifier {
1566- let ( unexpectedBeforeName, name) = self . expectAny ( [ . keyword( . mutating) , . keyword( . nonmutating) , . keyword( . __consuming) ] , default: . keyword( . mutating) )
1604+ let ( unexpectedBeforeName, name) = self . expect ( . keyword( . mutating) , . keyword( . nonmutating) , . keyword( . __consuming) , default: . keyword( . mutating) )
15671605 modifier = RawDeclModifierSyntax (
15681606 unexpectedBeforeName,
15691607 name: name,
@@ -1667,7 +1705,7 @@ extension Parser {
16671705 var elements = [ RawAccessorDeclSyntax] ( )
16681706 do {
16691707 var loopProgress = LoopProgressCondition ( )
1670- while !self . at ( any : [ . eof, . rightBrace] ) && loopProgress. evaluate ( currentToken) {
1708+ while !self . at ( . eof, . rightBrace) && loopProgress. evaluate ( currentToken) {
16711709 guard let introducer = self . parseAccessorIntroducer ( ) else {
16721710 // There can only be an implicit getter if no other accessors were
16731711 // seen before this one.
@@ -1812,7 +1850,7 @@ extension Parser {
18121850 case ( _, let handle) ? :
18131851 ( unexpectedBeforeName, name) = self . eat ( handle)
18141852 default :
1815- if let identifier = self . consume ( ifAny : [ . identifier, . dollarIdentifier] , allowTokenAtStartOfLine: false ) {
1853+ if let identifier = self . consume ( if : . identifier, . dollarIdentifier, allowTokenAtStartOfLine: false ) {
18161854 // Recover if the developer tried to use an identifier as the operator name
18171855 unexpectedBeforeName = RawUnexpectedNodesSyntax ( [ identifier] , arena: self . arena)
18181856 } else {
@@ -1827,7 +1865,7 @@ extension Parser {
18271865 var loopProgress = LoopProgressCondition ( )
18281866 while ( identifiersAfterOperatorName. last ?? name) . trailingTriviaByteLength == 0 ,
18291867 self . currentToken. leadingTriviaByteLength == 0 ,
1830- !self . at ( any : [ . colon, . leftBrace, . eof] ) ,
1868+ !self . at ( . colon, . leftBrace, . eof) ,
18311869 loopProgress. evaluate ( self . currentToken)
18321870 {
18331871 identifiersAfterOperatorName. append ( consumeAnyToken ( ) )
@@ -1977,12 +2015,12 @@ extension Parser {
19772015 var elements = [ RawPrecedenceGroupAttributeListSyntax . Element] ( )
19782016 do {
19792017 var attributesProgress = LoopProgressCondition ( )
1980- LOOP: while !self . at ( any : [ . eof, . rightBrace] ) && attributesProgress. evaluate ( currentToken) {
2018+ LOOP: while !self . at ( . eof, . rightBrace) && attributesProgress. evaluate ( currentToken) {
19812019 switch self . at ( anyIn: LabelText . self) {
19822020 case ( . associativity, let handle) ? :
19832021 let associativity = self . eat ( handle)
19842022 let ( unexpectedBeforeColon, colon) = self . expect ( . colon)
1985- var ( unexpectedBeforeValue, value) = self . expectAny ( [ . keyword( . left) , . keyword( . right) , . keyword( . none) ] , default: . keyword( . none) )
2023+ var ( unexpectedBeforeValue, value) = self . expect ( . keyword( . left) , . keyword( . right) , . keyword( . none) , default: . keyword( . none) )
19862024 if value. isMissing, let identifier = self . consume ( if: . identifier) {
19872025 unexpectedBeforeValue = RawUnexpectedNodesSyntax ( combining: unexpectedBeforeValue, identifier, arena: self . arena)
19882026 }
@@ -2001,7 +2039,7 @@ extension Parser {
20012039 case ( . assignment, let handle) ? :
20022040 let assignmentKeyword = self . eat ( handle)
20032041 let ( unexpectedBeforeColon, colon) = self . expect ( . colon)
2004- let ( unexpectedBeforeFlag, flag) = self . expectAny ( [ . keyword( . true ) , . keyword( . false ) ] , default: . keyword( . true ) )
2042+ let ( unexpectedBeforeFlag, flag) = self . expect ( . keyword( . true ) , . keyword( . false ) , default: . keyword( . true ) )
20052043 let unexpectedAfterFlag : RawUnexpectedNodesSyntax ?
20062044 if flag. isMissing, let unexpectedIdentifier = self . consume ( if: . identifier, allowTokenAtStartOfLine: false ) {
20072045 unexpectedAfterFlag = RawUnexpectedNodesSyntax ( [ unexpectedIdentifier] , arena: self . arena)
0 commit comments