Skip to content

Commit 14ddf4e

Browse files
authored
Merge pull request #1267 from ahoppen/ahoppen/remove-pound-keywords
Remove pound keywords token kinds
2 parents b7d7cd4 + 0887fdd commit 14ddf4e

File tree

10 files changed

+2
-752
lines changed

10 files changed

+2
-752
lines changed

CodeGeneration/Sources/SyntaxSupport/gyb_generated/TokenSpec.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,6 @@ public let SYNTAX_TOKENS: [TokenSpec] = [
196196
PunctuatorSpec(name: "StringQuote", kind: "string_quote", text: "\"", classification: "StringLiteral"),
197197
PunctuatorSpec(name: "SingleQuote", kind: "single_quote", text: "\'", classification: "StringLiteral"),
198198
PunctuatorSpec(name: "MultilineStringQuote", kind: "multiline_string_quote", text: "\"\"\"", classification: "StringLiteral"),
199-
PoundKeywordSpec(name: "PoundKeyPath", kind: "pound_keyPath", text: "#keyPath"),
200-
PoundKeywordSpec(name: "PoundLine", kind: "pound_line", text: "#line"),
201-
PoundKeywordSpec(name: "PoundSelector", kind: "pound_selector", text: "#selector"),
202-
PoundKeywordSpec(name: "PoundFile", kind: "pound_file", text: "#file"),
203-
PoundKeywordSpec(name: "PoundFileID", kind: "pound_fileID", text: "#fileID"),
204-
PoundKeywordSpec(name: "PoundFilePath", kind: "pound_filePath", text: "#filePath"),
205-
PoundKeywordSpec(name: "PoundColumn", kind: "pound_column", text: "#column"),
206-
PoundKeywordSpec(name: "PoundFunction", kind: "pound_function", text: "#function"),
207-
PoundKeywordSpec(name: "PoundDsohandle", kind: "pound_dsohandle", text: "#dsohandle"),
208199
PoundKeywordSpec(name: "PoundAssert", kind: "pound_assert", text: "#assert"),
209200
PoundDirectiveKeywordSpec(name: "PoundSourceLocation", kind: "pound_sourceLocation", text: "#sourceLocation"),
210201
PoundDirectiveKeywordSpec(name: "PoundWarning", kind: "pound_warning", text: "#warning"),

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/TokenKindFile.swift

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,6 @@ let tokenKindFile = SourceFileSyntax {
3535
}
3636
}
3737

38-
InitializerDeclSyntax("""
39-
/// Initializes a keyword token kind from its string representation. If the
40-
/// given string is not a keyword, this function returns `nil`.
41-
public init?(keyword: String)
42-
""") {
43-
SwitchStmtSyntax(expression: ExprSyntax("keyword")) {
44-
for token in SYNTAX_TOKENS where token.isKeyword {
45-
SwitchCaseSyntax("case \"\(raw: token.text!)\":") {
46-
SequenceExprSyntax("self = .\(raw: token.swiftKind)")
47-
}
48-
}
49-
50-
SwitchCaseSyntax("default:") {
51-
ReturnStmtSyntax("return nil")
52-
}
53-
}
54-
}
55-
5638
VariableDeclSyntax(
5739
leadingTrivia: .docBlockComment("/// The textual representation of this token kind.") + .newlines(1),
5840
attributes: [.attribute(AttributeSyntax(attributeName: TypeSyntax("_spi"), leftParen: .leftParenToken(), argument: .token(.identifier("Testing")), rightParen: .rightParenToken()))],
@@ -392,39 +374,6 @@ let tokenKindFile = SourceFileSyntax {
392374
}
393375
}
394376
}
395-
396-
InitializerDeclSyntax("""
397-
@_spi(RawSyntax)
398-
public init?(keyword text: SyntaxText)
399-
""") {
400-
401-
let tokensByLength = Dictionary(
402-
grouping: SYNTAX_TOKENS.filter { $0.isKeyword },
403-
by: { $0.text!.count }
404-
)
405-
406-
SwitchStmtSyntax(expression: ExprSyntax("text.count")) {
407-
for len in tokensByLength.keys.sorted() {
408-
SwitchCaseSyntax("case \(raw: len):") {
409-
SwitchStmtSyntax(expression: ExprSyntax("text")) {
410-
for token in tokensByLength[len]! {
411-
SwitchCaseSyntax("case \"\(raw: token.text!)\":") {
412-
SequenceExprSyntax("self = .\(raw: token.swiftKind)")
413-
}
414-
}
415-
416-
SwitchCaseSyntax("default:") {
417-
ReturnStmtSyntax("return nil")
418-
}
419-
}
420-
}
421-
}
422-
423-
SwitchCaseSyntax("default:") {
424-
ReturnStmtSyntax("return nil")
425-
}
426-
}
427-
}
428377
}
429378

