Fix CRLF line-ending parsing for comments.

This commit is contained in:
Lee Jeffery
2015-05-08 20:33:58 +01:00
parent b402c43f08
commit a76244fcef

View File

@@ -403,9 +403,11 @@ impl<'a> StringReader<'a> {
Some('/') => { Some('/') => {
self.bump(); self.bump();
self.bump(); self.bump();
// line comments starting with "///" or "//!" are doc-comments // line comments starting with "///" or "//!" are doc-comments
if self.curr_is('/') || self.curr_is('!') { let doc_comment = self.curr_is('/') || self.curr_is('!');
let start_bpos = self.pos - BytePos(3); let start_bpos = self.pos - BytePos(3);
while !self.is_eof() { while !self.is_eof() {
match self.curr.unwrap() { match self.curr.unwrap() {
'\n' => break, '\n' => break,
@@ -415,33 +417,33 @@ impl<'a> StringReader<'a> {
break break
} else { } else {
self.err_span_(self.last_pos, self.pos, self.err_span_(self.last_pos, self.pos,
"bare CR not allowed in doc-comment"); "bare CR not allowed in comment");
} }
} }
_ => () _ => ()
} }
self.bump(); self.bump();
} }
return self.with_str_from(start_bpos, |string| {
// but comments with only more "/"s are not return if doc_comment {
self.with_str_from(start_bpos, |string| {
// comments with only more "/"s are not doc comments
let tok = if is_doc_comment(string) { let tok = if is_doc_comment(string) {
token::DocComment(token::intern(string)) token::DocComment(token::intern(string))
} else { } else {
token::Comment token::Comment
}; };
return Some(TokenAndSpan{ Some(TokenAndSpan {
tok: tok, tok: tok,
sp: codemap::mk_sp(start_bpos, self.last_pos) sp: codemap::mk_sp(start_bpos, self.last_pos)
}); })
}); })
} else { } else {
let start_bpos = self.last_pos - BytePos(2); Some(TokenAndSpan {
while !self.curr_is('\n') && !self.is_eof() { self.bump(); }
return Some(TokenAndSpan {
tok: token::Comment, tok: token::Comment,
sp: codemap::mk_sp(start_bpos, self.last_pos) sp: codemap::mk_sp(start_bpos, self.last_pos)
}); })
} }
} }
Some('*') => { Some('*') => {