diff --git a/CodeGeneration/Sources/SyntaxSupport/TokenSpec.swift b/CodeGeneration/Sources/SyntaxSupport/TokenSpec.swift index c6b44382c87..b494b0d8caf 100644 --- a/CodeGeneration/Sources/SyntaxSupport/TokenSpec.swift +++ b/CodeGeneration/Sources/SyntaxSupport/TokenSpec.swift @@ -15,35 +15,26 @@ public class TokenSpec { public let name: String public let nameForDiagnostics: String public let text: String? - public let isKeyword: Bool public let associatedValueClass: String? public var swiftKind: String { - let name = lowercaseFirstWord(name: self.name) - - if isKeyword { - return name + "Keyword" - } else { - return name - } + return lowercaseFirstWord(name: self.name) } init( name: String, nameForDiagnostics: String, text: String? = nil, - isKeyword: Bool = false, associatedValueClass: String? = nil ) { self.name = name self.nameForDiagnostics = nameForDiagnostics self.text = text - self.isKeyword = isKeyword self.associatedValueClass = associatedValueClass } } -public class PoundKeywordSpec: TokenSpec { +public class PoundSpec: TokenSpec { init( name: String, nameForDiagnostics: String? = nil, @@ -52,13 +43,12 @@ public class PoundKeywordSpec: TokenSpec { super.init( name: name, nameForDiagnostics: nameForDiagnostics ?? text, - text: text, - isKeyword: true + text: text ) } } -public class PoundObjectLiteralSpec: PoundKeywordSpec { +public class PoundObjectLiteralSpec: PoundSpec { let `protocol`: String init( @@ -76,9 +66,9 @@ public class PoundObjectLiteralSpec: PoundKeywordSpec { } } -public class PoundConfigSpec: PoundKeywordSpec {} +public class PoundConfigSpec: PoundSpec {} -public class PoundDirectiveKeywordSpec: PoundKeywordSpec { +public class PoundDirectiveSpec: PoundSpec { init( name: String, text: String @@ -90,7 +80,7 @@ public class PoundDirectiveKeywordSpec: PoundKeywordSpec { } } -public class PoundConditionalDirectiveKeywordSpec: PoundDirectiveKeywordSpec { +public class PoundConditionalDirectiveSpec: PoundDirectiveSpec { override init( name: String, text: String @@ -110,8 +100,7 @@ public class PunctuatorSpec: TokenSpec { super.init( name: name, nameForDiagnostics: text, - text: text, - isKeyword: false + text: text ) } } @@ -149,11 +138,11 @@ public let SYNTAX_TOKENS: [TokenSpec] = [ PunctuatorSpec(name: "PostfixQuestionMark", text: "?"), PunctuatorSpec(name: "Pound", text: "#"), PoundConfigSpec(name: "PoundAvailable", text: "#available"), - PoundConditionalDirectiveKeywordSpec(name: "PoundElse", text: "#else"), - PoundConditionalDirectiveKeywordSpec(name: "PoundElseif", text: "#elseif"), - PoundConditionalDirectiveKeywordSpec(name: "PoundEndif", text: "#endif"), - PoundConditionalDirectiveKeywordSpec(name: "PoundIf", text: "#if"), - PoundDirectiveKeywordSpec(name: "PoundSourceLocation", text: "#sourceLocation"), + PoundConditionalDirectiveSpec(name: "PoundElse", text: "#else"), + PoundConditionalDirectiveSpec(name: "PoundElseif", text: "#elseif"), + PoundConditionalDirectiveSpec(name: "PoundEndif", text: "#endif"), + PoundConditionalDirectiveSpec(name: "PoundIf", text: "#if"), + PoundDirectiveSpec(name: "PoundSourceLocation", text: "#sourceLocation"), PoundConfigSpec(name: "PoundUnavailable", text: "#unavailable"), PunctuatorSpec(name: "PrefixAmpersand", text: "&"), MiscSpec(name: "PrefixOperator", nameForDiagnostics: "prefix operator"), diff --git a/CodeGeneration/Sources/Utils/SyntaxBuildableChild.swift b/CodeGeneration/Sources/Utils/SyntaxBuildableChild.swift index be382ffef37..1c80a9463e1 100644 --- a/CodeGeneration/Sources/Utils/SyntaxBuildableChild.swift +++ b/CodeGeneration/Sources/Utils/SyntaxBuildableChild.swift @@ -71,9 +71,6 @@ public extension Child { guard let token = token, isToken else { return type.defaultValue.map { InitializerClauseSyntax(value: $0) } } - if token.isKeyword { - return InitializerClauseSyntax(value: ExprSyntax(".\(raw: token.swiftKind)()")) - } if token.text != nil { return InitializerClauseSyntax(value: ExprSyntax(".\(raw: token.swiftKind)Token()")) } diff --git a/CodeGeneration/Sources/Utils/SyntaxBuildableType.swift b/CodeGeneration/Sources/Utils/SyntaxBuildableType.swift index 3f835abefc5..5627684d480 100644 --- a/CodeGeneration/Sources/Utils/SyntaxBuildableType.swift +++ b/CodeGeneration/Sources/Utils/SyntaxBuildableType.swift @@ -63,9 +63,7 @@ public struct SyntaxBuildableType: Hashable { if isOptional { return ExprSyntax(NilLiteralExprSyntax()) } else if let token = token { - if token.isKeyword { - return ExprSyntax(".\(raw: token.swiftKind)()") - } else if token.text != nil { + if token.text != nil { return ExprSyntax(".\(raw: lowercaseFirstWord(name: token.name))Token()") } } diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/IsLexerClassifiedFile.swift b/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/IsLexerClassifiedFile.swift index 10f59a29ada..040be98025c 100644 --- a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/IsLexerClassifiedFile.swift +++ b/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/IsLexerClassifiedFile.swift @@ -58,12 +58,6 @@ let isLexerClassifiedFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { """ ) { try! SwitchExprSyntax("switch self") { - for token in SYNTAX_TOKENS where token.isKeyword { - SwitchCaseSyntax("case .\(raw: token.swiftKind):") { - StmtSyntax("return true") - } - } - SwitchCaseSyntax("case .keyword(let keyword):") { StmtSyntax("return keyword.isLexerClassified") } diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/RawSyntaxValidationFile.swift b/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/RawSyntaxValidationFile.swift index 4f6eb71050a..ea16acead9e 100644 --- a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/RawSyntaxValidationFile.swift +++ b/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/RawSyntaxValidationFile.swift @@ -28,7 +28,7 @@ let rawSyntaxValidationFile = try! SourceFileSyntax(leadingTrivia: copyrightHead IfConfigDeclSyntax( clauses: try IfConfigClauseListSyntax { IfConfigClauseSyntax( - poundKeyword: .poundIfKeyword(), + poundKeyword: .poundIfToken(), condition: ExprSyntax("SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION"), elements: .statements( try CodeBlockItemListSyntax { diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxRewriterFile.swift b/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxRewriterFile.swift index dfe1102fef5..a9a4a1e0a29 100644 --- a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxRewriterFile.swift +++ b/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxRewriterFile.swift @@ -199,7 +199,7 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { """, clauses: IfConfigClauseListSyntax { IfConfigClauseSyntax( - poundKeyword: .poundIfKeyword(), + poundKeyword: .poundIfToken(), condition: ExprSyntax("DEBUG"), elements: .statements( try CodeBlockItemListSyntax { @@ -250,7 +250,7 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { ) ) IfConfigClauseSyntax( - poundKeyword: .poundElseKeyword(), + poundKeyword: .poundElseToken(), elements: .statements( CodeBlockItemListSyntax { try! FunctionDeclSyntax("private func visit(_ data: SyntaxData) -> Syntax") { diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/TokensFile.swift b/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/TokensFile.swift index 1d362359229..89dbbc484ab 100644 --- a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/TokensFile.swift +++ b/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/TokensFile.swift @@ -18,24 +18,7 @@ import Utils let tokensFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { try! ExtensionDeclSyntax("extension TokenSyntax") { for token in SYNTAX_TOKENS { - if token.isKeyword { - DeclSyntax( - """ - public static func \(raw: token.swiftKind)( - leadingTrivia: Trivia = [], - trailingTrivia: Trivia = [], - presence: SourcePresence = .present - ) -> TokenSyntax { - return TokenSyntax( - .\(raw: token.swiftKind), - leadingTrivia: leadingTrivia, - trailingTrivia: trailingTrivia, - presence: presence - ) - } - """ - ) - } else if let text = token.text { + if let text = token.text { DeclSyntax( """ public static func \(raw: token.swiftKind)Token( diff --git a/Sources/SwiftBasicFormat/BasicFormat.swift b/Sources/SwiftBasicFormat/BasicFormat.swift index 09d8abedb0d..fff146328e3 100644 --- a/Sources/SwiftBasicFormat/BasicFormat.swift +++ b/Sources/SwiftBasicFormat/BasicFormat.swift @@ -239,10 +239,10 @@ open class BasicFormat: SyntaxRewriter { (.multilineStringQuote, .stringSegment), // segment starting a multi-line string literal (.stringSegment, .multilineStringQuote), // ending a multi-line string literal that has a string interpolation segment at its end (.rightParen, .multilineStringQuote), // ending a multi-line string literal that has a string interpolation segment at its end - (.poundEndifKeyword, _), - (_, .poundElseKeyword), - (_, .poundElseifKeyword), - (_, .poundEndifKeyword), + (.poundEndif, _), + (_, .poundElse), + (_, .poundElseif), + (_, .poundEndif), (_, .rightBrace): return true default: @@ -283,7 +283,7 @@ open class BasicFormat: SyntaxRewriter { (.postfixQuestionMark, .leftParen), // init?() or myOptionalClosure?() (.postfixQuestionMark, .period), // someOptional?.someProperty (.pound, _), - (.poundUnavailableKeyword, .leftParen), // #unavailable(...) + (.poundUnavailable, .leftParen), // #unavailable(...) (.prefixAmpersand, _), (.prefixOperator, _), (.rawStringDelimiter, .leftParen), // opening raw string delimiter should never be separate by a space diff --git a/Sources/SwiftIDEUtils/CMakeLists.txt b/Sources/SwiftIDEUtils/CMakeLists.txt index c2f08cf18f5..309fd3efa31 100644 --- a/Sources/SwiftIDEUtils/CMakeLists.txt +++ b/Sources/SwiftIDEUtils/CMakeLists.txt @@ -7,6 +7,7 @@ # See http://swift.org/CONTRIBUTORS.txt for Swift project authors add_swift_host_library(SwiftIDEUtils + SwiftIDEUtilsCompatibility.swift Syntax+Classifications.swift SyntaxClassification.swift SyntaxClassifier.swift diff --git a/Sources/SwiftIDEUtils/SwiftIDEUtilsCompatibility.swift b/Sources/SwiftIDEUtils/SwiftIDEUtilsCompatibility.swift new file mode 100644 index 00000000000..d635efc063a --- /dev/null +++ b/Sources/SwiftIDEUtils/SwiftIDEUtilsCompatibility.swift @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +// This file provides compatiblity aliases to keep dependents of SwiftSyntax building. +// All users of the declarations in this file should transition away from them ASAP. + +public extension SyntaxClassification { + /// A `#` keyword like `#warning`. + @available(*, deprecated, renamed: "poundDirective") + static var poundDirectiveKeyword: SyntaxClassification { + return .poundDirective + } +} + +//==========================================================================// +// IMPORTANT: If you are tempted to add a compatiblity layer code here // +// please insert it in alphabetical order above // +//==========================================================================// diff --git a/Sources/SwiftIDEUtils/SyntaxClassification.swift b/Sources/SwiftIDEUtils/SyntaxClassification.swift index 5a66cb7298e..95dd490bbf2 100644 --- a/Sources/SwiftIDEUtils/SyntaxClassification.swift +++ b/Sources/SwiftIDEUtils/SyntaxClassification.swift @@ -43,8 +43,8 @@ public enum SyntaxClassification { case objectLiteral /// An identifier referring to an operator. case operatorIdentifier - /// A `#` keyword like `#warning`. - case poundDirectiveKeyword + /// A `#` token like `#warning`. + case poundDirective /// A regex literal, including multiline regex literals. case regexLiteral /// The opening and closing parenthesis of string interpolation. @@ -156,20 +156,20 @@ extension RawTokenKind { return .none case .pound: return .none - case .poundAvailableKeyword: - return .keyword - case .poundElseKeyword: - return .poundDirectiveKeyword - case .poundElseifKeyword: - return .poundDirectiveKeyword - case .poundEndifKeyword: - return .poundDirectiveKeyword - case .poundIfKeyword: - return .poundDirectiveKeyword - case .poundSourceLocationKeyword: - return .poundDirectiveKeyword - case .poundUnavailableKeyword: - return .keyword + case .poundAvailable: + return .none + case .poundElse: + return .poundDirective + case .poundElseif: + return .poundDirective + case .poundEndif: + return .poundDirective + case .poundIf: + return .poundDirective + case .poundSourceLocation: + return .poundDirective + case .poundUnavailable: + return .none case .prefixAmpersand: return .none case .prefixOperator: diff --git a/Sources/SwiftParser/Attributes.swift b/Sources/SwiftParser/Attributes.swift index 874a2c3dfd9..0207ae780ae 100644 --- a/Sources/SwiftParser/Attributes.swift +++ b/Sources/SwiftParser/Attributes.swift @@ -14,7 +14,7 @@ extension Parser { mutating func parseAttributeList() -> RawAttributeListSyntax? { - guard self.at(.atSign, .poundIfKeyword) else { + guard self.at(.atSign, .poundIf) else { return nil } @@ -23,7 +23,7 @@ extension Parser { repeat { let attribute = self.parseAttribute() elements.append(attribute) - } while self.at(.atSign, .poundIfKeyword) && loopProgress.evaluate(currentToken) + } while self.at(.atSign, .poundIf) && loopProgress.evaluate(currentToken) return RawAttributeListSyntax(elements: elements, arena: self.arena) } } @@ -213,7 +213,7 @@ extension Parser { } mutating func parseAttribute() -> RawAttributeListSyntax.Element { - if self.at(.poundIfKeyword) { + if self.at(.poundIf) { return .ifConfigDecl( self.parsePoundIfDirective { (parser, _) -> RawAttributeListSyntax.Element in return parser.parseAttribute() diff --git a/Sources/SwiftParser/Declarations.swift b/Sources/SwiftParser/Declarations.swift index 68867cfca87..0e8f53ab3ba 100644 --- a/Sources/SwiftParser/Declarations.swift +++ b/Sources/SwiftParser/Declarations.swift @@ -53,7 +53,7 @@ extension TokenConsumer { allowInitDecl: Bool = true, allowRecovery: Bool = false ) -> Bool { - if self.at(.poundIfKeyword) { + if self.at(.poundIf) { return true } @@ -85,12 +85,12 @@ extension TokenConsumer { } if hasAttribute { - if subparser.at(.rightBrace) || subparser.at(.endOfFile) || subparser.at(.poundEndifKeyword) { + if subparser.at(.rightBrace) || subparser.at(.endOfFile) || subparser.at(.poundEndif) { return true } } - if subparser.at(.poundIfKeyword) { + if subparser.at(.poundIf) { var attrLookahead = subparser.lookahead() return attrLookahead.consumeIfConfigOfAttributes() } @@ -196,7 +196,7 @@ extension Parser { mutating func parseDeclaration(inMemberDeclList: Bool = false) -> RawDeclSyntax { // If we are at a `#if` of attributes, the `#if` directive should be // parsed when we're parsing the attributes. - if self.at(.poundIfKeyword) && !self.withLookahead({ $0.consumeIfConfigOfAttributes() }) { + if self.at(.poundIf) && !self.withLookahead({ $0.consumeIfConfigOfAttributes() }) { let directive = self.parsePoundIfDirective { (parser, _) in let parsedDecl = parser.parseDeclaration() let semicolon = parser.consume(if: .semicolon) @@ -722,7 +722,7 @@ extension Parser { } let decl: RawDeclSyntax - if self.at(.poundSourceLocationKeyword) { + if self.at(.poundSourceLocation) { decl = RawDeclSyntax(self.parsePoundSourceLocationDirective()) } else { decl = self.parseDeclaration(inMemberDeclList: true) diff --git a/Sources/SwiftParser/Directives.swift b/Sources/SwiftParser/Directives.swift index e53eb1b7b5c..f7c64250385 100644 --- a/Sources/SwiftParser/Directives.swift +++ b/Sources/SwiftParser/Directives.swift @@ -14,22 +14,22 @@ extension Parser { private enum IfConfigContinuationClauseStartKeyword: TokenSpecSet { - case poundElseifKeyword - case poundElseKeyword + case poundElseif + case poundElse case pound var spec: TokenSpec { switch self { - case .poundElseifKeyword: return .poundElseifKeyword - case .poundElseKeyword: return .poundElseKeyword + case .poundElseif: return .poundElseif + case .poundElse: return .poundElse case .pound: return TokenSpec(.pound, recoveryPrecedence: .openingPoundIf) } } init?(lexeme: Lexer.Lexeme) { switch PrepareForKeywordMatch(lexeme) { - case TokenSpec(.poundElseifKeyword): self = .poundElseifKeyword - case TokenSpec(.poundElseKeyword): self = .poundElseKeyword + case TokenSpec(.poundElseif): self = .poundElseif + case TokenSpec(.poundElse): self = .poundElse case TokenSpec(.pound): self = .pound default: return nil } @@ -96,7 +96,7 @@ extension Parser { return RawIfConfigDeclSyntax( remainingTokens, clauses: RawIfConfigClauseListSyntax(elements: [], arena: self.arena), - poundEndif: missingToken(.poundEndifKeyword), + poundEndif: missingToken(.poundEndif), arena: self.arena ) } @@ -104,14 +104,14 @@ extension Parser { var clauses = [RawIfConfigClauseSyntax]() // Parse #if - let (unexpectedBeforePoundIfKeyword, poundIfKeyword) = self.expect(.poundIfKeyword) + let (unexpectedBeforePoundIf, poundIf) = self.expect(.poundIf) let condition = RawExprSyntax(self.parseSequenceExpression(.basic, forDirective: true)) let unexpectedBetweenConditionAndElements = self.consumeRemainingTokenOnLine() clauses.append( RawIfConfigClauseSyntax( - unexpectedBeforePoundIfKeyword, - poundKeyword: poundIfKeyword, + unexpectedBeforePoundIf, + poundKeyword: poundIf, condition: condition, unexpectedBetweenConditionAndElements, elements: syntax(&self, parseIfConfigClauseElements(parseElement, addSemicolonIfNeeded: addSemicolonIfNeeded)), @@ -122,21 +122,21 @@ extension Parser { // Proceed to parse #if continuation clauses (#elseif, #else, check #elif typo, #endif) var loopProgress = LoopProgressCondition() LOOP: while let (match, handle) = self.canRecoverTo(anyIn: IfConfigContinuationClauseStartKeyword.self), loopProgress.evaluate(self.currentToken) { - var unexpectedBeforePoundKeyword: RawUnexpectedNodesSyntax? - var poundKeyword: RawTokenSyntax + var unexpectedBeforePound: RawUnexpectedNodesSyntax? + var pound: RawTokenSyntax let condition: RawExprSyntax? let unexpectedBetweenConditionAndElements: RawUnexpectedNodesSyntax? switch match { - case .poundElseifKeyword: - (unexpectedBeforePoundKeyword, poundKeyword) = self.eat(handle) + case .poundElseif: + (unexpectedBeforePound, pound) = self.eat(handle) condition = RawExprSyntax(self.parseSequenceExpression(.basic, forDirective: true)) unexpectedBetweenConditionAndElements = self.consumeRemainingTokenOnLine() - case .poundElseKeyword: - (unexpectedBeforePoundKeyword, poundKeyword) = self.eat(handle) + case .poundElse: + (unexpectedBeforePound, pound) = self.eat(handle) if let ifToken = self.consume(if: .init(.if, allowAtStartOfLine: false)) { - unexpectedBeforePoundKeyword = RawUnexpectedNodesSyntax(combining: unexpectedBeforePoundKeyword, poundKeyword, ifToken, arena: self.arena) - poundKeyword = self.missingToken(.poundElseifKeyword) + unexpectedBeforePound = RawUnexpectedNodesSyntax(combining: unexpectedBeforePound, pound, ifToken, arena: self.arena) + pound = self.missingToken(.poundElseif) condition = RawExprSyntax(self.parseSequenceExpression(.basic, forDirective: true)) } else { condition = nil @@ -144,12 +144,12 @@ extension Parser { unexpectedBetweenConditionAndElements = self.consumeRemainingTokenOnLine() case .pound: if self.atElifTypo() { - (unexpectedBeforePoundKeyword, poundKeyword) = self.eat(handle) + (unexpectedBeforePound, pound) = self.eat(handle) guard let elif = self.consume(if: TokenSpec(.identifier, allowAtStartOfLine: false)) else { preconditionFailure("The current token should be an identifier, guaranteed by the `atElifTypo` check.") } - unexpectedBeforePoundKeyword = RawUnexpectedNodesSyntax(combining: unexpectedBeforePoundKeyword, poundKeyword, elif, arena: self.arena) - poundKeyword = self.missingToken(.poundElseifKeyword) + unexpectedBeforePound = RawUnexpectedNodesSyntax(combining: unexpectedBeforePound, pound, elif, arena: self.arena) + pound = self.missingToken(.poundElseif) condition = RawExprSyntax(self.parseSequenceExpression(.basic, forDirective: true)) unexpectedBetweenConditionAndElements = self.consumeRemainingTokenOnLine() } else { @@ -159,8 +159,8 @@ extension Parser { clauses.append( RawIfConfigClauseSyntax( - unexpectedBeforePoundKeyword, - poundKeyword: poundKeyword, + unexpectedBeforePound, + poundKeyword: pound, condition: condition, unexpectedBetweenConditionAndElements, elements: syntax(&self, parseIfConfigClauseElements(parseElement, addSemicolonIfNeeded: addSemicolonIfNeeded)), @@ -169,9 +169,8 @@ extension Parser { ) } - let (unexpectedBeforePoundEndIf, poundEndIf) = self.expect(.poundEndifKeyword) + let (unexpectedBeforePoundEndIf, poundEndIf) = self.expect(.poundEndif) let unexpectedAfterPoundEndif = self.consumeRemainingTokenOnLine() - return RawIfConfigDeclSyntax( clauses: RawIfConfigClauseListSyntax(elements: clauses, arena: self.arena), unexpectedBeforePoundEndIf, @@ -206,7 +205,7 @@ extension Parser { var elements = [Element]() var elementsProgress = LoopProgressCondition() while !self.at(.endOfFile) - && !self.at(.poundElseKeyword, .poundElseifKeyword, .poundEndifKeyword) + && !self.at(.poundElse, .poundElseif, .poundEndif) && !self.atElifTypo() && elementsProgress.evaluate(currentToken) { diff --git a/Sources/SwiftParser/Expressions.swift b/Sources/SwiftParser/Expressions.swift index 72f87b8bc48..1fb44925a27 100644 --- a/Sources/SwiftParser/Expressions.swift +++ b/Sources/SwiftParser/Expressions.swift @@ -1,4 +1,5 @@ //===----------------------------------------------------------------------===// +//===----------------------------------------------------------------------===// // // This source file is part of the Swift.org open source project // @@ -743,7 +744,7 @@ extension Parser { _ flavor: ExprFlavor, forDirective: Bool ) -> RawExprSyntax { - precondition(self.at(.poundIfKeyword)) + precondition(self.at(.poundIf)) let config = self.parsePoundIfDirective { (parser, isFirstElement) -> RawExprSyntax? in if !isFirstElement { @@ -752,7 +753,7 @@ extension Parser { let head: RawExprSyntax if parser.at(.period) { head = parser.parseDottedExpressionSuffix(nil) - } else if parser.at(.poundIfKeyword) { + } else if parser.at(.poundIf) { head = parser.parseIfConfigExpressionSuffix(nil, flavor, forDirective: forDirective) } else { // TODO: diagnose and skip. @@ -946,7 +947,7 @@ extension Parser { continue } - if self.at(.poundIfKeyword) { + if self.at(.poundIf) { // Check if the first '#if' body starts with '.' , and parse // it as a "postfix ifconfig expression". do { @@ -959,11 +960,11 @@ extension Parser { // .someMember var loopProgress = LoopProgressCondition() repeat { - backtrack.eat(.poundIfKeyword) + backtrack.eat(.poundIf) while !backtrack.at(.endOfFile) && !backtrack.currentToken.isAtStartOfLine { backtrack.skipSingle() } - } while backtrack.at(.poundIfKeyword) && loopProgress.evaluate(backtrack.currentToken) + } while backtrack.at(.poundIf) && loopProgress.evaluate(backtrack.currentToken) guard backtrack.isAtStartOfPostfixExprSuffix() else { break @@ -1281,7 +1282,7 @@ extension Parser { return RawExprSyntax( self.parseMacroExpansionExpr(pattern: pattern, flavor: flavor) ) - case (.poundAvailableKeyword, _)?, (.poundUnavailableKeyword, _)?: + case (.poundAvailable, _)?, (.poundUnavailable, _)?: let poundAvailable = self.parsePoundAvailableConditionElement() return RawExprSyntax( RawIdentifierExprSyntax( @@ -1732,7 +1733,7 @@ extension Parser { // If The next token is at the beginning of a new line and can never start // an element, break. if self.currentToken.isAtStartOfLine - && (self.at(.rightBrace, .poundEndifKeyword) || self.atStartOfDeclaration() || self.atStartOfStatement()) + && (self.at(.rightBrace, .poundEndif) || self.atStartOfDeclaration() || self.atStartOfStatement()) { break } @@ -2238,7 +2239,7 @@ extension Parser.Lookahead { backtrack.eat(.leftBrace) var loopProgress = LoopProgressCondition() while !backtrack.at(.endOfFile, .rightBrace) - && !backtrack.at(.poundEndifKeyword, .poundElseKeyword, .poundElseifKeyword) + && !backtrack.at(.poundEndif, .poundElse, .poundElseif) && loopProgress.evaluate(backtrack.currentToken) { backtrack.skipSingle() @@ -2390,12 +2391,12 @@ extension Parser { mutating func parseSwitchCases(allowStandaloneStmtRecovery: Bool) -> RawSwitchCaseListSyntax { var elements = [RawSwitchCaseListSyntax.Element]() var elementsProgress = LoopProgressCondition() - while !self.at(.endOfFile, .rightBrace) && !self.at(.poundEndifKeyword, .poundElseifKeyword, .poundElseKeyword) + while !self.at(.endOfFile, .rightBrace) && !self.at(.poundEndif, .poundElseif, .poundElse) && elementsProgress.evaluate(currentToken) { if self.withLookahead({ $0.isAtStartOfSwitchCase(allowRecovery: false) }) { elements.append(.switchCase(self.parseSwitchCase())) - } else if self.canRecoverTo(.poundIfKeyword) != nil { + } else if self.canRecoverTo(.poundIf) != nil { // '#if' in 'case' position can enclose zero or more 'case' or 'default' // clauses. elements.append( @@ -2461,7 +2462,7 @@ extension Parser { mutating func parseSwitchCaseBody() -> RawCodeBlockItemListSyntax { parseCodeBlockItemList(until: { - $0.at(.rightBrace) || $0.at(.poundEndifKeyword, .poundElseifKeyword, .poundElseKeyword) || $0.withLookahead({ $0.isStartOfConditionalSwitchCases() }) + $0.at(.rightBrace) || $0.at(.poundEndif, .poundElseif, .poundElse) || $0.withLookahead({ $0.isStartOfConditionalSwitchCases() }) }) } diff --git a/Sources/SwiftParser/Lexer/Cursor.swift b/Sources/SwiftParser/Lexer/Cursor.swift index fba099949cf..1e3ffc6a6a1 100644 --- a/Sources/SwiftParser/Lexer/Cursor.swift +++ b/Sources/SwiftParser/Lexer/Cursor.swift @@ -1563,13 +1563,13 @@ extension Lexer.Cursor { let kind: RawTokenKind switch literal { - case "sourceLocation": kind = .poundSourceLocationKeyword - case "if": kind = .poundIfKeyword - case "else": kind = .poundElseKeyword - case "elseif": kind = .poundElseifKeyword - case "endif": kind = .poundEndifKeyword - case "available": kind = .poundAvailableKeyword - case "unavailable": kind = .poundUnavailableKeyword + case "sourceLocation": kind = .poundSourceLocation + case "if": kind = .poundIf + case "else": kind = .poundElse + case "elseif": kind = .poundElseif + case "endif": kind = .poundEndif + case "available": kind = .poundAvailable + case "unavailable": kind = .poundUnavailable default: // If we didn't find a match, then just return `.pound`. This is highly // dubious in terms of error recovery, but is useful for code completion and diff --git a/Sources/SwiftParser/Lexer/RegexLiteralLexer.swift b/Sources/SwiftParser/Lexer/RegexLiteralLexer.swift index 11d1df0e4fe..7a1615776cb 100644 --- a/Sources/SwiftParser/Lexer/RegexLiteralLexer.swift +++ b/Sources/SwiftParser/Lexer/RegexLiteralLexer.swift @@ -644,11 +644,11 @@ extension Lexer.Cursor { return false // Pound keywords that do not generally sequence expressions. - case .poundAvailableKeyword, .poundSourceLocationKeyword, .poundUnavailableKeyword: + case .poundAvailable, .poundSourceLocation, .poundUnavailable: return false // Pound keywords that generally do sequence expressions. - case .poundIfKeyword, .poundElseKeyword, .poundElseifKeyword, .poundEndifKeyword: + case .poundIf, .poundElse, .poundElseif, .poundEndif: return true // Bits of string/regex grammar, we can't start lexing a regex literal here. diff --git a/Sources/SwiftParser/Lookahead.swift b/Sources/SwiftParser/Lookahead.swift index 6c59e329b7e..3ed3513a881 100644 --- a/Sources/SwiftParser/Lookahead.swift +++ b/Sources/SwiftParser/Lookahead.swift @@ -200,7 +200,7 @@ extension Parser.Lookahead { } while self.consume(if: .period) != nil if self.consume(if: .leftParen) != nil { - while !self.at(.endOfFile, .rightParen, .poundEndifKeyword) { + while !self.at(.endOfFile, .rightParen, .poundEndif) { self.skipSingle() } self.consume(if: .rightParen) @@ -215,11 +215,11 @@ extension Parser.Lookahead { /// - the directive contained non-attributes /// - the directive did not contain any attributes mutating func consumeIfConfigOfAttributes() -> Bool { - precondition(self.at(.poundIfKeyword)) + precondition(self.at(.poundIf)) var didSeeAnyAttributes = false var poundIfLoopProgress = LoopProgressCondition() repeat { - precondition(self.at(.poundIfKeyword, .poundElseKeyword, .poundElseifKeyword)) + precondition(self.at(.poundIf, .poundElse, .poundElseif)) self.consumeAnyToken() // after `#if` or `#elseif` @@ -231,15 +231,15 @@ extension Parser.Lookahead { case .atSign: didSeeAnyAttributes = true _ = self.consumeAttributeList() - case .poundIfKeyword: + case .poundIf: _ = self.consumeIfConfigOfAttributes() default: break ATTRIBUTE_LOOP } } - } while self.at(.poundElseifKeyword, .poundElseKeyword) && poundIfLoopProgress.evaluate(self.currentToken) + } while self.at(.poundElseif, .poundElse) && poundIfLoopProgress.evaluate(self.currentToken) - return didSeeAnyAttributes && self.currentToken.isAtStartOfLine && self.consume(if: .poundEndifKeyword) != nil + return didSeeAnyAttributes && self.currentToken.isAtStartOfLine && self.consume(if: .poundEndif) != nil } } @@ -315,18 +315,18 @@ extension Parser.Lookahead { case leftParen case leftBrace case leftSquare - case poundIfKeyword - case poundElseKeyword - case poundElseifKeyword + case poundIf + case poundElse + case poundElseif init?(lexeme: Lexer.Lexeme) { switch lexeme.rawTokenKind { case .leftParen: self = .leftParen case .leftBrace: self = .leftBrace case .leftSquare: self = .leftSquare - case .poundIfKeyword: self = .poundIfKeyword - case .poundElseKeyword: self = .poundElseKeyword - case .poundElseifKeyword: self = .poundElseifKeyword + case .poundIf: self = .poundIf + case .poundElse: self = .poundElse + case .poundElseif: self = .poundElseif default: return nil } } @@ -336,9 +336,9 @@ extension Parser.Lookahead { case .leftParen: return .leftParen case .leftBrace: return .leftBrace case .leftSquare: return .leftSquare - case .poundIfKeyword: return .poundIfKeyword - case .poundElseKeyword: return .poundElseKeyword - case .poundElseifKeyword: return .poundElseifKeyword + case .poundIf: return .poundIf + case .poundElse: return .poundElse + case .poundElseif: return .poundElseif } } } @@ -371,12 +371,12 @@ extension Parser.Lookahead { case (.leftSquare, let handle)?: self.eat(handle) stack += [.skipSinglePost(start: .leftSquare), .skipUntil(.rightSquare, .rightSquare)] - case (.poundIfKeyword, let handle)?, - (.poundElseKeyword, let handle)?, - (.poundElseifKeyword, let handle)?: + case (.poundIf, let handle)?, + (.poundElse, let handle)?, + (.poundElseif, let handle)?: self.eat(handle) // skipUntil also implicitly stops at tok::pound_endif. - stack += [.skipSinglePost(start: t!.0), .skipUntil(.poundElseKeyword, .poundElseifKeyword)] + stack += [.skipSinglePost(start: t!.0), .skipUntil(.poundElse, .poundElseif)] case nil: self.consumeAnyToken() } @@ -388,16 +388,16 @@ extension Parser.Lookahead { self.consume(if: .rightBrace) case .leftSquare: self.consume(if: .rightSquare) - case .poundIfKeyword, .poundElseKeyword, .poundElseifKeyword: - if self.at(.poundElseKeyword, .poundElseifKeyword) { + case .poundIf, .poundElse, .poundElseif: + if self.at(.poundElse, .poundElseif) { stack += [.skipSingle] } else { - self.consume(if: .poundElseifKeyword) + self.consume(if: .poundElseif) } return } case .skipUntil(let t1, let t2): - if !self.at(.endOfFile, t1, t2) && !self.at(.poundEndifKeyword, .poundElseKeyword, .poundElseifKeyword) { + if !self.at(.endOfFile, t1, t2) && !self.at(.poundEndif, .poundElse, .poundElseif) { stack += [.skipUntil(t1, t2), .skipSingle] } } diff --git a/Sources/SwiftParser/Parser.swift b/Sources/SwiftParser/Parser.swift index bae1cbd082b..65d6eabd039 100644 --- a/Sources/SwiftParser/Parser.swift +++ b/Sources/SwiftParser/Parser.swift @@ -221,9 +221,9 @@ public struct Parser { private mutating func adjustNestingLevel(for tokenKind: RawTokenKind) { switch tokenKind { - case .leftAngle, .leftBrace, .leftParen, .leftSquare, .poundIfKeyword: + case .leftAngle, .leftBrace, .leftParen, .leftSquare, .poundIf: nestingLevel += 1 - case .rightAngle, .rightBrace, .rightParen, .rightSquare, .poundEndifKeyword: + case .rightAngle, .rightBrace, .rightParen, .rightSquare, .poundEndif: nestingLevel -= 1 default: break diff --git a/Sources/SwiftParser/Statements.swift b/Sources/SwiftParser/Statements.swift index 49426f1a860..4c754318498 100644 --- a/Sources/SwiftParser/Statements.swift +++ b/Sources/SwiftParser/Statements.swift @@ -216,7 +216,7 @@ extension Parser { /// `lastBindingKind` will be used to get a correct fall back, when there is missing `var` or `let` in a `if` statement etc. mutating func parseConditionElement(lastBindingKind: RawTokenSyntax?) -> RawConditionElementSyntax.Condition { // Parse a leading #available/#unavailable condition if present. - if self.at(.poundAvailableKeyword, .poundUnavailableKeyword) { + if self.at(.poundAvailable, .poundUnavailable) { return self.parsePoundAvailableConditionElement() } @@ -333,7 +333,7 @@ extension Parser { /// availability-condition → '#available' '(' availability-arguments ')' /// availability-condition → '#unavailable' '(' availability-arguments ')' mutating func parsePoundAvailableConditionElement() -> RawConditionElementSyntax.Condition { - precondition(self.at(.poundAvailableKeyword, .poundUnavailableKeyword)) + precondition(self.at(.poundAvailable, .poundUnavailable)) let keyword = self.consumeAnyToken() let (unexpectedBeforeLParen, lparen) = self.expect(.leftParen) let arguments = self.parseAvailabilitySpecList() @@ -690,10 +690,10 @@ extension Parser { case `case` case `default` case semicolon - case poundIfKeyword - case poundEndifKeyword - case poundElseKeyword - case poundElseifKeyword + case poundIf + case poundEndif + case poundElse + case poundElseif case endOfFile init?(lexeme: Lexer.Lexeme) { @@ -702,10 +702,10 @@ extension Parser { case TokenSpec(.case): self = .case case TokenSpec(.default): self = .default case TokenSpec(.semicolon): self = .semicolon - case TokenSpec(.poundIfKeyword): self = .poundIfKeyword - case TokenSpec(.poundEndifKeyword): self = .poundEndifKeyword - case TokenSpec(.poundElseKeyword): self = .poundElseKeyword - case TokenSpec(.poundElseifKeyword): self = .poundElseifKeyword + case TokenSpec(.poundIf): self = .poundIf + case TokenSpec(.poundEndif): self = .poundEndif + case TokenSpec(.poundElse): self = .poundElse + case TokenSpec(.poundElseif): self = .poundElseif case TokenSpec(.endOfFile): self = .endOfFile default: return nil } @@ -717,10 +717,10 @@ extension Parser { case .case: return .keyword(.case) case .default: return .keyword(.default) case .semicolon: return .semicolon - case .poundIfKeyword: return .poundIfKeyword - case .poundEndifKeyword: return .poundEndifKeyword - case .poundElseKeyword: return .poundElseKeyword - case .poundElseifKeyword: return .poundElseifKeyword + case .poundIf: return .poundIf + case .poundEndif: return .poundEndif + case .poundElse: return .poundElse + case .poundElseif: return .poundElseif case .endOfFile: return .endOfFile } } @@ -1052,7 +1052,7 @@ extension Parser.Lookahead { } mutating func isStartOfConditionalSwitchCases() -> Bool { - guard self.at(.poundIfKeyword) else { + guard self.at(.poundIf) else { return self.isAtStartOfSwitchCase() } @@ -1062,7 +1062,7 @@ extension Parser.Lookahead { lookahead.consumeAnyToken() // just find the end of the line lookahead.skipUntilEndOfLine() - } while lookahead.at(.poundIfKeyword, .poundElseifKeyword, .poundElseKeyword) && loopProgress.evaluate(lookahead.currentToken) + } while lookahead.at(.poundIf, .poundElseif, .poundElse) && loopProgress.evaluate(lookahead.currentToken) return lookahead.isAtStartOfSwitchCase() } } diff --git a/Sources/SwiftParser/TokenPrecedence.swift b/Sources/SwiftParser/TokenPrecedence.swift index 93f0d8f3329..eca5e43a127 100644 --- a/Sources/SwiftParser/TokenPrecedence.swift +++ b/Sources/SwiftParser/TokenPrecedence.swift @@ -53,7 +53,7 @@ enum TokenPrecedence: Comparable { case .openingBrace(closingDelimiter: let closingDelimiter): return closingDelimiter case .openingPoundIf: - return .poundEndifKeyword + return .poundEndif default: return nil } @@ -119,7 +119,7 @@ enum TokenPrecedence: Comparable { case // Literals .floatingLiteral, .integerLiteral, // Pound literals - .poundAvailableKeyword, .poundSourceLocationKeyword, .poundUnavailableKeyword, + .poundAvailable, .poundSourceLocation, .poundUnavailable, // Identifiers .dollarIdentifier, .identifier, // '_' can occur in types to replace a type identifier @@ -161,7 +161,7 @@ enum TokenPrecedence: Comparable { // MARK: Strong bracketed case .leftBrace: self = .openingBrace(closingDelimiter: .rightBrace) - case .poundElseifKeyword, .poundElseKeyword, .poundIfKeyword: + case .poundElseif, .poundElse, .poundIf: self = .openingPoundIf // MARK: Strong punctuator @@ -176,7 +176,7 @@ enum TokenPrecedence: Comparable { // MARK: Strong bracket close case .rightBrace: self = .closingBrace - case .poundEndifKeyword: + case .poundEndif: self = .closingPoundIf case .keyword: preconditionFailure("RawTokenKind passed to init(nonKeyword:) must not be a keyword") diff --git a/Sources/SwiftParser/TokenSpecSet.swift b/Sources/SwiftParser/TokenSpecSet.swift index 2a948b80176..a020b86def7 100644 --- a/Sources/SwiftParser/TokenSpecSet.swift +++ b/Sources/SwiftParser/TokenSpecSet.swift @@ -784,8 +784,8 @@ enum PrimaryExpressionStart: TokenSpecSet { case `nil` case period case pound - case poundAvailableKeyword // For recovery - case poundUnavailableKeyword // For recovery + case poundAvailable // For recovery + case poundUnavailable // For recovery case regexSlash case extendedRegexDelimiter case `self` @@ -814,8 +814,8 @@ enum PrimaryExpressionStart: TokenSpecSet { case TokenSpec(.nil): self = .nil case TokenSpec(.period): self = .period case TokenSpec(.pound): self = .pound - case TokenSpec(.poundAvailableKeyword): self = .poundAvailableKeyword - case TokenSpec(.poundUnavailableKeyword): self = .poundUnavailableKeyword + case TokenSpec(.poundAvailable): self = .poundAvailable + case TokenSpec(.poundUnavailable): self = .poundUnavailable case TokenSpec(.regexSlash): self = .regexSlash case TokenSpec(.extendedRegexDelimiter): self = .extendedRegexDelimiter case TokenSpec(.self): self = .self @@ -847,8 +847,8 @@ enum PrimaryExpressionStart: TokenSpecSet { case .nil: return .keyword(.nil) case .period: return .period case .pound: return .pound - case .poundAvailableKeyword: return .poundAvailableKeyword - case .poundUnavailableKeyword: return .poundUnavailableKeyword + case .poundAvailable: return .poundAvailable + case .poundUnavailable: return .poundUnavailable case .regexSlash: return .regexSlash case .extendedRegexDelimiter: return .extendedRegexDelimiter case .self: return .keyword(.self) diff --git a/Sources/SwiftParser/TopLevel.swift b/Sources/SwiftParser/TopLevel.swift index 311e3bcc757..c30e1eaa1c0 100644 --- a/Sources/SwiftParser/TopLevel.swift +++ b/Sources/SwiftParser/TopLevel.swift @@ -238,7 +238,7 @@ extension Parser { /// If we are not at the top level, such a closing brace should close the /// wrapping declaration instead of being consumed by lookahead. private mutating func parseItem(isAtTopLevel: Bool = false, allowInitDecl: Bool = true) -> RawCodeBlockItemSyntax.Item { - if self.at(.poundIfKeyword) && !self.withLookahead({ $0.consumeIfConfigOfAttributes() }) { + if self.at(.poundIf) && !self.withLookahead({ $0.consumeIfConfigOfAttributes() }) { // If config of attributes is parsed as part of declaration parsing as it // doesn't constitute its own code block item. let directive = self.parsePoundIfDirective { (parser, _) in @@ -260,7 +260,7 @@ extension Parser { return .statements(RawCodeBlockItemListSyntax(elements: items, arena: parser.arena)) } return .decl(RawDeclSyntax(directive)) - } else if self.at(.poundSourceLocationKeyword) { + } else if self.at(.poundSourceLocation) { return .decl(RawDeclSyntax(self.parsePoundSourceLocationDirective())) } else if self.atStartOfDeclaration(isAtTopLevel: isAtTopLevel, allowInitDecl: allowInitDecl) { return .decl(self.parseDeclaration()) diff --git a/Sources/SwiftParser/generated/IsLexerClassified.swift b/Sources/SwiftParser/generated/IsLexerClassified.swift index 590cdb82dae..3c1fc70d8aa 100644 --- a/Sources/SwiftParser/generated/IsLexerClassified.swift +++ b/Sources/SwiftParser/generated/IsLexerClassified.swift @@ -140,20 +140,6 @@ extension TokenKind { @_spi(Diagnostics) @_spi(Testing) public var isLexerClassifiedKeyword: Bool { switch self { - case .poundAvailableKeyword: - return true - case .poundElseKeyword: - return true - case .poundElseifKeyword: - return true - case .poundEndifKeyword: - return true - case .poundIfKeyword: - return true - case .poundSourceLocationKeyword: - return true - case .poundUnavailableKeyword: - return true case .keyword(let keyword): return keyword.isLexerClassified default: diff --git a/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift b/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift index fa585620804..6dcc37ab94a 100644 --- a/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift +++ b/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift @@ -177,15 +177,15 @@ extension AttributedTypeSyntax { extension AvailabilityConditionSyntax { enum AvailabilityKeywordOptions: TokenSpecSet { - case poundAvailableKeyword - case poundUnavailableKeyword + case poundAvailable + case poundUnavailable init?(lexeme: Lexer.Lexeme) { switch PrepareForKeywordMatch(lexeme) { - case TokenSpec(.poundAvailableKeyword): - self = .poundAvailableKeyword - case TokenSpec(.poundUnavailableKeyword): - self = .poundUnavailableKeyword + case TokenSpec(.poundAvailable): + self = .poundAvailable + case TokenSpec(.poundUnavailable): + self = .poundUnavailable default: return nil } @@ -193,10 +193,10 @@ extension AvailabilityConditionSyntax { var spec: TokenSpec { switch self { - case .poundAvailableKeyword: - return .poundAvailableKeyword - case .poundUnavailableKeyword: - return .poundUnavailableKeyword + case .poundAvailable: + return .poundAvailable + case .poundUnavailable: + return .poundUnavailable } } } @@ -1119,18 +1119,18 @@ extension IdentifierPatternSyntax { extension IfConfigClauseSyntax { enum PoundKeywordOptions: TokenSpecSet { - case poundIfKeyword - case poundElseifKeyword - case poundElseKeyword + case poundIf + case poundElseif + case poundElse init?(lexeme: Lexer.Lexeme) { switch PrepareForKeywordMatch(lexeme) { - case TokenSpec(.poundIfKeyword): - self = .poundIfKeyword - case TokenSpec(.poundElseifKeyword): - self = .poundElseifKeyword - case TokenSpec(.poundElseKeyword): - self = .poundElseKeyword + case TokenSpec(.poundIf): + self = .poundIf + case TokenSpec(.poundElseif): + self = .poundElseif + case TokenSpec(.poundElse): + self = .poundElse default: return nil } @@ -1138,12 +1138,12 @@ extension IfConfigClauseSyntax { var spec: TokenSpec { switch self { - case .poundIfKeyword: - return .poundIfKeyword - case .poundElseifKeyword: - return .poundElseifKeyword - case .poundElseKeyword: - return .poundElseKeyword + case .poundIf: + return .poundIf + case .poundElseif: + return .poundElseif + case .poundElse: + return .poundElse } } } diff --git a/Sources/SwiftParser/generated/TokenSpecStaticMembers.swift b/Sources/SwiftParser/generated/TokenSpecStaticMembers.swift index 249a0e29b44..2c61bdb72ed 100644 --- a/Sources/SwiftParser/generated/TokenSpecStaticMembers.swift +++ b/Sources/SwiftParser/generated/TokenSpecStaticMembers.swift @@ -119,32 +119,32 @@ extension TokenSpec { return TokenSpec(.pound) } - static var poundAvailableKeyword: TokenSpec { - return TokenSpec(.poundAvailableKeyword) + static var poundAvailable: TokenSpec { + return TokenSpec(.poundAvailable) } - static var poundElseKeyword: TokenSpec { - return TokenSpec(.poundElseKeyword) + static var poundElse: TokenSpec { + return TokenSpec(.poundElse) } - static var poundElseifKeyword: TokenSpec { - return TokenSpec(.poundElseifKeyword) + static var poundElseif: TokenSpec { + return TokenSpec(.poundElseif) } - static var poundEndifKeyword: TokenSpec { - return TokenSpec(.poundEndifKeyword) + static var poundEndif: TokenSpec { + return TokenSpec(.poundEndif) } - static var poundIfKeyword: TokenSpec { - return TokenSpec(.poundIfKeyword) + static var poundIf: TokenSpec { + return TokenSpec(.poundIf) } - static var poundSourceLocationKeyword: TokenSpec { - return TokenSpec(.poundSourceLocationKeyword) + static var poundSourceLocation: TokenSpec { + return TokenSpec(.poundSourceLocation) } - static var poundUnavailableKeyword: TokenSpec { - return TokenSpec(.poundUnavailableKeyword) + static var poundUnavailable: TokenSpec { + return TokenSpec(.poundUnavailable) } static var prefixAmpersand: TokenSpec { diff --git a/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift b/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift index 34da0c650f1..4e5b1817564 100644 --- a/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift +++ b/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift @@ -55,10 +55,10 @@ fileprivate extension TokenSyntax { /// returns the opposite keyword. var negatedAvailabilityKeyword: TokenSyntax { switch self.tokenKind { - case .poundAvailableKeyword: - return self.with(\.tokenKind, .poundUnavailableKeyword) - case .poundUnavailableKeyword: - return self.with(\.tokenKind, .poundAvailableKeyword) + case .poundAvailable: + return self.with(\.tokenKind, .poundUnavailable) + case .poundUnavailable: + return self.with(\.tokenKind, .poundAvailable) default: preconditionFailure("The availability token of an AvailabilityConditionSyntax should always be #available or #unavailable") } @@ -1094,7 +1094,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor { public override func visit(_ node: IfConfigDeclSyntax) -> SyntaxVisitorContinueKind { for clause in node.clauses where clause.hasError { if let unexpectedBeforePoundKeyword = clause.unexpectedBeforePoundKeyword, - clause.poundKeyword.tokenKind == .poundElseifKeyword, + clause.poundKeyword.tokenKind == .poundElseif, clause.poundKeyword.isMissing { let unexpectedTokens = @@ -1103,7 +1103,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor { .compactMap { $0.as(TokenSyntax.self) } var diagnosticMessage: DiagnosticMessage? - if unexpectedTokens.map(\.tokenKind) == [.poundElseKeyword, .keyword(.if)] { + if unexpectedTokens.map(\.tokenKind) == [.poundElse, .keyword(.if)] { diagnosticMessage = StaticParserError.unexpectedPoundElseSpaceIf } else if unexpectedTokens.first?.tokenKind == .pound, unexpectedTokens.last?.text == "elif" { diagnosticMessage = UnknownDirectiveError(unexpected: unexpectedBeforePoundKeyword) diff --git a/Sources/SwiftParserDiagnostics/generated/TokenNameForDiagnostics.swift b/Sources/SwiftParserDiagnostics/generated/TokenNameForDiagnostics.swift index c62f66e428e..3eccb0c56e4 100644 --- a/Sources/SwiftParserDiagnostics/generated/TokenNameForDiagnostics.swift +++ b/Sources/SwiftParserDiagnostics/generated/TokenNameForDiagnostics.swift @@ -69,19 +69,19 @@ extension TokenKind { return #"?"# case .pound: return #"#"# - case .poundAvailableKeyword: + case .poundAvailable: return #"#available"# - case .poundElseKeyword: + case .poundElse: return #"#else"# - case .poundElseifKeyword: + case .poundElseif: return #"#elseif"# - case .poundEndifKeyword: + case .poundEndif: return #"#endif"# - case .poundIfKeyword: + case .poundIf: return #"#if"# - case .poundSourceLocationKeyword: + case .poundSourceLocation: return #"#sourceLocation"# - case .poundUnavailableKeyword: + case .poundUnavailable: return #"#unavailable"# case .prefixAmpersand: return #"&"# diff --git a/Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift b/Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift index 07571e3fc14..ffef63ca9bf 100644 --- a/Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift +++ b/Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift @@ -71,6 +71,41 @@ public extension TokenKind { return .leftSquare } + @available(*, deprecated, renamed: "poundAvailable") + static var poundAvailableKeyword: TokenKind { + return .poundAvailable + } + + @available(*, deprecated, renamed: "poundElse") + static var poundElseKeyword: TokenKind { + return .poundElse + } + + @available(*, deprecated, renamed: "poundElseif") + static var poundElseifKeyword: TokenKind { + return .poundElseif + } + + @available(*, deprecated, renamed: "poundEndif") + static var poundEndifKeyword: TokenKind { + return .poundEndif + } + + @available(*, deprecated, renamed: "poundIf") + static var poundIfKeyword: TokenKind { + return .poundIf + } + + @available(*, deprecated, renamed: "poundSourceLocation") + static var poundSourceLocationKeyword: TokenKind { + return .poundSourceLocation + } + + @available(*, deprecated, renamed: "poundUnavailable") + static var poundUnavailableKeyword: TokenKind { + return .poundUnavailable + } + @available(*, deprecated, renamed: "rightSquare") static var rightSquareBracket: TokenKind { return .rightSquare @@ -94,6 +129,97 @@ public extension TokenSyntax { ) } + @available(*, deprecated, renamed: "poundAvailableToken") + static func poundAvailableKeyword( + leadingTrivia: Trivia = [], + trailingTrivia: Trivia = [], + presence: SourcePresence = .present + ) -> TokenSyntax { + return poundAvailableToken( + leadingTrivia: leadingTrivia, + trailingTrivia: trailingTrivia, + presence: presence + ) + } + + @available(*, deprecated, renamed: "poundElseToken") + static func poundElseKeyword( + leadingTrivia: Trivia = [], + trailingTrivia: Trivia = [], + presence: SourcePresence = .present + ) -> TokenSyntax { + return poundElseToken( + leadingTrivia: leadingTrivia, + trailingTrivia: trailingTrivia, + presence: presence + ) + } + + @available(*, deprecated, renamed: "poundElseifToken") + static func poundElseIfKeyword( + leadingTrivia: Trivia = [], + trailingTrivia: Trivia = [], + presence: SourcePresence = .present + ) -> TokenSyntax { + return poundElseifToken( + leadingTrivia: leadingTrivia, + trailingTrivia: trailingTrivia, + presence: presence + ) + } + + @available(*, deprecated, renamed: "poundEndifToken") + static func poundEndifKeyword( + leadingTrivia: Trivia = [], + trailingTrivia: Trivia = [], + presence: SourcePresence = .present + ) -> TokenSyntax { + return poundEndifToken( + leadingTrivia: leadingTrivia, + trailingTrivia: trailingTrivia, + presence: presence + ) + } + + @available(*, deprecated, renamed: "poundIfToken") + static func poundIfKeyword( + leadingTrivia: Trivia = [], + trailingTrivia: Trivia = [], + presence: SourcePresence = .present + ) -> TokenSyntax { + return poundIfToken( + leadingTrivia: leadingTrivia, + trailingTrivia: trailingTrivia, + presence: presence + ) + } + + @available(*, deprecated, renamed: "poundSourceLocationToken") + static func poundSourceLocationKeyword( + leadingTrivia: Trivia = [], + trailingTrivia: Trivia = [], + presence: SourcePresence = .present + ) -> TokenSyntax { + return poundSourceLocationToken( + leadingTrivia: leadingTrivia, + trailingTrivia: trailingTrivia, + presence: presence + ) + } + + @available(*, deprecated, renamed: "poundUnavailableToken") + static func poundUnavailableKeyword( + leadingTrivia: Trivia = [], + trailingTrivia: Trivia = [], + presence: SourcePresence = .present + ) -> TokenSyntax { + return poundUnavailableToken( + leadingTrivia: leadingTrivia, + trailingTrivia: trailingTrivia, + presence: presence + ) + } + @available(*, deprecated, renamed: "rightSquareToken") static func rightSquareBracketToken( leadingTrivia: Trivia = [], diff --git a/Sources/SwiftSyntax/generated/TokenKind.swift b/Sources/SwiftSyntax/generated/TokenKind.swift index 18b5e8f37ed..f257f4d0d63 100644 --- a/Sources/SwiftSyntax/generated/TokenKind.swift +++ b/Sources/SwiftSyntax/generated/TokenKind.swift @@ -41,13 +41,13 @@ public enum TokenKind: Hashable { case postfixOperator(String) case postfixQuestionMark case pound - case poundAvailableKeyword - case poundElseKeyword - case poundElseifKeyword - case poundEndifKeyword - case poundIfKeyword - case poundSourceLocationKeyword - case poundUnavailableKeyword + case poundAvailable + case poundElse + case poundElseif + case poundEndif + case poundIf + case poundSourceLocation + case poundUnavailable case prefixAmpersand case prefixOperator(String) case rawStringDelimiter(String) @@ -122,19 +122,19 @@ public enum TokenKind: Hashable { return #"?"# case .pound: return #"#"# - case .poundAvailableKeyword: + case .poundAvailable: return #"#available"# - case .poundElseKeyword: + case .poundElse: return #"#else"# - case .poundElseifKeyword: + case .poundElseif: return #"#elseif"# - case .poundEndifKeyword: + case .poundEndif: return #"#endif"# - case .poundIfKeyword: + case .poundIf: return #"#if"# - case .poundSourceLocationKeyword: + case .poundSourceLocation: return #"#sourceLocation"# - case .poundUnavailableKeyword: + case .poundUnavailable: return #"#unavailable"# case .prefixAmpersand: return #"&"# @@ -213,19 +213,19 @@ public enum TokenKind: Hashable { return #"?"# case .pound: return #"#"# - case .poundAvailableKeyword: + case .poundAvailable: return #"#available"# - case .poundElseKeyword: + case .poundElse: return #"#else"# - case .poundElseifKeyword: + case .poundElseif: return #"#elseif"# - case .poundEndifKeyword: + case .poundEndif: return #"#endif"# - case .poundIfKeyword: + case .poundIf: return #"#if"# - case .poundSourceLocationKeyword: + case .poundSourceLocation: return #"#sourceLocation"# - case .poundUnavailableKeyword: + case .poundUnavailable: return #"#unavailable"# case .prefixAmpersand: return #"&"# @@ -313,19 +313,19 @@ public enum TokenKind: Hashable { return true case .pound: return true - case .poundAvailableKeyword: + case .poundAvailable: return false - case .poundElseKeyword: + case .poundElse: return false - case .poundElseifKeyword: + case .poundElseif: return false - case .poundEndifKeyword: + case .poundEndif: return false - case .poundIfKeyword: + case .poundIf: return false - case .poundSourceLocationKeyword: + case .poundSourceLocation: return false - case .poundUnavailableKeyword: + case .poundUnavailable: return false case .prefixAmpersand: return true @@ -418,19 +418,19 @@ extension TokenKind: Equatable { return true case (.pound, .pound): return true - case (.poundAvailableKeyword, .poundAvailableKeyword): + case (.poundAvailable, .poundAvailable): return true - case (.poundElseKeyword, .poundElseKeyword): + case (.poundElse, .poundElse): return true - case (.poundElseifKeyword, .poundElseifKeyword): + case (.poundElseif, .poundElseif): return true - case (.poundEndifKeyword, .poundEndifKeyword): + case (.poundEndif, .poundEndif): return true - case (.poundIfKeyword, .poundIfKeyword): + case (.poundIf, .poundIf): return true - case (.poundSourceLocationKeyword, .poundSourceLocationKeyword): + case (.poundSourceLocation, .poundSourceLocation): return true - case (.poundUnavailableKeyword, .poundUnavailableKeyword): + case (.poundUnavailable, .poundUnavailable): return true case (.prefixAmpersand, .prefixAmpersand): return true @@ -502,13 +502,13 @@ public enum RawTokenKind: UInt8, Equatable, Hashable { case postfixOperator case postfixQuestionMark case pound - case poundAvailableKeyword - case poundElseKeyword - case poundElseifKeyword - case poundEndifKeyword - case poundIfKeyword - case poundSourceLocationKeyword - case poundUnavailableKeyword + case poundAvailable + case poundElse + case poundElseif + case poundEndif + case poundIf + case poundSourceLocation + case poundUnavailable case prefixAmpersand case prefixOperator case rawStringDelimiter @@ -566,19 +566,19 @@ public enum RawTokenKind: UInt8, Equatable, Hashable { return #"?"# case .pound: return #"#"# - case .poundAvailableKeyword: + case .poundAvailable: return #"#available"# - case .poundElseKeyword: + case .poundElse: return #"#else"# - case .poundElseifKeyword: + case .poundElseif: return #"#elseif"# - case .poundEndifKeyword: + case .poundEndif: return #"#endif"# - case .poundIfKeyword: + case .poundIf: return #"#if"# - case .poundSourceLocationKeyword: + case .poundSourceLocation: return #"#sourceLocation"# - case .poundUnavailableKeyword: + case .poundUnavailable: return #"#unavailable"# case .prefixAmpersand: return #"&"# @@ -666,19 +666,19 @@ public enum RawTokenKind: UInt8, Equatable, Hashable { return true case .pound: return true - case .poundAvailableKeyword: + case .poundAvailable: return false - case .poundElseKeyword: + case .poundElse: return false - case .poundElseifKeyword: + case .poundElseif: return false - case .poundEndifKeyword: + case .poundEndif: return false - case .poundIfKeyword: + case .poundIf: return false - case .poundSourceLocationKeyword: + case .poundSourceLocation: return false - case .poundUnavailableKeyword: + case .poundUnavailable: return false case .prefixAmpersand: return true @@ -795,27 +795,27 @@ extension TokenKind { case .pound: precondition(text.isEmpty || rawKind.defaultText.map(String.init) == text) return .pound - case .poundAvailableKeyword: + case .poundAvailable: precondition(text.isEmpty || rawKind.defaultText.map(String.init) == text) - return .poundAvailableKeyword - case .poundElseKeyword: + return .poundAvailable + case .poundElse: precondition(text.isEmpty || rawKind.defaultText.map(String.init) == text) - return .poundElseKeyword - case .poundElseifKeyword: + return .poundElse + case .poundElseif: precondition(text.isEmpty || rawKind.defaultText.map(String.init) == text) - return .poundElseifKeyword - case .poundEndifKeyword: + return .poundElseif + case .poundEndif: precondition(text.isEmpty || rawKind.defaultText.map(String.init) == text) - return .poundEndifKeyword - case .poundIfKeyword: + return .poundEndif + case .poundIf: precondition(text.isEmpty || rawKind.defaultText.map(String.init) == text) - return .poundIfKeyword - case .poundSourceLocationKeyword: + return .poundIf + case .poundSourceLocation: precondition(text.isEmpty || rawKind.defaultText.map(String.init) == text) - return .poundSourceLocationKeyword - case .poundUnavailableKeyword: + return .poundSourceLocation + case .poundUnavailable: precondition(text.isEmpty || rawKind.defaultText.map(String.init) == text) - return .poundUnavailableKeyword + return .poundUnavailable case .prefixAmpersand: precondition(text.isEmpty || rawKind.defaultText.map(String.init) == text) return .prefixAmpersand @@ -918,20 +918,20 @@ extension TokenKind { return (.postfixQuestionMark, nil) case .pound: return (.pound, nil) - case .poundAvailableKeyword: - return (.poundAvailableKeyword, nil) - case .poundElseKeyword: - return (.poundElseKeyword, nil) - case .poundElseifKeyword: - return (.poundElseifKeyword, nil) - case .poundEndifKeyword: - return (.poundEndifKeyword, nil) - case .poundIfKeyword: - return (.poundIfKeyword, nil) - case .poundSourceLocationKeyword: - return (.poundSourceLocationKeyword, nil) - case .poundUnavailableKeyword: - return (.poundUnavailableKeyword, nil) + case .poundAvailable: + return (.poundAvailable, nil) + case .poundElse: + return (.poundElse, nil) + case .poundElseif: + return (.poundElseif, nil) + case .poundEndif: + return (.poundEndif, nil) + case .poundIf: + return (.poundIf, nil) + case .poundSourceLocation: + return (.poundSourceLocation, nil) + case .poundUnavailable: + return (.poundUnavailable, nil) case .prefixAmpersand: return (.prefixAmpersand, nil) case .prefixOperator(let str): diff --git a/Sources/SwiftSyntax/generated/Tokens.swift b/Sources/SwiftSyntax/generated/Tokens.swift index 70c676feaf9..1b8369265cc 100644 --- a/Sources/SwiftSyntax/generated/Tokens.swift +++ b/Sources/SwiftSyntax/generated/Tokens.swift @@ -407,13 +407,13 @@ extension TokenSyntax { ) } - public static func poundAvailableKeyword( + public static func poundAvailableToken( leadingTrivia: Trivia = [], trailingTrivia: Trivia = [], presence: SourcePresence = .present ) -> TokenSyntax { return TokenSyntax( - .poundAvailableKeyword, + .poundAvailable, leadingTrivia: leadingTrivia, trailingTrivia: trailingTrivia, presence: presence @@ -421,13 +421,13 @@ extension TokenSyntax { ) } - public static func poundElseKeyword( + public static func poundElseToken( leadingTrivia: Trivia = [], trailingTrivia: Trivia = [], presence: SourcePresence = .present ) -> TokenSyntax { return TokenSyntax( - .poundElseKeyword, + .poundElse, leadingTrivia: leadingTrivia, trailingTrivia: trailingTrivia, presence: presence @@ -435,13 +435,13 @@ extension TokenSyntax { ) } - public static func poundElseifKeyword( + public static func poundElseifToken( leadingTrivia: Trivia = [], trailingTrivia: Trivia = [], presence: SourcePresence = .present ) -> TokenSyntax { return TokenSyntax( - .poundElseifKeyword, + .poundElseif, leadingTrivia: leadingTrivia, trailingTrivia: trailingTrivia, presence: presence @@ -449,13 +449,13 @@ extension TokenSyntax { ) } - public static func poundEndifKeyword( + public static func poundEndifToken( leadingTrivia: Trivia = [], trailingTrivia: Trivia = [], presence: SourcePresence = .present ) -> TokenSyntax { return TokenSyntax( - .poundEndifKeyword, + .poundEndif, leadingTrivia: leadingTrivia, trailingTrivia: trailingTrivia, presence: presence @@ -463,13 +463,13 @@ extension TokenSyntax { ) } - public static func poundIfKeyword( + public static func poundIfToken( leadingTrivia: Trivia = [], trailingTrivia: Trivia = [], presence: SourcePresence = .present ) -> TokenSyntax { return TokenSyntax( - .poundIfKeyword, + .poundIf, leadingTrivia: leadingTrivia, trailingTrivia: trailingTrivia, presence: presence @@ -477,13 +477,13 @@ extension TokenSyntax { ) } - public static func poundSourceLocationKeyword( + public static func poundSourceLocationToken( leadingTrivia: Trivia = [], trailingTrivia: Trivia = [], presence: SourcePresence = .present ) -> TokenSyntax { return TokenSyntax( - .poundSourceLocationKeyword, + .poundSourceLocation, leadingTrivia: leadingTrivia, trailingTrivia: trailingTrivia, presence: presence @@ -491,13 +491,13 @@ extension TokenSyntax { ) } - public static func poundUnavailableKeyword( + public static func poundUnavailableToken( leadingTrivia: Trivia = [], trailingTrivia: Trivia = [], presence: SourcePresence = .present ) -> TokenSyntax { return TokenSyntax( - .poundUnavailableKeyword, + .poundUnavailable, leadingTrivia: leadingTrivia, trailingTrivia: trailingTrivia, presence: presence diff --git a/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift b/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift index 0cd38082d0d..c1d8b68997c 100644 --- a/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift +++ b/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift @@ -419,7 +419,7 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) { case .availabilityCondition: assert(layout.count == 9) assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) - assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.poundAvailableKeyword), .tokenKind(.poundUnavailableKeyword)])) + assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.poundAvailable), .tokenKind(.poundUnavailable)])) assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self)) assertNoError(kind, 3, verify(layout[3], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.leftParen)])) assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self)) @@ -1461,7 +1461,7 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) { case .ifConfigClause: assert(layout.count == 7) assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) - assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.poundIfKeyword), .tokenKind(.poundElseifKeyword), .tokenKind(.poundElseKeyword)])) + assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.poundIf), .tokenKind(.poundElseif), .tokenKind(.poundElse)])) assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self)) assertNoError(kind, 3, verify(layout[3], as: RawExprSyntax?.self)) assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self)) @@ -1473,7 +1473,7 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) { assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) assertNoError(kind, 1, verify(layout[1], as: RawIfConfigClauseListSyntax.self)) assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self)) - assertNoError(kind, 3, verify(layout[3], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.poundEndifKeyword)])) + assertNoError(kind, 3, verify(layout[3], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.poundEndif)])) assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self)) case .ifExpr: assert(layout.count == 11) @@ -2090,7 +2090,7 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) { case .poundSourceLocation: assert(layout.count == 9) assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) - assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.poundSourceLocationKeyword)])) + assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.poundSourceLocation)])) assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self)) assertNoError(kind, 3, verify(layout[3], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.leftParen)])) assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self)) diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxDeclNodes.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxDeclNodes.swift index 26d7383d8ba..29285a45ecd 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxDeclNodes.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxDeclNodes.swift @@ -3096,7 +3096,7 @@ public struct IfConfigDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { _ unexpectedBeforeClauses: UnexpectedNodesSyntax? = nil, clauses: IfConfigClauseListSyntax, _ unexpectedBetweenClausesAndPoundEndif: UnexpectedNodesSyntax? = nil, - poundEndif: TokenSyntax = .poundEndifKeyword(), + poundEndif: TokenSyntax = .poundEndifToken(), _ unexpectedAfterPoundEndif: UnexpectedNodesSyntax? = nil, trailingTrivia: Trivia? = nil @@ -5049,7 +5049,7 @@ public struct PoundSourceLocationSyntax: DeclSyntaxProtocol, SyntaxHashable { public init( leadingTrivia: Trivia? = nil, _ unexpectedBeforePoundSourceLocation: UnexpectedNodesSyntax? = nil, - poundSourceLocation: TokenSyntax = .poundSourceLocationKeyword(), + poundSourceLocation: TokenSyntax = .poundSourceLocationToken(), _ unexpectedBetweenPoundSourceLocationAndLeftParen: UnexpectedNodesSyntax? = nil, leftParen: TokenSyntax = .leftParenToken(), _ unexpectedBetweenLeftParenAndArgs: UnexpectedNodesSyntax? = nil, diff --git a/Sources/lit-test-helper/ClassifiedSyntaxTreePrinter.swift b/Sources/lit-test-helper/ClassifiedSyntaxTreePrinter.swift index 40382ef6bcb..6693a371f70 100644 --- a/Sources/lit-test-helper/ClassifiedSyntaxTreePrinter.swift +++ b/Sources/lit-test-helper/ClassifiedSyntaxTreePrinter.swift @@ -27,7 +27,7 @@ extension SyntaxClassification { case .stringLiteral: return "str" case .stringInterpolationAnchor: return "anchor" case .regexLiteral: return "regex" - case .poundDirectiveKeyword: return "#kw" + case .poundDirective: return "#kw" case .buildConfigId: return "#id" case .attribute: return "attr-builtin" case .objectLiteral: return "object-literal" diff --git a/Tests/SwiftParserTest/translated/IfconfigExprTests.swift b/Tests/SwiftParserTest/translated/IfconfigExprTests.swift index 0820cc45f24..d8ddb93d0c2 100644 --- a/Tests/SwiftParserTest/translated/IfconfigExprTests.swift +++ b/Tests/SwiftParserTest/translated/IfconfigExprTests.swift @@ -709,7 +709,7 @@ final class IfconfigExprTests: XCTestCase { """, substructure: Syntax( IfConfigClauseSyntax( - poundKeyword: .poundIfKeyword(), + poundKeyword: .poundIfToken(), condition: FunctionCallExprSyntax( calledExpression: IdentifierExprSyntax(identifier: .identifier("hasFeature")), leftParen: .leftParenToken(), diff --git a/Tests/SwiftSyntaxBuilderTest/IfConfigDeclSyntaxTests.swift b/Tests/SwiftSyntaxBuilderTest/IfConfigDeclSyntaxTests.swift index 00752caee94..2801f7b1954 100644 --- a/Tests/SwiftSyntaxBuilderTest/IfConfigDeclSyntaxTests.swift +++ b/Tests/SwiftSyntaxBuilderTest/IfConfigDeclSyntaxTests.swift @@ -19,7 +19,7 @@ final class IfConfigDeclSyntaxTests: XCTestCase { let buildable = IfConfigDeclSyntax( clauses: IfConfigClauseListSyntax { IfConfigClauseSyntax( - poundKeyword: .poundIfKeyword(), + poundKeyword: .poundIfToken(), condition: ExprSyntax("DEBUG"), elements: .statements( CodeBlockItemListSyntax { @@ -34,7 +34,7 @@ final class IfConfigDeclSyntaxTests: XCTestCase { ) ) IfConfigClauseSyntax( - poundKeyword: .poundElseifKeyword(), + poundKeyword: .poundElseifToken(), condition: ExprSyntax("TEST"), elements: .statements( CodeBlockItemListSyntax { @@ -49,7 +49,7 @@ final class IfConfigDeclSyntaxTests: XCTestCase { ) ) IfConfigClauseSyntax( - poundKeyword: .poundElseKeyword(), + poundKeyword: .poundElseToken(), elements: .statements( CodeBlockItemListSyntax { DeclSyntax( @@ -63,7 +63,7 @@ final class IfConfigDeclSyntaxTests: XCTestCase { ) ) }, - poundEndif: .poundEndifKeyword() + poundEndif: .poundEndifToken() ) assertBuildResult(