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

[SR-170] SE 0168 Multi-Line String Literals #42792

Closed
swift-ci opened this issue Dec 10, 2015 · 7 comments
Closed

[SR-170] SE 0168 Multi-Line String Literals #42792

swift-ci opened this issue Dec 10, 2015 · 7 comments
Labels
compiler The Swift compiler in itself feature A feature request or implementation improvement lexer Area → compiler: The legacy C++ lexer literals Feature → expressions: Literals such as an integer or string literal multiline string literals Feature → expressions → literals → string literals: multiline string literals

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Dec 10, 2015

Previous ID SR-170
Radar rdar://problem/12574718
Original Reporter ttilley (JIRA User)
Type Improvement
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 6
Component/s Compiler
Labels Improvement, LanguageFeatureRequest
Assignee None
Priority Medium

md5: f0038de7dd719f443bd86f54945b80da

Issue Description:

I would very much like to implement python-style multi-line string literals in swift (not to be confused with slightly more complex heredoc style syntax). Strings would be started by a triple quote and ended by a triple quote, potentially with any consistent internal indentation stripped from the resulting string.

Something to the effect of:

let foo = """
  this is the first line
  this is the second line
"""

Is there any interest, and if so is there any code I would need to touch outside of lib/Parse/Lexer.cpp? I only have a basic understanding of C++ and don't grok SourceKit in any way whatsoever.

My main motivation is to make the use of DocOpt style command-line parsing significantly more pleasant. To see an example of what I mean, please check out http://docopt.org/

@drewcrawford
Copy link
Contributor

I filed a request for this a year ago as rdar://17923205

That rdar got duped to rdar://12574718 which remains open.

I assume Apple folk have access to additional commentary under those #s

@swift-ci
Copy link
Collaborator Author

Comment by Travis Tilley (JIRA)

Access to said commentary would be quite helpful indeed.

@belkadan
Copy link
Contributor

Info from Radar:

  • There are many duplicates of this, so it is definitely desireable.

  • There are many possible syntaxes; Python triple-quoted strings are only one suggestion.

  • Some of the requests mention specifying dialects for the string, so that they can be independently parsed by IDEs. This is useful for things like shaders.

  • People are also interested in "raw strings" that don't require escapes, but that's probably worth a separate proposal rather than trying to tackle both at once.

Info from me:

  • I think this would mostly just be a change to Lexer.cpp, yes, but I haven't really looked into it.

  • As a language change, this needs to go through the Swift Evolution Process.

@swift-ci
Copy link
Collaborator Author

Comment by Travis Tilley (JIRA)

Thank you very kindly for the information. In open source projects I tend to just implement things and since the work is already done it tends to get accepted without too much debate (or accepted after a maintainer tells me a better way to do it and I rewrite). I guess I can't get away with that here. 😉

I'll hop on the mailing lists and make sure everything is hashed out.

@swift-ci
Copy link
Collaborator Author

Comment by Travis Tilley (JIRA)

Just to note for anyone not following the discussion on the mailing list, that feedback is ongoing here: https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151207/001565.html

@johnno1962
Copy link
Contributor

Proof of concept PR raised showing Lexer changed required: #2275

@tkremenek
Copy link
Member

The latest proposal:

https://github.com/apple/swift-evolution/blob/master/proposals/0168-multi-line-string-literals.md

The following PR implements it:

#8813

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added literals Feature → expressions: Literals such as an integer or string literal multiline string literals Feature → expressions → literals → string literals: multiline string literals labels Mar 22, 2023
@AnthonyLatsis AnthonyLatsis added the lexer Area → compiler: The legacy C++ lexer label Mar 22, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself feature A feature request or implementation improvement lexer Area → compiler: The legacy C++ lexer literals Feature → expressions: Literals such as an integer or string literal multiline string literals Feature → expressions → literals → string literals: multiline string literals
Projects
None yet
Development

No branches or pull requests

6 participants