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

Raw strings #6306

Open
Chriscbr opened this issue Apr 23, 2024 · 6 comments
Open

Raw strings #6306

Chriscbr opened this issue Apr 23, 2024 · 6 comments
Labels
breaking-change Fix expected to include a breaking change 🛠️ compiler Compiler ✨ enhancement New feature or request 📐 language-design Language architecture

Comments

@Chriscbr
Copy link
Contributor

Use Case

As a user, I would like a way to create strings that allow me to type special characters like backslashes without having them treated as escape sequences. Likewise, I would like to be able to type quotes without having to escape them every time.

Here are some examples where I need to modify my string in order to use it in my Wing source code:

"C:\Development\profile\aboutme.html"
// today, this turns into "C:Developmentprofileaboutme.html"

"{
  "name": "John Doe",
  "age": 43,
  "phones": [
    "+44 1234567",
    "+44 2345678"
  ]
}"
// today this is a syntax error

Proposed Solution

Perhaps we can reuse the non-interpolated string syntax from #6290, and change it so that it requires a trailing #, so we would end up with:

#"C:\Development\profile\aboutme.html"# // prints "C:\Development\profile\aboutme.html"

#"{
  "name": "John Doe",
  "age": 43,
  "phones": [
    "+44 1234567",
    "+44 2345678"
  ]
}"#

This is more or less similar to the design of Swift's raw strings (examples, RFC).

In cases where you want use the closing delimiter "# in your string, then the user can add more #'s:

log(##"hello"#world"##) // hello"#world

Implementation Notes

JavaScript has a way to obtain raw strings that could be useful: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw. Or maybe it would be easier to do the escaping within Wing's parser - not sure.

Component

Language Design

Community Notes

  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.
  • If this issue is labeled needs-discussion, it means the spec has not been finalized yet. Please reach out on the #dev channel in the Wing Slack.
@Chriscbr Chriscbr added ✨ enhancement New feature or request 📐 language-design Language architecture 🛠️ compiler Compiler needs-discussion Further discussion is needed prior to impl labels Apr 23, 2024
@monadabot monadabot added this to Wing Apr 23, 2024
@github-project-automation github-project-automation bot moved this to 🆕 New - not properly defined in Wing Apr 23, 2024
@marciocadev
Copy link
Collaborator

I like this solution, Chris.

I found it quite interesting that by changing the quantity of # at the beginning and end of the string, it allows the use of this character within the string.

@staycoolcall911 staycoolcall911 moved this from 🆕 New - not properly defined to 🤝 Backlog - handoff to owners in Wing May 9, 2024
@Chriscbr Chriscbr added the breaking-change Fix expected to include a breaking change label May 9, 2024
@eladb
Copy link
Contributor

eladb commented May 18, 2024

@Chriscbr I think this is implemented right?

@Chriscbr
Copy link
Contributor Author

@eladb Right now we have "non-interpolated strings" which allow you to create strings like "foo{bar}" without interpolating variables for you. But characters like backslashes and quotes are still require escaping if you want to use them.

@eladb
Copy link
Contributor

eladb commented May 19, 2024

I see. Any reason not to merge these use cases and make non-interpolated strings into raw strings?

Is it really valuable to 3 types of string literals in the language?

@Chriscbr
Copy link
Contributor Author

Yup, exactly - I think they can combined 👍

Copy link

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days.
Feel free to re-open this issue when there's an update or relevant information to be added.
Thanks!

@github-actions github-actions bot added the Stale label Aug 17, 2024
@Chriscbr Chriscbr removed Stale needs-discussion Further discussion is needed prior to impl labels Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Fix expected to include a breaking change 🛠️ compiler Compiler ✨ enhancement New feature or request 📐 language-design Language architecture
Projects
Status: 🤝 Backlog - handoff to owners
Development

No branches or pull requests

3 participants