Skip to content

Remove References to Unknown Syntax #454

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
Dec 12, 2022
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
4 changes: 2 additions & 2 deletions Documentation/PrettyPrinter.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,15 @@ Tokens = [docBlock(" Doc Block comment\n * Second line *")]
Verbatim tokens are used to print text verbatim without any formatting apart
from applying a global indentation. They have a length set to the maximum line
width. They are typically used to handle syntax types that are classed as
"unknown" by SwiftSyntax. In these cases, we don't have access to the
"unexpected" by SwiftSyntax. In these cases, we don't have access to the
substructure of the syntax node a manner useful for formatting, so we print them
verbatim. The indentation for verbatim tokens is applied to the first line of
the text. The relative indentation of subsequent lines is preserved unless they
have less indentation than the first line, in which case we set the indentation
of those lines equal to the first.

```
// Consider "ifnt", an unknown syntax structure:
// Consider "ifnt", an unexpected syntax structure:

if someCondition {
ifnt anotherCondition {
Expand Down
32 changes: 1 addition & 31 deletions Sources/SwiftFormatPrettyPrint/TokenStreamCreator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2411,43 +2411,13 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
return .visitChildren
}

// MARK: - Nodes representing unknown or malformed syntax
// MARK: - Nodes representing unexpected or malformed syntax

override func visit(_ node: UnexpectedNodesSyntax) -> SyntaxVisitorContinueKind {
verbatimToken(Syntax(node))
return .skipChildren
}

override func visit(_ node: UnknownDeclSyntax) -> SyntaxVisitorContinueKind {
verbatimToken(Syntax(node))
return .skipChildren
}

override func visit(_ node: UnknownExprSyntax) -> SyntaxVisitorContinueKind {
verbatimToken(Syntax(node))
return .skipChildren
}

override func visit(_ node: UnknownPatternSyntax) -> SyntaxVisitorContinueKind {
verbatimToken(Syntax(node))
return .skipChildren
}

override func visit(_ node: UnknownStmtSyntax) -> SyntaxVisitorContinueKind {
verbatimToken(Syntax(node))
return .skipChildren
}

override func visit(_ node: UnknownSyntax) -> SyntaxVisitorContinueKind {
verbatimToken(Syntax(node))
return .skipChildren
}

override func visit(_ node: UnknownTypeSyntax) -> SyntaxVisitorContinueKind {
verbatimToken(Syntax(node))
return .skipChildren
}

override func visit(_ node: NonEmptyTokenListSyntax) -> SyntaxVisitorContinueKind {
verbatimToken(Syntax(node))
return .skipChildren
Expand Down