elm-format
elm-format copied to clipboard
"\r" is converted into "\x0D"
Before:
"\r\n\t"
After:
"\x0D\n\t"
Is this intended? I prefer "\r" for readability.
Yes, that was intended, the reason being that a lot of people don't know what \r is (especially web developers).
Can you share a bit more about the context in which you need a string containing \r ?
I'm implementing a XML parser. XML considers "\r" as a whitespace. I haven't parsed any document yet but maybe a document that is written in Windows environment can contain that character.
This happens a lot in parsers. The CSV spec (haha, I know) specifies lines end with a \r\n.
Ran into the same thing, writing an EDN parser... The \x0D is certainly a bit ugly and confusing. But also not a particularly big deal.
Bitten by this as well. In general, I would expect elm-format to not rewrite anything except whitespace. Is there something I'm missing here?
this causes a compiler error sadly
Backslashes always start escaped characters, but I do not recognize this one:
41| Parser.chompWhile (\c -> c == ' ' || c == '\t' || c == '\n' || c == '\x0D')
^
Maybe there is some typo?
Hint: Valid escape characters include:
\n
\r
\t
\"
\'
\\
\u{03BB}
You appear to be using elm-format in Elm 0.18 mode. Try passing --elm-version=0.19 or removing the elm-package.json from your project to get it to run in 0.19 mode, which should emit \u{0D} instead of \x0D
Thank you! Yes, this was the issue.
Came across this today when running elm-format on this particular piece of code:
https://github.com/elm/parser/blob/7506b07eaa93a93d13b508b948c016105b0953c8/examples/DoubleQuoteString.elm#L32-L40
In this context I would argue that map (\_ -> "\u{000D}") (token "r") is less clear. Before I found this thread I thought it was a bug! 😄
Came across this today too during a code review, did not know what "\u{000D}" meant, when I looked it up, found out it was \r. What we needed to do is export file with windows line endings which is <CR><LF> or "\r\n". I find this very strange and confusing.