Skip to content

Remove parsing, token, and syntax nodes for # things subsumed by macros #1284

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 14 commits into from
Jan 27, 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 @@ -213,58 +213,6 @@ public let DECL_NODES: [Node] = [
classification: "BuildConfigId")
]),

Node(name: "PoundErrorDecl",
nameForDiagnostics: "'#error' directive",
kind: "Decl",
traits: [
"Parenthesized"
],
children: [
Child(name: "PoundError",
kind: "PoundErrorToken",
tokenChoices: [
"PoundError"
]),
Child(name: "LeftParen",
kind: "LeftParenToken",
tokenChoices: [
"LeftParen"
]),
Child(name: "Message",
kind: "StringLiteralExpr"),
Child(name: "RightParen",
kind: "RightParenToken",
tokenChoices: [
"RightParen"
])
]),

Node(name: "PoundWarningDecl",
nameForDiagnostics: "'#warning' directive",
kind: "Decl",
traits: [
"Parenthesized"
],
children: [
Child(name: "PoundWarning",
kind: "PoundWarningToken",
tokenChoices: [
"PoundWarning"
]),
Child(name: "LeftParen",
kind: "LeftParenToken",
tokenChoices: [
"LeftParen"
]),
Child(name: "Message",
kind: "StringLiteralExpr"),
Child(name: "RightParen",
kind: "RightParenToken",
tokenChoices: [
"RightParen"
])
]),

Node(name: "PoundSourceLocation",
nameForDiagnostics: "'#sourceLocation' directive",
kind: "Decl",
Expand Down Expand Up @@ -1600,7 +1548,7 @@ public let DECL_NODES: [Node] = [
]),

Node(name: "MacroExpansionDecl",
nameForDiagnostics: "pound literal declaration",
nameForDiagnostics: "macro expansion",
kind: "Decl",
traits: [
"FreestandingMacroExpansion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ public let EXPR_NODES: [Node] = [
]),

Node(name: "MacroExpansionExpr",
nameForDiagnostics: "pound literal expression",
nameForDiagnostics: "macro expansion expression",
kind: "Expr",
traits: [
"FreestandingMacroExpansion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,7 @@ public let STMT_NODES: [Node] = [
Child(name: "MatchingPattern",
kind: "MatchingPatternCondition"),
Child(name: "OptionalBinding",
kind: "OptionalBindingCondition"),
Child(name: "HasSymbol",
kind: "HasSymbolCondition")
kind: "OptionalBindingCondition")
]),
Child(name: "TrailingComma",
kind: "CommaToken",
Expand Down Expand Up @@ -489,26 +487,6 @@ public let STMT_NODES: [Node] = [
isOptional: true)
]),

Node(name: "HasSymbolCondition",
nameForDiagnostics: "'#_hasSymbol' condition",
kind: "Syntax",
children: [
Child(name: "HasSymbolKeyword",
kind: "HasSymbolToken"),
Child(name: "LeftParen",
kind: "LeftParenToken",
tokenChoices: [
"LeftParen"
]),
Child(name: "Expression",
kind: "Expr"),
Child(name: "RightParen",
kind: "RightParenToken",
tokenChoices: [
"RightParen"
])
]),

Node(name: "ConditionElementList",
nameForDiagnostics: nil,
kind: "SyntaxCollection",
Expand Down Expand Up @@ -695,39 +673,4 @@ public let STMT_NODES: [Node] = [
kind: "CodeBlock")
]),

