avh4 / elm-format

elm-format formats Elm source code according to a standard set of rules based on the official Elm Style Guide
BSD 3-Clause "New" or "Revised" License
1.31k stars 145 forks source link

"\r" is converted into "\x0D" #376

Open jinjor opened 7 years ago

jinjor commented 7 years ago

Before:

"\r\n\t"

After:

"\x0D\n\t"

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

avh4 commented 7 years ago

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 ?

jinjor commented 7 years ago

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.

BrianHicks commented 7 years ago

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

robx commented 6 years ago

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.

keithasaurus commented 5 years ago

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?

sgaston321 commented 5 years ago

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}
avh4 commented 5 years ago

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

sgaston321 commented 5 years ago

Thank you! Yes, this was the issue.

ben-eb commented 4 years ago

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

richardhozak commented 3 years ago

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.