<qyliss>
You'd want modes for both " and '' strings
<infinisil>
Probably could do them in one by just outputting both
<qyliss>
That would work too
<qyliss>
And even then you could only output both if they differ, which lots of the time they probably wouldn't.
<infinisil>
Ah nice idea
<infinisil>
> unicorn
<{^_^}>
"🦄"
<infinisil>
Now the difficult part of course is how to implement that..
<infinisil>
Maybe a sane way is to just escape everything, then make sure the result is what we want, then remove escapings one by one, removing as much as possible until no more can be removed
<infinisil>
> "\h\e\l\l\o\$\$\{\}"
<{^_^}>
"hello$${}"
<infinisil>
Or maybe only escape all characters that *might* be involved in escape shenanigans
<infinisil>
Or probably rather only don't escape those that for sure aren't involved in escape shenanigans
<qyliss>
well, for double quoting Nix can already do this:
<qyliss>
% nix-instantiate --eval -E "{ x }: x" --argstr x 'foo"'
<qyliss>
"foo\""
<infinisil>
Oh and that always works?
<qyliss>
I assume it does
<qyliss>
would be weird to have it if that wasn't at least a goal
<infinisil>
% nix-instantiate --eval -E "{ x }: x" --argstr x '${}'
<infinisil>
"${}"
<qyliss>
hmm :/
<infinisil>
Guess not quite
<qyliss>
that's probably a bug tbh?
<infinisil>
Is it a bug if this was never intended to be a feature?
hmpffff_ has quit [Quit: nchrrrr…]
<infinisil>
Oh, does it maybe just use json escaping for the output
hmpffff has joined #nix-lang
hmpffff has quit [Client Quit]
hmpffff has joined #nix-lang
hmpffff has quit [Client Quit]
<infinisil>
> "${"h"}${"i"}${"$"}${"\""}"
<{^_^}>
"hi$\""
<qyliss>
I guess I just assumed it would output an escaped Nix string because lots of other interpreted languages do that
<pie_>
their escaping is a bit simpler though >.>
<qyliss>
not necessarily
<pie_>
(citation needed)
<pie_>
<-
<infinisil>
With IRC at least I won't need to handle newlines :)
<qyliss>
Ruby escaping is pretty gnarly
<qyliss>
Or, well, it's pretty regular in that you always use a backslash, but there's all sorts of weird syntaxes inside a string
<{^_^}>
'' two single quotes: ''' bash curly bois: ''${} newline: ''\n tab: ''\t any character x: ''\x ''
<infinisil>
> '' '' ''
<{^_^}>
error: syntax error, unexpected $end, expecting IND_STR or DOLLAR_CURLY or IND_STRING_CLOSE, at (string):311:1
<infinisil>
> ''${"'"}${"'"}''
<{^_^}>
"''"
<infinisil>
How to escape anything in a '' string: Just use ''${<the escaped form for " strings>}'' :)
<infinisil>
Oh no, I think trying to find the best escaping is a graph traversal problem
<infinisil>
The starting node is the string fully escaped, with ${"x"} for every character
<infinisil>
Edges are transformations to that string that don't change the final result
<infinisil>
And they need to shorten the string too
<infinisil>
The goal is a node that has the shortest string, which you can get to using a series of these edge transformations
<infinisil>
> '' \thello ''
<{^_^}>
"\\thello "
<infinisil>
> '' ''' ''
<{^_^}>
"'' "
<infinisil>
> '''''''
<{^_^}>
"''"
<infinisil>
> ''''''''
<{^_^}>
error: syntax error, unexpected $end, expecting IND_STR or DOLLAR_CURLY or IND_STRING_CLOSE, at (string):310:9
<infinisil>
> '' '''' ''
<{^_^}>
"''' "
<infinisil>
Huh
<infinisil>
> '' ''''''
<{^_^}>
error: syntax error, unexpected $end, expecting IND_STR or DOLLAR_CURLY or IND_STRING_CLOSE, at (string):310:10
<infinisil>
> '''''' ''
<{^_^}>
"''' "
<infinisil>
> '' '''' ''
<{^_^}>
"''' "
<infinisil>
> '' ''''' ''
<{^_^}>
error: syntax error, unexpected $end, expecting IND_STR or DOLLAR_CURLY or IND_STRING_CLOSE, at (string):311:1
<infinisil>
> '' '''''' ''
<{^_^}>
"'''' "
<infinisil>
> '''''
<{^_^}>
error: syntax error, unexpected $end, expecting IND_STR or DOLLAR_CURLY or IND_STRING_CLOSE, at (string):310:6
<infinisil>
> ''${"'"}''
<{^_^}>
"'"
<infinisil>
> ''''\'''
<{^_^}>
"'"
<infinisil>
> ''''\ ''
<{^_^}>
" "
<infinisil>
> ''''\n''
<{^_^}>
"\n"
<infinisil>
What
<infinisil>
> '' ''\n ''
<{^_^}>
"\n "
<infinisil>
> '' ''\t ''
<{^_^}>
"\t "
<infinisil>
> '' ''\a ''
<{^_^}>
"a "
<infinisil>
> '' ''\'''\'''\' ''
<{^_^}>
"''' "
<infinisil>
> '' ''\'''\'''\'''
<{^_^}>
"'''"
<infinisil>
> ''''\'''\'''\'''
<{^_^}>
"'''"
<infinisil>
> ''''\'''\'''
<{^_^}>
"''"
<MichaelRaskin>
infinisil: If you are doing graph traversal, maybe simplify the situation a bit and consider the graph where paths are valid input strings?