Node(name: "PoundAssertStmt",
nameForDiagnostics: "'#assert' directive",
kind: "Stmt",
children: [
Child(name: "PoundAssert",
kind: "PoundAssertToken",
tokenChoices: [
"PoundAssert"
]),
Child(name: "LeftParen",
kind: "LeftParenToken",
tokenChoices: [
"LeftParen"
]),
Child(name: "Condition",
kind: "Expr",
description: "The assertion condition."),
Child(name: "Comma",
kind: "CommaToken",
description: "The comma after the assertion condition.",
isOptional: true,
tokenChoices: [
"Comma"
]),
Child(name: "Message",
kind: "StringLiteralExpr",
description: "The assertion message.",
isOptional: true),
Child(name: "RightParen",
kind: "RightParenToken",
tokenChoices: [
"RightParen"
])
]),

]
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,13 @@ 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: "PoundAssert", kind: "pound_assert", text: "#assert"),
PoundDirectiveKeywordSpec(name: "PoundSourceLocation", kind: "pound_sourceLocation", text: "#sourceLocation"),
PoundDirectiveKeywordSpec(name: "PoundWarning", kind: "pound_warning", text: "#warning"),
PoundDirectiveKeywordSpec(name: "PoundError", kind: "pound_error", text: "#error"),
PoundConditionalDirectiveKeywordSpec(name: "PoundIf", kind: "pound_if", text: "#if"),
PoundConditionalDirectiveKeywordSpec(name: "PoundElse", kind: "pound_else", text: "#else"),
PoundConditionalDirectiveKeywordSpec(name: "PoundElseif", kind: "pound_elseif", text: "#elseif"),
PoundConditionalDirectiveKeywordSpec(name: "PoundEndif", kind: "pound_endif", text: "#endif"),
PoundConfigSpec(name: "PoundAvailable", kind: "pound_available", text: "#available"),
PoundConfigSpec(name: "PoundUnavailable", kind: "pound_unavailable", text: "#unavailable"),
PoundObjectLiteralSpec(name: "PoundFileLiteral", kind: "pound_fileLiteral", text: "#fileLiteral", nameForDiagnostics: "file reference", protocol: "ExpressibleByFileReferenceLiteral"),
PoundObjectLiteralSpec(name: "PoundImageLiteral", kind: "pound_imageLiteral", text: "#imageLiteral", nameForDiagnostics: "image", protocol: "ExpressibleByImageLiteral"),
PoundObjectLiteralSpec(name: "PoundColorLiteral", kind: "pound_colorLiteral", text: "#colorLiteral", nameForDiagnostics: "color", protocol: "ExpressibleByColorLiteral"),
PoundConfigSpec(name: "PoundHasSymbol", kind: "pound__hasSymbol", text: "#_hasSymbol"),
LiteralSpec(name: "IntegerLiteral", kind: "integer_literal", nameForDiagnostics: "integer literal", classification: "IntegerLiteral"),
LiteralSpec(name: "FloatingLiteral", kind: "floating_literal", nameForDiagnostics: "floating literal", classification: "FloatingLiteral"),
LiteralSpec(name: "RegexLiteral", kind: "regex_literal", nameForDiagnostics: "regex literal"),
Expand Down
14 changes: 0 additions & 14 deletions Sources/IDEUtils/generated/SyntaxClassification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,8 @@ extension RawTokenKind {
return .stringLiteral
case .multilineStringQuote:
return .stringLiteral
case .poundAssertKeyword:
return .keyword
case .poundSourceLocationKeyword:
return .poundDirectiveKeyword
case .poundWarningKeyword:
return .poundDirectiveKeyword
case .poundErrorKeyword:
return .poundDirectiveKeyword
case .poundIfKeyword:
return .poundDirectiveKeyword
case .poundElseKeyword:
Expand All @@ -212,14 +206,6 @@ extension RawTokenKind {
return .keyword
case .poundUnavailableKeyword:
return .keyword
case .poundFileLiteralKeyword:
return .objectLiteral
case .poundImageLiteralKeyword:
return .objectLiteral
case .poundColorLiteralKeyword:
return .objectLiteral
case .poundHasSymbolKeyword:
return .keyword
case .integerLiteral:
return .integerLiteral
case .floatingLiteral:
Expand Down
14 changes: 0 additions & 14 deletions Sources/SwiftBasicFormat/generated/BasicFormat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,8 @@ open class BasicFormat: SyntaxRewriter {
return true
case .arrow:
return true
case .poundAssertKeyword:
return true
case .poundSourceLocationKeyword:
return true
case .poundWarningKeyword:
return true
case .poundErrorKeyword:
return true
case .poundIfKeyword:
return true
case .poundElseKeyword:
Expand All @@ -218,14 +212,6 @@ open class BasicFormat: SyntaxRewriter {
return true
case .poundUnavailableKeyword:
return true
case .poundFileLiteralKeyword:
return true
case .poundImageLiteralKeyword:
return true
case .poundColorLiteralKeyword:
return true
case .poundHasSymbolKeyword:
return true
case .binaryOperator:
return true
case .keyword(.`Any`):
Expand Down
72 changes: 0 additions & 72 deletions Sources/SwiftParser/Declarations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,6 @@ extension Parser {
return .decls(RawMemberDeclListSyntax(elements: elements, arena: parser.arena))
}
return RawDeclSyntax(directive)
case (.poundWarningKeyword, _)?, (.poundErrorKeyword, _)?:
return self.parsePoundDiagnosticDeclaration()
case (.pound, _)?:
// FIXME: If we can have attributes for macro expansions, handle this
// via DeclarationStart.
Expand Down Expand Up @@ -2062,76 +2060,6 @@ extension Parser {
}

extension Parser {
enum PoundDiagnosticKind {
case error(poundError: RawTokenSyntax)
case warning(poundWarning: RawTokenSyntax)
}

@_spi(RawSyntax)
public mutating func parsePoundDiagnosticDeclaration() -> RawDeclSyntax {
enum ExpectedTokenKind: RawTokenKindSubset {
case poundErrorKeyword
case poundWarningKeyword

init?(lexeme: Lexer.Lexeme) {
switch lexeme.rawTokenKind {
case .poundErrorKeyword: self = .poundErrorKeyword
case .poundWarningKeyword: self = .poundWarningKeyword
default: return nil
}
}

var rawTokenKind: RawTokenKind {
switch self {
case .poundErrorKeyword: return .poundErrorKeyword
case .poundWarningKeyword: return .poundWarningKeyword
}
}
}

let directive: PoundDiagnosticKind

switch self.at(anyIn: ExpectedTokenKind.self) {
case (.poundErrorKeyword, let handle)?:
directive = .error(poundError: self.eat(handle))
case (.poundWarningKeyword, let handle)?:
directive = .warning(poundWarning: self.eat(handle))
case nil:
directive = .error(poundError: RawTokenSyntax(missing: .poundErrorKeyword, arena: self.arena))
}

let (unexpectedBeforeLeftParen, leftParen) = self.expect(.leftParen)
let stringLiteral = self.parseStringLiteral()
let (unexpectedBeforeRightParen, rightParen) = self.expect(.rightParen)

switch directive {
case .error(let tok):
return RawDeclSyntax(
RawPoundErrorDeclSyntax(
poundError: tok,
unexpectedBeforeLeftParen,
leftParen: leftParen,
message: stringLiteral,
unexpectedBeforeRightParen,
rightParen: rightParen,
arena: self.arena
)
)
case .warning(let tok):
return RawDeclSyntax(
RawPoundWarningDeclSyntax(
poundWarning: tok,
unexpectedBeforeLeftParen,
leftParen: leftParen,
message: stringLiteral,
unexpectedBeforeRightParen,
rightParen: rightParen,
arena: self.arena
)
)
}
}

/// Parse a macro declaration.
mutating func parseMacroDeclaration(
attrs: DeclAttributes,
Expand Down
4 changes: 0 additions & 4 deletions Sources/SwiftParser/Lexer/Cursor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1458,17 +1458,13 @@ extension Lexer.Cursor {

let kind: RawTokenKind
switch literal {
case "assert": kind = .poundAssertKeyword
case "sourceLocation": kind = .poundSourceLocationKeyword
case "warning": kind = .poundWarningKeyword
case "error": kind = .poundErrorKeyword
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 "_hasSymbol": kind = .poundHasSymbolKeyword
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
Expand Down
9 changes: 0 additions & 9 deletions Sources/SwiftParser/RawTokenKindSubset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ enum CanBeStatementStart: RawTokenKindSubset {
case forKeyword
case guardKeyword
case ifKeyword
case poundAssertKeyword
case repeatKeyword
case returnKeyword
case switchKeyword
Expand All @@ -122,7 +121,6 @@ enum CanBeStatementStart: RawTokenKindSubset {
case RawTokenKindMatch(.for): self = .forKeyword
case RawTokenKindMatch(.guard): self = .guardKeyword
case RawTokenKindMatch(.if): self = .ifKeyword
case RawTokenKindMatch(.poundAssertKeyword): self = .poundAssertKeyword
case RawTokenKindMatch(.repeat): self = .repeatKeyword
case RawTokenKindMatch(.return): self = .returnKeyword
case RawTokenKindMatch(.switch): self = .switchKeyword
Expand All @@ -143,7 +141,6 @@ enum CanBeStatementStart: RawTokenKindSubset {
case .forKeyword: return .keyword(.for)
case .guardKeyword: return .keyword(.guard)
case .ifKeyword: return .keyword(.if)
case .poundAssertKeyword: return .poundAssertKeyword
case .repeatKeyword: return .keyword(.repeat)
case .returnKeyword: return .keyword(.return)
case .switchKeyword: return .keyword(.switch)
Expand Down Expand Up @@ -474,15 +471,11 @@ enum OperatorLike: RawTokenKindSubset {

enum PoundDeclarationStart: RawTokenKindSubset {
case poundIfKeyword
case poundWarningKeyword
case poundErrorKeyword
case pound

init?(lexeme: Lexer.Lexeme) {
switch lexeme.rawTokenKind {
case .poundIfKeyword: self = .poundIfKeyword
case .poundWarningKeyword: self = .poundWarningKeyword
case .poundErrorKeyword: self = .poundErrorKeyword
case .pound: self = .pound
default: return nil
}
Expand All @@ -491,8 +484,6 @@ enum PoundDeclarationStart: RawTokenKindSubset {
var rawTokenKind: RawTokenKind {
switch self {
case .poundIfKeyword: return .poundIfKeyword
case .poundWarningKeyword: return .poundWarningKeyword
case .poundErrorKeyword: return .poundErrorKeyword
case .pound: return .pound
}
}
Expand Down
Loading