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
[SR-9616] SwiftSyntax is not following trivia rule #438
Comments
I agree this is a bug. https://github.com/apple/swift/blob/75033ed05a8f5ecf79e77b41dabd2c3863cbc9e5/lib/Parse/Lexer.cpp#L2560 https://bugs.swift.org/browse/SR-2373 Lexing trailing-comment as |
This example inamiy (JIRA User) gave here is an obvious bug since the comments are in different forms ("//" and "///"), so it's reasonable to assume they're If they are both "///", i have no strong opinion on whether we split them as trailing and leading trivia or combine them as leading trivia, because the lexer cannot |
Comment by Yasuhiro Inami (JIRA)
I think trailing and leading trivias should be separated in the above case too, and it's probably possible to distinguish them by checking if token exists in the same line or not. If this can be done, it's exciting to see SR-2373 trailing-doc support can be implemented as well 🙂 |
rdar://95639215 |
…s separated by a newline This changes the trivia attribution rule in the new parser to consider all trivia up to the next newline as trailing trivia. Previously, comments were always considered trailing trivia. This was discussed last year in https://forums.swift.org/t/changing-comment-trivia-attribution-from-trailing-trivia-to-leading-trivia/50773. My idea is that right now is probably one of the best times to change this because switching from the old to the new parser is an active source change for all clients. Resolves rdar://68234477 Resolves rdar://95639215 Fixes apple#438
…s separated by a newline This changes the trivia attribution rule in the new parser to consider all trivia up to the next newline as trailing trivia. Previously, comments were always considered trailing trivia. This was discussed last year in https://forums.swift.org/t/changing-comment-trivia-attribution-from-trailing-trivia-to-leading-trivia/50773. My idea is that right now is probably one of the best times to change this because switching from the old to the new parser is an active source change for all clients. Resolves rdar://68234477 Resolves rdar://95639215 Fixes apple#438
Add support in build-script-helper.py to install swift-format into an open source toolchain
Attachment: Download
Environment
Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1)
SwiftSyntax 0.40200.0
Additional Detail from JIRA
md5: b19e5c1a45f2ad0872b99a66f9211c27
relates to:
Issue Description:
According to the libSyntax documentation:
The following code should have leading / trailing trivias as follows:
But actually, both comments are bundled as `var`'s leading trivia.
You can test the code at https://swift-ast-explorer.kishikawakatsumi.com/ (screenshot attached).
By the way, in TypeScript, it seems to work as is:
https://github.com/basarat/typescript-book/blob/master/docs/compiler/ast-trivia.md
The text was updated successfully, but these errors were encountered: