-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
POC make fmt"{foo}\n{\bar}" do the right thing #7071
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
Conversation
| else: | ||
| format($arg, option, res) | ||
|
|
||
| proc impl(pattern: NimNode, shouldUnescape: bool): NimNode = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to move this above the runableExamples so the diff is huge. The only actual change was adding the makeStrLit template and calling on lines 252 and 285
| while i < f.len and f[i] != '}' and f[i] != ':': | ||
| subexpr.add f[i] | ||
| inc i | ||
| if i == f.len: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check was added in commit 2 to improve the error message when " is used incorrectly
| proc unescape*(s: string, prefix = "\"", suffix = "\""): string {.noSideEffect, | ||
| rtl, extern: "nsuUnescape".} = | ||
| ## Unescapes a string `s`. | ||
| ## Unescapes a string `s` using nim's string escape rules. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if that is its purpose. I imagined it to use some lowest common denominator escape rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too opinionated on where this functionality belongs, but it does seem useful in stdlib. Does macros.nim sound better since it is most useful when writing macros?
|
So it's either:
or
|
|
@dom96 This PR stills keeps This is not possible to solve with |
In what way is that silly? That's what I would expect. If you want a literal |
|
I think it is a distinction in whether you view it as "writing a string that is passed to the fmt macro" or "writing an fmt string". I think your description makes sense if you think of it like the former, which is technically correct but less useful. I think we should make fmt work like the later, similar to how when using re"" you think about writing a regex rather than writing a string that gets passed to re. Isn't that the goal when writing a DSL? |
|
It becomes a big problem with syntax highlighting. A good highlighter should highlight text inside |
|
Thank you for this PR but we decided for |
This is a POC. If the general concept is approved, I'll test, document, etc.
This is an alternative to #7070