Re: [Nix-dev] How to escape $'\t' in Nix multi-line string?
On 30/04/17 20:04, Bjørn Forsman wrote: On 30 April 2017 at 19:53, Profpatschwrote: On 17-04-30 03:07pm, Bjørn Forsman wrote: On 30 April 2017 at 15:01, Bjørn Forsman wrote: Hi all, I'm stuck trying to pass $'\t' to bash via Nix multi-line strings: nix-repl> ''cut -d $'\t' -f 1'' error: syntax error, unexpected $undefined, expecting IND_STR or DOLLAR_CURLY or IND_STRING_CLOSE, at (string):1:10 Oh, it was only missing double single-quotes before the dollar sign. What tripped me was that the documentation says ${ is special in strings, not $'. How should we improve the manual in this regard? Sure. But I'm also quite interested in knowing why $' needs escaping, especially when $ ' (space between) does not. I guess the answer resides at https://github.com/NixOS/nix/blob/2f21d522c28b1e902bd7f0b5b9e7523975102d81/src/libexpr/lexer.l#L159-L162 To be efficient, we accept any $ followed by something that's not a opening curly brace ('{') as normal string content. But we cannot accept "$'", as the last single quote could be part of a double single-quote, thus ending the multiline-string. The corner case of a single single-quote following a dollar requires a lookahead and has been left out (forgotten ? :-)) in the lexer. For advanced usages of multiline-strings, I refer you to the tests in nix source code : https://github.com/NixOS/nix/blob/master/tests/lang/eval-okay-ind-string.nix -- Layus. ___ nix-dev mailing list nix-dev@lists.science.uu.nl https://mailman.science.uu.nl/mailman/listinfo/nix-dev
Re: [Nix-dev] How to escape $'\t' in Nix multi-line string?
On 30 April 2017 at 19:53, Profpatschwrote: > On 17-04-30 03:07pm, Bjørn Forsman wrote: >> On 30 April 2017 at 15:01, Bjørn Forsman wrote: >> > Hi all, >> > >> > I'm stuck trying to pass $'\t' to bash via Nix multi-line strings: >> > >> > nix-repl> ''cut -d $'\t' -f 1'' >> > error: syntax error, unexpected $undefined, expecting IND_STR or >> > DOLLAR_CURLY or IND_STRING_CLOSE, at (string):1:10 >> >> Oh, it was only missing double single-quotes before the dollar sign. >> >> What tripped me was that the documentation says ${ is special in >> strings, not $'. > > How should we improve the manual in this regard? Sure. But I'm also quite interested in knowing why $' needs escaping, especially when $ ' (space between) does not. - Bjørn ___ nix-dev mailing list nix-dev@lists.science.uu.nl https://mailman.science.uu.nl/mailman/listinfo/nix-dev
Re: [Nix-dev] How to escape $'\t' in Nix multi-line string?
On 17-04-30 03:07pm, Bjørn Forsman wrote: > On 30 April 2017 at 15:01, Bjørn Forsmanwrote: > > Hi all, > > > > I'm stuck trying to pass $'\t' to bash via Nix multi-line strings: > > > > nix-repl> ''cut -d $'\t' -f 1'' > > error: syntax error, unexpected $undefined, expecting IND_STR or > > DOLLAR_CURLY or IND_STRING_CLOSE, at (string):1:10 > > Oh, it was only missing double single-quotes before the dollar sign. > > What tripped me was that the documentation says ${ is special in > strings, not $'. How should we improve the manual in this regard? -- Proudly written in Mutt with Vim on NixOS. Q: Why is this email five sentences or less? A: http://five.sentenc.es May take up to five days to read your message. If it’s urgent, call me. ___ nix-dev mailing list nix-dev@lists.science.uu.nl https://mailman.science.uu.nl/mailman/listinfo/nix-dev