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

Raw strings literal is eliminated in StringInterpolationExpr

    XMLWordPrintable

    Details

      Description

      Overview

      It seems like that `StringInterpolationExpr` doesn't have syntax info of raw strings literal(#). Is this expected behavior? If so, formatter/rewriter tools might have an issue because generated swift code from libSyntax/SwiftSyntax would be a bit different from input swift code.

       

      Examples

      As you can see below example, raw strings literal `#` is eliminated in syntax tree.

       

      // sample.swift
      #"foo \#(bar)"#
      

        

      // swift -frontend -emit-syntax sample.swift
      {"id":18,"kind":"SourceFile","layout":[{"id":17,"kind":"CodeBlockItemList","layout":[{"id":14,"kind":"CodeBlockItem","layout":[{"id":13,"kind":"StringInterpolationExpr","layout":[{"id":1,"tokenKind":{"kind":"string_quote"},"leadingTrivia":[],"trailingTrivia":[],"presence":"Present"},{"id":12,"kind":"StringInterpolationSegments","layout":[{"id":3,"kind":"StringSegment","layout":[{"id":2,"tokenKind":{"kind":"string_segment","text":"foo "},"leadingTrivia":[],"trailingTrivia":[],"presence":"Present"}],"presence":"Present"},{"id":9,"kind":"ExpressionSegment","layout":[{"id":4,"tokenKind":{"kind":"backslash"},"leadingTrivia":[],"trailingTrivia":[],"presence":"Present"},{"id":5,"tokenKind":{"kind":"l_paren"},"leadingTrivia":[],"trailingTrivia":[],"presence":"Present"},{"id":7,"kind":"IdentifierExpr","layout":[{"id":6,"tokenKind":{"kind":"identifier","text":"bar"},"leadingTrivia":[],"trailingTrivia":[],"presence":"Present"},null],"presence":"Present"},{"id":8,"tokenKind":{"kind":"string_interpolation_anchor"},"leadingTrivia":[],"trailingTrivia":[],"presence":"Present"}],"presence":"Present"},{"id":11,"kind":"StringSegment","layout":[{"id":10,"tokenKind":{"kind":"string_segment","text":""},"leadingTrivia":[],"trailingTrivia":[],"presence":"Present"}],"presence":"Present"}],"presence":"Present"},{"id":1,"tokenKind":{"kind":"string_quote"},"leadingTrivia":[],"trailingTrivia":[],"presence":"Present"}],"presence":"Present"},null,null],"presence":"Present"}],"presence":"Present"},{"id":16,"tokenKind":{"kind":"eof","text":""},"leadingTrivia":[{"kind":"Newline","value":1}],"trailingTrivia":[],"presence":"Present"}],"presence":"Present"}
      

       

      Qestions

      Can we have the raw strings literal as token kind like pound in syntax tree? This can be eliminated in AST as it is.

        Attachments

          Activity

            People

            Assignee:
            jansvoboda11 Jan Svoboda
            Reporter:
            kitasuke Yusuke Kita
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: