Closed darichey closed 2 years ago
If we do this, we should do it properly from the start, i.e. remove all whitespace prefixes. In fact I have started on a patch for that, but it needs some more polishing, expect a PR ~next week :)
don't we already do that? The only difference necessary is that the first and last line are handled differently (in them, if they contain only spaces ' '
, they're omitted)
Right, I believe that is already handled. That said, I also think that this entire logic could use a rework. I started by trying to just dumbly port the reference implementation in this commit: https://github.com/darichey/rnix-parser/commit/d56b15ff4ae9e1c03a28c1f0894f6881761925dd
I confirmed that it at least parses all multiline strings in nixpkgs (see #107), but honestly the code is kind of ugly, and I haven't done any kind of benchmarks, so I didn't bother making a PR yet. Please feel free to use it as inspiration @Ma27 :)
Summary & Motivation
Previously, trailing whitespace on the last line of a multiline string was always removed, but this is not necessarily correct. For example, the string
''hello ''
should keep its trailing whitespace.This PR attempts to mimic the logic used in the reference implementation of the parser to instead only remove the final line if it consists solely of whitespace.