-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Windows line endings break escaped newlines in strings #5831
Comments
IMHO Crystal shouldn't support CRLF in source files at all. |
Any particular reason? Just to deliberately make future chances of Windows compatibility more difficult, or...? I don't like CRLF either, but that's no reason to deliberately handle them incorrectly. |
Because it's completely unnecessary and avoids annoying line ending issues. |
Well, except for everyone developing on Windows. Only allowing LF will, for example, require lines like Personally, I think Crystal should aim to be friendly for the developers using it, as opposed to just the developers developing the language itself. |
The issue isn't LF vs CRLF, but that we shouldn't support escaping line breaks with |
Oh, that's on its way out for some reason? In the string literals section of the syntax docs, it's quite clearly documented, and I'd say it's a fairly welcome feature. Guess that might not be the case soon, though? |
@obskyr I'm working on Windows as my primary development platform. None of my source code files uses CRLF (unless explicitly required) and this really keeps away pain. This is way easier to achieve than you think. Put To me, developer friendly means to make life easier avoiding unnecessary choices and less things to worry about. @ysbaddaden IMHO it's a different issue. It shows that the implementation has to keep track of different line endings in many places (not just regarding line continuation). This would be easier if only LF is supported. |
@straight-shoota Requiring Windows users to either use EditorConfig or change their global git config is most definitely not "developer friendly". |
I think it is, because it's a setting you have to set once and can forget it. Otherwise you will inevitably run into issues with non-matching line endings, mistakenly commit wrong line endings etc. |
You won't if Crystal supports them properly. Instead of having it work only for people who have manually set global settings, why not have it work for everyone? |
Sigh... is this so hard to understand? Whether Crystal supports CRLF or not has nothing to do with the issues I mentioned. |
Hey, there's no need to be condescending. So, you're thinking Crystal should just error out if it encounters a CRLF linebreak while parsing? |
Essentially, yes. This is obviously not entirely thought through, just an idea to contemplate. Don't know what core members think. CR-only newlines for example are not supported and result in an syntax error: |
I really am not at all into the idea of having to add |
We should either support all like endings in the compiler or error out if the line endings are wrong. There's an actionable item either way. |
What do Rust, Go, Nim in this case? |
Probably support them, and so should crystal. |
Interesting, I had a similar issue some time ago
https://github.com/crystal-lang-tools/vscode-crystal-lang/wiki/Known-Issues |
Yes! I have the same issue! I'm also developing on Windows and I can't create these Strings. |
Another related consideration - with "A multiline
string" Currently, it evaluates to |
On Nim: https://nim-lang.org/docs/manual.html Encoding All Nim source files are in the UTF-8 encoding (or its ASCII subset). Other encodings are not supported. Any of the standard platform line termination sequences can be used - the Unix form using ASCII LF (linefeed), the Windows form using the ASCII sequence CR LF (return followed by linefeed), or the old Macintosh form using the ASCII CR (return) character. All of these forms can be used equally, regardless of platform. I suppose they all support CR LF so it may be useful for crystal to support the other variants it as-is (also, the docu mentions it, so users may assume that \r works fine; if it does not work then I would assume users to expect that the documentation reflects this as well), Aside from this, I personally agree with straight-shoota (I myself never use \r, ever) but I think if "everyone else treats CR LF like newlines", such as the mentioned programming languages above for windows, then perhaps crystal should do so as well. You could also say that this is one small step for crystal to regard windows as a main platform ... :) |
|
Using |
I have an issue with CRLF.
Windows will inevitably create a file with CRLF somewhere, this is a reason why Crystal has to handle CRLF. I continue my deep dive of Crystal with Windows 🌊🌊🌊 |
Maybe crystal format could handle it. IMHO the language should handle the case anyway and encourage the |
The CRLF will probably go away if you define My opinion is the formatter should be able to normalize Crystal source files to LF, so that things continue to work even without EditorConfig; the formatter alone should be able to produce the same effects as the default |
Totally, |
I suppose we can support CRLF in the parser and have the formatter change them into LF. |
I don't understand what the issue is with supporting both CRLF and LF. Making the formatter change CRLF to LF might break someone's editor, maybe. Not sure! I think fixing this is trivial. The formatter enhancement is a separate topic. I'll send a PR later this week when ai have time. |
Hi, regardless of what you end up choosing, a more explicit error message would go a long way. This caused me a bunch of trouble. |
The following does not work as expected if your file's line endings are
\r\n
:Perhaps Crystal wants to support CRLF as a regular newline, perhaps it doesn't - whatever the case, I figured I'd report it.
The text was updated successfully, but these errors were encountered: