Skip to content

Conversation

@allevato
Copy link
Member

@allevato allevato commented Nov 2, 2022

This is something that I've wanted to have during development, especially when manipulating trivia in swift-format.


Manually tested example:

$ swift-parser-cli print-tree --include-trivia <<'EOF'
heredoc> /*xyz*/ func foo() {  // blah
heredoc>   }
heredoc> EOF

SourceFileSyntax children=2
  0: CodeBlockItemListSyntax children=1
    0: CodeBlockItemSyntax children=1
      0: FunctionDeclSyntax children=4
        0: funcKeyword leadingTrivia=[blockComment("/*xyz*/"), spaces(1)] trailingTrivia=spaces(1)
        1: identifier("foo")
        2: FunctionSignatureSyntax children=1
          0: ParameterClauseSyntax children=3
            0: leftParen
            1: FunctionParameterListSyntax
            2: rightParen trailingTrivia=spaces(1)
        3: CodeBlockSyntax children=3
          0: leftBrace trailingTrivia=[spaces(2), lineComment("// blah")]
          1: CodeBlockItemListSyntax
          2: rightBrace leadingTrivia=[newlines(1), spaces(2)]
  1: eof leadingTrivia=newlines(1)

This is something that I've wanted to have during development,
especially when manipulating trivia in swift-format.
@allevato allevato requested a review from CodaFi November 2, 2022 16:22
@allevato allevato requested a review from ahoppen as a code owner November 2, 2022 16:22
@allevato
Copy link
Member Author

allevato commented Nov 2, 2022

@swift-ci please test

@allevato allevato merged commit 0a67557 into swiftlang:main Nov 2, 2022
@allevato allevato deleted the print-trivia branch November 2, 2022 19:37
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.

2 participants