Skip to content

Remove pound keywords token kinds #1267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,6 @@ public let SYNTAX_TOKENS: [TokenSpec] = [
PunctuatorSpec(name: "StringQuote", kind: "string_quote", text: "\"", classification: "StringLiteral"),
PunctuatorSpec(name: "SingleQuote", kind: "single_quote", text: "\'", classification: "StringLiteral"),
PunctuatorSpec(name: "MultilineStringQuote", kind: "multiline_string_quote", text: "\"\"\"", classification: "StringLiteral"),
PoundKeywordSpec(name: "PoundKeyPath", kind: "pound_keyPath", text: "#keyPath"),
PoundKeywordSpec(name: "PoundLine", kind: "pound_line", text: "#line"),
PoundKeywordSpec(name: "PoundSelector", kind: "pound_selector", text: "#selector"),
PoundKeywordSpec(name: "PoundFile", kind: "pound_file", text: "#file"),
PoundKeywordSpec(name: "PoundFileID", kind: "pound_fileID", text: "#fileID"),
PoundKeywordSpec(name: "PoundFilePath", kind: "pound_filePath", text: "#filePath"),
PoundKeywordSpec(name: "PoundColumn", kind: "pound_column", text: "#column"),
PoundKeywordSpec(name: "PoundFunction", kind: "pound_function", text: "#function"),
PoundKeywordSpec(name: "PoundDsohandle", kind: "pound_dsohandle", text: "#dsohandle"),
PoundKeywordSpec(name: "PoundAssert", kind: "pound_assert", text: "#assert"),
PoundDirectiveKeywordSpec(name: "PoundSourceLocation", kind: "pound_sourceLocation", text: "#sourceLocation"),
PoundDirectiveKeywordSpec(name: "PoundWarning", kind: "pound_warning", text: "#warning"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,6 @@ let tokenKindFile = SourceFileSyntax {
}
}

InitializerDeclSyntax("""
/// Initializes a keyword token kind from its string representation. If the
/// given string is not a keyword, this function returns `nil`.
public init?(keyword: String)
""") {
SwitchStmtSyntax(expression: ExprSyntax("keyword")) {
for token in SYNTAX_TOKENS where token.isKeyword {
SwitchCaseSyntax("case \"\(raw: token.text!)\":") {
SequenceExprSyntax("self = .\(raw: token.swiftKind)")
}
}

SwitchCaseSyntax("default:") {
ReturnStmtSyntax("return nil")
}
}
}

VariableDeclSyntax(
leadingTrivia: .docBlockComment("/// The textual representation of this token kind.") + .newlines(1),
attributes: [.attribute(AttributeSyntax(attributeName: TypeSyntax("_spi"), leftParen: .leftParenToken(), argument: .token(.identifier("Testing")), rightParen: .rightParenToken()))],
Expand Down Expand Up @@ -392,39 +374,6 @@ let tokenKindFile = SourceFileSyntax {
}
}
}

InitializerDeclSyntax("""
@_spi(RawSyntax)
public init?(keyword text: SyntaxText)
""") {

let tokensByLength = Dictionary(
grouping: SYNTAX_TOKENS.filter { $0.isKeyword },
by: { $0.text!.count }
)

SwitchStmtSyntax(expression: ExprSyntax("text.count")) {
for len in tokensByLength.keys.sorted() {
SwitchCaseSyntax("case \(raw: len):") {
SwitchStmtSyntax(expression: ExprSyntax("text")) {
for token in tokensByLength[len]! {
SwitchCaseSyntax("case \"\(raw: token.text!)\":") {
SequenceExprSyntax("self = .\(raw: token.swiftKind)")
}
}

SwitchCaseSyntax("default:") {
ReturnStmtSyntax("return nil")
}
}
}
}

SwitchCaseSyntax("default:") {
ReturnStmtSyntax("return nil")
}
}
}
}

ExtensionDeclSyntax("extension TokenKind") {
Expand Down
18 changes: 0 additions & 18 deletions Sources/IDEUtils/generated/SyntaxClassification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,24 +192,6 @@ extension RawTokenKind {
return .stringLiteral
case .multilineStringQuote:
return .stringLiteral
case .poundKeyPathKeyword:
return .keyword
case .poundLineKeyword:
return .keyword
case .poundSelectorKeyword:
return .keyword
case .poundFileKeyword:
return .keyword
case .poundFileIDKeyword:
return .keyword
case .poundFilePathKeyword:
return .keyword
case .poundColumnKeyword:
return .keyword
case .poundFunctionKeyword:
return .keyword
case .poundDsohandleKeyword:
return .keyword
case .poundAssertKeyword:
return .keyword
case .poundSourceLocationKeyword:
Expand Down
18 changes: 0 additions & 18 deletions Sources/SwiftBasicFormat/generated/BasicFormat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,24 +198,6 @@ open class BasicFormat: SyntaxRewriter {
return true
case .arrow:
return true
case .poundKeyPathKeyword:
return true
case .poundLineKeyword:
return true
case .poundSelectorKeyword:
return true
case .poundFileKeyword:
return true
case .poundFileIDKeyword:
return true
case .poundFilePathKeyword:
return true
case .poundColumnKeyword:
return true
case .poundFunctionKeyword:
return true
case .poundDsohandleKeyword:
return true
case .poundAssertKeyword:
return true
case .poundSourceLocationKeyword:
Expand Down
4 changes: 1 addition & 3 deletions Sources/SwiftParser/Lexer/Cursor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1838,9 +1838,7 @@ extension Lexer.Cursor {
self.advance(while: { $0.isValidIdentifierContinuationCodePoint })

let text = tokStart.text(upTo: self)
if let keywordKind = RawTokenKind(keyword: text) {
return Lexer.Result(keywordKind)
} else if let keyword = Keyword(text), keyword.isLexerClassified {
if let keyword = Keyword(text), keyword.isLexerClassified {
return Lexer.Result(.keyword(keyword))
} else if text == "_" {
return Lexer.Result(.wildcard)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftParser/TokenPrecedence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public enum TokenPrecedence: Comparable {
case // Literals
.floatingLiteral, .integerLiteral, .regexLiteral,
// Pound literals
.poundAvailableKeyword, .poundColorLiteralKeyword, .poundColumnKeyword, .poundDsohandleKeyword, .poundFileIDKeyword, .poundFileKeyword, .poundFileLiteralKeyword, .poundFilePathKeyword, .poundFunctionKeyword, .poundImageLiteralKeyword, .poundKeyPathKeyword, .poundLineKeyword, .poundSelectorKeyword, .poundSourceLocationKeyword, .poundUnavailableKeyword, .poundHasSymbolKeyword,
.poundAvailableKeyword, .poundColorLiteralKeyword, .poundFileLiteralKeyword, .poundImageLiteralKeyword, .poundSourceLocationKeyword, .poundUnavailableKeyword, .poundHasSymbolKeyword,
// Identifiers
.dollarIdentifier, .identifier,
// '_' can occur in types to replace a type identifier
Expand Down
Loading