Uploaded image for project: 'Swift'
  1. Swift
  2. SR-9616

SwiftSyntax is not following trivia rule

    XMLWordPrintable

    Details

      Description

      According to the libSyntax documentation:

      1. A token owns all of its trailing trivia up to, but not including, the next newline character.
      2. Looking backward in the text, a token owns all of the leading trivia up to and including the first contiguous sequence of newlines characters.

      The following code should have leading / trailing trivias as follows:

      let x = 1 // This should be "1"'s trailing trivia
      /// This should be `var`'s leading trivia
      var y = 2
      

      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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              inamiy Yasuhiro Inami
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated: