This works:
import strformat
echo &"""{"url = http//example.com"}"""
This does not:
import strformat
echo &"""{"url = http://example.com"}"""
Colon is the problem.
This works:
import strformat
echo &"""{"url = http\://example.com"}"""
@lscrd That doesn't compile for me.
@stbalbach Also, why do you have a literal string inside the curly braces. I have only seen variable names followed by colon and formatting options within the braces.
For example, I don't see the need of braces or & in your example. But if you remove the braces, it works:
import strformat
echo &""""url = http://example.com""""
Can you show something close to the actual example where you needed a literal string with : within braces within the & macro?
That's quite an odd thing your trying to do. Like kaushalmodi strformat is for embedding variables into string.
import strformat
let x = "url = http://example.com"
echo &"""{x}"""
on devel, you can escape colons (and curly brackets) with a backslash as @lscrd pointed out. Colons don't need to be backslash-escaped if inside parentheses https://nim-lang.github.io/Nim/strformat.html#implementation-details
so this also works:
import strformat
echo &"""{("url = http://example.com")}"""
Thanks. I revisited the strformat docs and there's certainly a lot of new stuff for me over there.
@shirleyquirk TIL about the special use if parens inside the braces. As I understand, this is still only in devel.
This example in the docs is pretty cool!
This hack works (1.4.0)
import strformat, re
proc colon(): char = ':'
echo &"""{re.replace("hello" & colon() & " world", re.re("hell"), "X")}"""
FWIW (1.6 doesn't build for me via choosenim - will wait for stable to catch up)1.6 doesn't build for me via choosenim
There is no 1.6 yet. You can use devel for the latest Nim.