File tree Expand file tree Collapse file tree 6 files changed +8
-135
lines changed
CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax Expand file tree Collapse file tree 6 files changed +8
-135
lines changed Original file line number Diff line number Diff line change @@ -304,32 +304,6 @@ let tokenKindFile = SourceFileSyntax {
304304 }
305305 }
306306
307- try ! VariableDeclSyntax (
308- """
309- /// Returns `true` if the token is a Swift keyword.
310- ///
311- /// Keywords are reserved unconditionally for use by Swift and may not
312- /// appear as identifiers in any position without being escaped. For example,
313- /// `class`, `func`, or `import`.
314- public var isLexerClassifiedKeyword: Bool
315- """
316- ) {
317- try ! SwitchExprSyntax ( " switch self.base " ) {
318- SwitchCaseSyntax ( " case .eof: " ) {
319- StmtSyntax ( " return false " )
320- }
321-
322- for token in SYNTAX_TOKENS where token. swiftKind != " keyword " {
323- SwitchCaseSyntax ( " case . \( raw: token. swiftKind) : " ) {
324- StmtSyntax ( " return \( raw: token. isKeyword) " )
325- }
326- }
327- SwitchCaseSyntax ( " case .keyword: " ) {
328- StmtSyntax ( " return self.keyword.isLexerClassified " )
329- }
330- }
331- }
332-
333307 try ! VariableDeclSyntax (
334308 """
335309 /// Returns `true` if the token is a Swift punctuator.
Original file line number Diff line number Diff line change @@ -2562,7 +2562,7 @@ extension Parser.Lookahead {
25622562 if self . peek ( ) . rawTokenKind != . identifier,
25632563 self . peek ( ) . rawTokenKind != . keyword( . Self) ,
25642564 self . peek ( ) . rawTokenKind != . keyword( . self ) ,
2565- !self . peek ( ) . rawTokenKind . isLexerClassifiedKeyword
2565+ !self . peek ( ) . isLexerClassifiedKeyword
25662566 {
25672567 return false
25682568 }
Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ extension Parser {
6868 ident = self . expectIdentifierWithoutRecovery ( )
6969 } else if flags. contains ( . operators) , let ( _, _) = self . at ( anyIn: Operator . self) {
7070 ident = self . consumeAnyToken ( remapping: . binaryOperator)
71- } else if flags. contains ( . keywords) && self . currentToken. rawTokenKind . isLexerClassifiedKeyword {
71+ } else if flags. contains ( . keywords) && self . currentToken. isLexerClassifiedKeyword {
7272 ident = self . consumeAnyToken ( remapping: . identifier)
7373 } else {
7474 ident = self . expectIdentifierWithoutRecovery ( )
@@ -279,7 +279,10 @@ extension Lexer.Lexeme {
279279 }
280280
281281 var isLexerClassifiedKeyword : Bool {
282- self . rawTokenKind. isLexerClassifiedKeyword
282+ // Only lexer-classified lexemes have `RawTokenKind` of `keyword.
283+ // Contextual keywords will only be made keywords when a `RawTokenSyntax` is
284+ // constructed from them.
285+ return self . rawTokenKind. base == . keyword
283286 }
284287
285288 func starts( with symbol: SyntaxText ) -> Bool {
Original file line number Diff line number Diff line change @@ -427,7 +427,7 @@ extension Parser {
427427 self . missingToken ( . identifier, text: nil )
428428 )
429429 } else if keywordRecovery,
430- ( self . currentToken. rawTokenKind . isLexerClassifiedKeyword || self . currentToken. rawTokenKind == . wildcard) ,
430+ ( self . currentToken. isLexerClassifiedKeyword || self . currentToken. rawTokenKind == . wildcard) ,
431431 !self . currentToken. isAtStartOfLine
432432 {
433433 let keyword = self . consumeAnyToken ( )
Original file line number Diff line number Diff line change @@ -131,7 +131,7 @@ extension Parser {
131131 )
132132 )
133133 case nil :
134- if self . currentToken. rawTokenKind . isLexerClassifiedKeyword, !self . currentToken. isAtStartOfLine {
134+ if self . currentToken. isLexerClassifiedKeyword, !self . currentToken. isAtStartOfLine {
135135 // Recover if a keyword was used instead of an identifier
136136 let keyword = self . consumeAnyToken ( )
137137 return RawPatternSyntax (
Original file line number Diff line number Diff line change @@ -1095,110 +1095,6 @@ public struct RawTokenKind: Equatable, Hashable {
10951095 }
10961096 }
10971097
1098- /// Returns `true` if the token is a Swift keyword.
1099- ///
1100- /// Keywords are reserved unconditionally for use by Swift and may not
1101- /// appear as identifiers in any position without being escaped. For example,
1102- /// `class`, `func`, or `import`.
1103- public var isLexerClassifiedKeyword : Bool {
1104- switch self . base {
1105- case . eof:
1106- return false
1107- case . wildcard:
1108- return false
1109- case . leftParen:
1110- return false
1111- case . rightParen:
1112- return false
1113- case . leftBrace:
1114- return false
1115- case . rightBrace:
1116- return false
1117- case . leftSquareBracket:
1118- return false
1119- case . rightSquareBracket:
1120- return false
1121- case . leftAngle:
1122- return false
1123- case . rightAngle:
1124- return false
1125- case . period:
1126- return false
1127- case . comma:
1128- return false
1129- case . ellipsis:
1130- return false
1131- case . colon:
1132- return false
1133- case . semicolon:
1134- return false
1135- case . equal:
1136- return false
1137- case . atSign:
1138- return false
1139- case . pound:
1140- return false
1141- case . prefixAmpersand:
1142- return false
1143- case . arrow:
1144- return false
1145- case . backtick:
1146- return false
1147- case . backslash:
1148- return false
1149- case . exclamationMark:
1150- return false
1151- case . postfixQuestionMark:
1152- return false
1153- case . infixQuestionMark:
1154- return false
1155- case . stringQuote:
1156- return false
1157- case . singleQuote:
1158- return false
1159- case . multilineStringQuote:
1160- return false
1161- case . poundSourceLocationKeyword:
1162- return true
1163- case . poundIfKeyword:
1164- return true
1165- case . poundElseKeyword:
1166- return true
1167- case . poundElseifKeyword:
1168- return true
1169- case . poundEndifKeyword:
1170- return true
1171- case . poundAvailableKeyword:
1172- return true
1173- case . poundUnavailableKeyword:
1174- return true
1175- case . integerLiteral:
1176- return false
1177- case . floatingLiteral:
1178- return false
1179- case . regexLiteral:
1180- return false
1181- case . unknown:
1182- return false
1183- case . identifier:
1184- return false
1185- case . binaryOperator:
1186- return false
1187- case . postfixOperator:
1188- return false
1189- case . prefixOperator:
1190- return false
1191- case . dollarIdentifier:
1192- return false
1193- case . rawStringDelimiter:
1194- return false
1195- case . stringSegment:
1196- return false
1197- case . keyword:
1198- return self . keyword. isLexerClassified
1199- }
1200- }
1201-
12021098 /// Returns `true` if the token is a Swift punctuator.
12031099 ///
12041100 /// Punctuation tokens generally separate identifiers from each other. For
You can’t perform that action at this time.
0 commit comments