430379
ExtensionDeclSyntax("extension TokenKind") {

Sources/IDEUtils/generated/SyntaxClassification.swift

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -192,24 +192,6 @@ extension RawTokenKind {
192192
return .stringLiteral
193193
case .multilineStringQuote:
194194
return .stringLiteral
195-
case .poundKeyPathKeyword:
196-
return .keyword
197-
case .poundLineKeyword:
198-
return .keyword
199-
case .poundSelectorKeyword:
200-
return .keyword
201-
case .poundFileKeyword:
202-
return .keyword
203-
case .poundFileIDKeyword:
204-
return .keyword
205-
case .poundFilePathKeyword:
206-
return .keyword
207-
case .poundColumnKeyword:
208-
return .keyword
209-
case .poundFunctionKeyword:
210-
return .keyword
211-
case .poundDsohandleKeyword:
212-
return .keyword
213195
case .poundAssertKeyword:
214196
return .keyword
215197
case .poundSourceLocationKeyword:

Sources/SwiftBasicFormat/generated/BasicFormat.swift

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -198,24 +198,6 @@ open class BasicFormat: SyntaxRewriter {
198198
return true
199199
case .arrow:
200200
return true
201-
case .poundKeyPathKeyword:
202-
return true
203-
case .poundLineKeyword:
204-
return true
205-
case .poundSelectorKeyword:
206-
return true
207-
case .poundFileKeyword:
208-
return true
209-
case .poundFileIDKeyword:
210-
return true
211-
case .poundFilePathKeyword:
212-
return true
213-
case .poundColumnKeyword:
214-
return true
215-
case .poundFunctionKeyword:
216-
return true
217-
case .poundDsohandleKeyword:
218-
return true
219201
case .poundAssertKeyword:
220202
return true
221203
case .poundSourceLocationKeyword:

Sources/SwiftParser/Lexer/Cursor.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,9 +1846,7 @@ extension Lexer.Cursor {
18461846
self.advance(while: { $0.isValidIdentifierContinuationCodePoint })
18471847

18481848
let text = tokStart.text(upTo: self)
1849-
if let keywordKind = RawTokenKind(keyword: text) {
1850-
return Lexer.Result(keywordKind)
1851-
} else if let keyword = Keyword(text), keyword.isLexerClassified {
1849+
if let keyword = Keyword(text), keyword.isLexerClassified {
18521850
return Lexer.Result(.keyword(keyword))
18531851
} else if text == "_" {
18541852
return Lexer.Result(.wildcard)

Sources/SwiftParser/TokenPrecedence.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public enum TokenPrecedence: Comparable {
108108
case // Literals
109109
.floatingLiteral, .integerLiteral, .regexLiteral,
110110
// Pound literals
111-
.poundAvailableKeyword, .poundColorLiteralKeyword, .poundColumnKeyword, .poundDsohandleKeyword, .poundFileIDKeyword, .poundFileKeyword, .poundFileLiteralKeyword, .poundFilePathKeyword, .poundFunctionKeyword, .poundImageLiteralKeyword, .poundKeyPathKeyword, .poundLineKeyword, .poundSelectorKeyword, .poundSourceLocationKeyword, .poundUnavailableKeyword, .poundHasSymbolKeyword,
111+
.poundAvailableKeyword, .poundColorLiteralKeyword, .poundFileLiteralKeyword, .poundImageLiteralKeyword, .poundSourceLocationKeyword, .poundUnavailableKeyword, .poundHasSymbolKeyword,
112112
// Identifiers
113113
.dollarIdentifier, .identifier,
114114
// '_' can occur in types to replace a type identifier

0 commit comments

Comments
 (0)