elm-format icon indicating copy to clipboard operation
elm-format copied to clipboard

"\r" is converted into "\x0D"

Open jinjor opened this issue 8 years ago • 10 comments

Before:

"\r\n\t"

After:

"\x0D\n\t"

Is this intended? I prefer "\r" for readability.

jinjor avatar Jun 03 '17 13:06 jinjor

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 ?

avh4 avatar Jun 03 '17 19:06 avh4

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.

jinjor avatar Jun 04 '17 02:06 jinjor

This happens a lot in parsers. The CSV spec (haha, I know) specifies lines end with a \r\n.

BrianHicks avatar Jul 11 '17 14:07 BrianHicks

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.

robx avatar Jan 31 '18 18:01 robx

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?

keithasaurus avatar Jul 04 '19 05:07 keithasaurus

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}

sgaston321 avatar Jul 23 '19 20:07 sgaston321

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

avh4 avatar Jul 23 '19 20:07 avh4

Thank you! Yes, this was the issue.

sgaston321 avatar Jul 23 '19 20:07 sgaston321

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! 😄

ben-eb avatar Jul 05 '20 21:07 ben-eb

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.

richardhozak avatar May 21 '21 14:05 richardhozak