]> git.lizzy.rs Git - rust.git/commit
Handle CRLF properly in the lexer
authorKevin Ballard <kevin@sb.org>
Sat, 24 May 2014 08:13:59 +0000 (01:13 -0700)
committerKevin Ballard <kevin@sb.org>
Thu, 19 Jun 2014 04:07:58 +0000 (21:07 -0700)
commit8a8e497ae786ffc032c1e68fc23da0edcf6fa5e3
treee9d7a99dbf4006f1eba4976cf432cc81bfcf7665
parentd41058ed39fcd7e15ce9d0e7705643da85c94271
Handle CRLF properly in the lexer

The lexer already ignores CRLF in between tokens, but it doesn't
properly handle carriage returns inside strings and doc comments. Teach
it to treat CRLF as LF inside these tokens, and to disallow carriage
returns that are not followed by linefeeds. This includes handling an
escaped CRLF inside a regular string token the same way it handles an
escaped LF.

This is technically a breaking change, as bare carriage returns are no
longer allowed, and CRLF sequences are now treated as LF inside strings
and doc comments, but it's very unlikely to actually affect any
real-world code.

This change is necessary to have Rust code compile on Windows the same
way it does on Unix. The mozilla/rust repository explicitly sets eol=lf
for Rust source files, but other Rust repositories don't. Notably,
rust-http cannot be compiled on Windows without converting the CRLF line
endings back to LF.

[breaking-change]
src/libsyntax/parse/lexer/mod.rs
src/libsyntax/parse/mod.rs
src/test/compile-fail/lex-bare-cr-string-literal-doc-comment.rs [new file with mode: 0644]
src/test/run-pass/.gitattributes [new file with mode: 0644]
src/test/run-pass/lexer-crlf-line-endings-string-literal-doc-comment.rs [new file with mode: 0644]