-
Notifications
You must be signed in to change notification settings - Fork 497
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
String iterpolation #70
Comments
From an implementation point of view, one would need to adjust the lexer to split the string in token that can be parsed independently: |
Thanks for the implementation view, will take a closer look on it soon. |
Using a |
Ah yes, Python's f strings are like JS template strings - I also like that syntax a lot. And using regular quotes is easier than the backticks in JS. The more I think about it, the more I dislike those and prefer something like f strings. I guess we just have to pick one and go with it. |
I tried to make a survey of the different language: JavascriptUses `string text ${expression} string text` PythonRequire a f'My name is {name}, my age next year is {age+1}, my anniversary is {anniversary:%A, %B %d, %Y}.' C# / VisualBasicString starts with $"Hello, {name}! Today is {date.DayOfWeek}, it's {date:HH:mm} now." PHPOne must use "This works {$obj->values[3]->name}"; SwiftNormal string using "\(multiplier) times 2.5 is \(Double(multiplier) * 2.5)" RustRust does not have string interpolation, but the syntax of the format! macro will allow to use Note that in the .60 language, there is not even yet way to escape quotes or anything. We don't have raw literal either. |
I vote for python or javascript, maybe a mix between both languages since they are the cleaner and friendly approach for the user ?
I also agree with @Plecra comment about the escape char for interpolation. |
Currently what's implemented in master is |
We want to be able to easily format strings with other expression.
Possible syntax:
Advantage is that people coming from JS will be familiar with this.
\{
The advantage is that there is only one form of string. (I think JS uses backtick because using normal quote would not have been backward compatible, but we don't have this problem)
The question is how good does it play with translation?
Imagine we support this syntax:
The translation extracting tool could extract the string "The window with is {0} and its title is {1}" as the string to be translated.
The text was updated successfully, but these errors were encountered: