Skip to content

Commit 956687e

Browse files
committed
Remove References to Unknown Syntax
The new Swift parser in SwiftSyntax does not ever construct Unknown*Syntax nodes. These are a relic of the C++, which would use these nodes as stand-ins for cases where the legacy parser did not known how to build a node, or built one incorrectly. Simultaneously, the formatter was relying on unknown nodes containing verbatim text it would leave untouched. The general replacement for that case is UnexpectedSyntax. Drop the Unknown*Syntax entrypoints in the visitors, and replace refernces to "unknown syntax" with "unexpected syntax". See also swiftlang#1131
1 parent 7e8bd26 commit 956687e

File tree

2 files changed

+3
-33
lines changed

2 files changed

+3
-33
lines changed

Documentation/PrettyPrinter.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,15 @@ Tokens = [docBlock(" Doc Block comment\n * Second line *")]
233233
Verbatim tokens are used to print text verbatim without any formatting apart
234234
from applying a global indentation. They have a length set to the maximum line
235235
width. They are typically used to handle syntax types that are classed as
236-
"unknown" by SwiftSyntax. In these cases, we don't have access to the
236+
"unexpected" by SwiftSyntax. In these cases, we don't have access to the
237237
substructure of the syntax node a manner useful for formatting, so we print them
238238
verbatim. The indentation for verbatim tokens is applied to the first line of
239239
the text. The relative indentation of subsequent lines is preserved unless they
240240
have less indentation than the first line, in which case we set the indentation
241241
of those lines equal to the first.
242242

243243
```
244-
// Consider "ifnt", an unknown syntax structure:
244+
// Consider "ifnt", an unexpected syntax structure:
245245
246246
if someCondition {
247247
ifnt anotherCondition {

Sources/SwiftFormatPrettyPrint/TokenStreamCreator.swift

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,43 +2411,13 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
24112411
return .visitChildren
24122412
}
24132413

2414-
// MARK: - Nodes representing unknown or malformed syntax
2414+
// MARK: - Nodes representing unexpected or malformed syntax
24152415

24162416
override func visit(_ node: UnexpectedNodesSyntax) -> SyntaxVisitorContinueKind {
24172417
verbatimToken(Syntax(node))
24182418
return .skipChildren
24192419
}
24202420

2421-
override func visit(_ node: UnknownDeclSyntax) -> SyntaxVisitorContinueKind {
2422-
verbatimToken(Syntax(node))
2423-
return .skipChildren
2424-
}
2425-
2426-
override func visit(_ node: UnknownExprSyntax) -> SyntaxVisitorContinueKind {
2427-
verbatimToken(Syntax(node))
2428-
return .skipChildren
2429-
}
2430-
2431-
override func visit(_ node: UnknownPatternSyntax) -> SyntaxVisitorContinueKind {
2432-
verbatimToken(Syntax(node))
2433-
return .skipChildren
2434-
}
2435-
2436-
override func visit(_ node: UnknownStmtSyntax) -> SyntaxVisitorContinueKind {
2437-
verbatimToken(Syntax(node))
2438-
return .skipChildren
2439-
}
2440-
2441-
override func visit(_ node: UnknownSyntax) -> SyntaxVisitorContinueKind {
2442-
verbatimToken(Syntax(node))
2443-
return .skipChildren
2444-
}
2445-
2446-
override func visit(_ node: UnknownTypeSyntax) -> SyntaxVisitorContinueKind {
2447-
verbatimToken(Syntax(node))
2448-
return .skipChildren
2449-
}
2450-
24512421
override func visit(_ node: NonEmptyTokenListSyntax) -> SyntaxVisitorContinueKind {
24522422
verbatimToken(Syntax(node))
24532423
return .skipChildren

0 commit comments

Comments
 (0)