Comments (7)
From an implementation point of view, one would need to adjust the lexer to split the string in token that can be parsed independently: StringLiteral OpenInterpolation Identifier Dot Identifier ... CloseInterpolation StringLiteral OpenInterpolation ...
Then the parser could build an expression tree that would have a Expression::InterpolatedString { components: Vec<Expression> }
that would then be produced.
from slint.
Thanks for the implementation view, will take a closer look on it soon.
from slint.
Using a \
for the interpolation syntax is confusing to me. I'd expect it to be used to disable a special syntax, rather than mark it. I'd prefer "{foo}"
to be interpolated, like Python's f strings.
from slint.
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.
from slint.
I tried to make a survey of the different language:
Please let me know if i got something wrong or forgot a language.
I only include the languages that allow to put any arbitrary expression within a string, so not just printf
style
Javascript
Uses `
instead of "
for the quote, then ${ ... }
for the expression
`string text ${expression} string text`
Python
Require a f
before the string, then expression are just in { }
f'My name is {name}, my age next year is {age+1}, my anniversary is {anniversary:%A, %B %d, %Y}.'
C# / VisualBasic
String starts with $
and then inside is just { }
$"Hello, {name}! Today is {date.DayOfWeek}, it's {date:HH:mm} now."
PHP
One must use "
(and not '
) then one can use $variable
or ${variable}
One can put some expression within the ${ ... }
but not all expression are supported.
"This works {$obj->values[3]->name}";
Swift
Normal string using \( ... )
"\(multiplier) times 2.5 is \(Double(multiplier) * 2.5)"
Rust
Rust does not have string interpolation, but the syntax of the format! macro will allow to use {variable}
as per RFC 2795
Note that in the .60 language, there is not even yet way to escape quotes or anything. We don't have raw literal either.
But I guess that \
would be the most natural character to do escapes, since this is what almost all languages do (eg: \n
and \"
) so it would be natural to use \{ }
, then one does not need anything else special. This is almost what swift does.
from slint.
I vote for python or javascript, maybe a mix between both languages since they are the cleaner and friendly approach for the user ?
// js
`string text ${expression} string text`
// python
f"string text {expression} string text"
// mix
`string text {expression} string text` or "string text {expression} string text"
I also agree with @Plecra comment about the escape char for interpolation.
from slint.
Currently what's implemented in master is "string text \{expression} string text"
from slint.
Related Issues (20)
- TimePicker widget HOT 2
- LineEdit Widget Error HOT 2
- Quickstart Rust Example Code Display Defect HOT 2
- Using Path in an embedded project will result in a compilation error. HOT 1
- is it possible to express a tree in this type system? HOT 1
- Path: Can't parse commands containing scientific notation HOT 3
- Performance issues using imports vs single .slint file HOT 6
- RFC: date-time builtin type HOT 2
- Component catalogue in Design Mode includes component under preview, resulting in compilation errors on drop HOT 2
- Component catalogue shows user defined duplicates in gallery demo HOT 1
- Built-in VirtualKeyboard element for improved support for in-process embedded virtual keyboards
- A bug with booleans, rust slint. HOT 3
- Android: double-clicked callback not work on TouchArea HOT 2
- Android: default-font-family not work
- Support libraries in LSP
- Compiler panic compiling `init` callback from a component inlined into a repeater HOT 1
- Include LTS Version as slintpad dependency
- I created a TextEdit that automatically fills in a string of keyboard characters when switching from the desktop window. Can anyone tell me why? I am very distressed HOT 4
- hide() directly closes the program HOT 3
- Introduce undefined values for properties and struct fields HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slint.