Skip to content
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

Automatically generate leading/trailing space trivia for tokens in SyntaxFactory #473

Merged
merged 1 commit into from
Jun 27, 2022

Conversation

fwcd
Copy link
Member

@fwcd fwcd commented Jun 25, 2022

In an effort to clean up the TokensFile template in SwiftSyntaxBuilderGeneration, this branch moves the generation of leading/trailing space trivia around tokens into SyntaxFactory. In other words, calls like

SyntaxFactory.makeSwitchKeyword()

will now automatically generate a trailing space (although this is still overridable by explicitly passing trailingTrivia: [] as a parameter).

cc @ahoppen

@kimdv
Copy link
Contributor

kimdv commented Jun 25, 2022

@swift-ci please test

Copy link
Member Author

@fwcd fwcd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few notes on the implementation below. The open keyword also still needs an explicit trailing trivia call (in TokensFile.swift:100) since contextual keywords as generated in makeContextualKeyword apparently do not require a trailing space.

Tests/SwiftSyntaxBuilderTest/VariableTests.swift Outdated Show resolved Hide resolved
@fwcd fwcd marked this pull request as ready for review June 25, 2022 15:43
@fwcd fwcd requested a review from ahoppen as a code owner June 25, 2022 15:43
@fwcd
Copy link
Member Author

fwcd commented Jun 25, 2022

@swift-ci please test

@fwcd fwcd force-pushed the auto-token-trivia branch from aa6b163 to 5a961ef Compare June 26, 2022 02:28
@fwcd
Copy link
Member Author

fwcd commented Jun 26, 2022

@swift-ci please test

1 similar comment
@fwcd
Copy link
Member Author

fwcd commented Jun 26, 2022

@swift-ci please test

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, this is so much simpler than what we had before 😍

Additionally, remove redundant trivia generation from TokensFile and no
longer needed leading/trailing space info from Tokens in
SwiftSyntaxBuilderGeneration. Since SyntaxFactory now takes care of
leading/trailing spaces, we no longer need these helpers (that were
previously required by the TokensFile template).
@fwcd fwcd force-pushed the auto-token-trivia branch from b9d548c to 94c6970 Compare June 27, 2022 12:46
@fwcd
Copy link
Member Author

fwcd commented Jun 27, 2022

@swift-ci please test

@fwcd fwcd merged commit 518f1d2 into swiftlang:main Jun 27, 2022
@fwcd fwcd deleted the auto-token-trivia branch June 27, 2022 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants