Skip to content

Commit f8b1562

Browse files
committed
Mark original eof interfaces as deprecated, and clean up some code
1 parent 1dadd6a commit f8b1562

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

CodeGeneration/Sources/SyntaxSupport/TokenSpec.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ public let SYNTAX_TOKENS: [TokenSpec] = [
183183
PunctuatorSpec(name: "Comma", kind: "comma", text: ",", requiresTrailingSpace: true),
184184
MiscSpec(name: "DollarIdentifier", kind: "dollarident", nameForDiagnostics: "dollar identifier", classification: "DollarIdentifier"),
185185
PunctuatorSpec(name: "Ellipsis", kind: "ellipsis", text: "..."),
186+
MiscSpec(name: "EndOfFile", kind: "eof", nameForDiagnostics: "end of file", text: ""),
186187
PunctuatorSpec(name: "Equal", kind: "equal", text: "=", requiresLeadingSpace: true, requiresTrailingSpace: true),
187188
PunctuatorSpec(name: "ExclamationMark", kind: "exclaim_postfix", text: "!"),
188189
MiscSpec(name: "ExtendedRegexDelimiter", kind: "extended_regex_delimiter", nameForDiagnostics: "extended delimiter", classification: "RegexLiteral"),
@@ -222,7 +223,6 @@ public let SYNTAX_TOKENS: [TokenSpec] = [
222223
MiscSpec(name: "StringSegment", kind: "string_segment", nameForDiagnostics: "string segment", classification: "StringLiteral"),
223224
MiscSpec(name: "Unknown", kind: "unknown", nameForDiagnostics: "token"),
224225
MiscSpec(name: "Wildcard", kind: "_", nameForDiagnostics: "wildcard", text: "_"),
225-
MiscSpec(name: "EndOfFile", kind: "eof", nameForDiagnostics: "end of file", text: "")
226226
]
227227

228228
public let SYNTAX_TOKEN_MAP = Dictionary(

Sources/SwiftParser/TokenPrecedence.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ enum TokenPrecedence: Comparable {
169169
.semicolon,
170170
// Arrow is a strong indicator in a function type that we are now in the return type
171171
.arrow,
172-
// EOF is here because it is a very stong marker and doesn't belong anywhere else
172+
// `endOfFile` is here because it is a very stong marker and doesn't belong anywhere else
173173
.endOfFile:
174174
self = .strongPunctuator
175175

Sources/SwiftParser/TopLevel.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ extension Parser {
4646
/// source-file → top-level-declaration?
4747
mutating func parseSourceFile() -> RawSourceFileSyntax {
4848
let items = self.parseTopLevelCodeBlockItems()
49-
let unexpectedBeforeEof = consumeRemainingTokens()
50-
let eof = self.consume(if: .endOfFile)!
49+
let unexpectedBeforeEndOfFileToken = consumeRemainingTokens()
50+
let endOfFile = self.consume(if: .endOfFile)!
5151
return .init(
5252
statements: items,
53-
RawUnexpectedNodesSyntax(unexpectedBeforeEof, arena: self.arena),
54-
endOfFileToken: eof,
53+
RawUnexpectedNodesSyntax(unexpectedBeforeEndOfFileToken, arena: self.arena),
54+
endOfFileToken: endOfFile,
5555
arena: self.arena
5656
)
5757
}

Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public extension TokenKind {
5151
static var rightSquareBracket: TokenKind {
5252
return .rightSquare
5353
}
54+
55+
@available(*, deprecated, renamed: "endOfFile")
56+
static var eof: TokenKind { .endOfFile }
5457
}
5558

5659
public extension TokenSyntax {
@@ -79,6 +82,19 @@ public extension TokenSyntax {
7982
presence: presence
8083
)
8184
}
85+
86+
@available(*, deprecated, renamed: "endOfFileToken")
87+
static func eof(
88+
leadingTrivia: Trivia = [],
89+
trailingTrivia: Trivia = [],
90+
presence: SourcePresence = .present
91+
) -> TokenSyntax {
92+
return .endOfFileToken(
93+
leadingTrivia: leadingTrivia,
94+
trailingTrivia: trailingTrivia,
95+
presence: presence
96+
)
97+
}
8298
}
8399

84100
//==========================================================================//

0 commit comments

Comments
 (0)