diff options
| author | Lee Jeffery <leejeffery@gmail.com> | 2015-05-08 20:33:58 +0100 |
|---|---|---|
| committer | Lee Jeffery <leejeffery@gmail.com> | 2015-05-08 20:33:58 +0100 |
| commit | a76244fcef9e1ae83b6a7631f33c409c156ad3d9 (patch) | |
| tree | 6c7bdee487f54089e9b6f28c21d3a734eccf97d0 /src/libsyntax/parse | |
| parent | b402c43f088882db8a03bfcbb5eb8429ef7def0e (diff) | |
| download | rust-a76244fcef9e1ae83b6a7631f33c409c156ad3d9.tar.gz rust-a76244fcef9e1ae83b6a7631f33c409c156ad3d9.zip | |
Fix CRLF line-ending parsing for comments.
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/lexer/mod.rs | 50 |
1 files changed, 26 insertions, 24 deletions
diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 6b0674c9a41..1a772783c9d 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -403,45 +403,47 @@ impl<'a> StringReader<'a> { Some('/') => { self.bump(); self.bump(); + // line comments starting with "///" or "//!" are doc-comments - if self.curr_is('/') || self.curr_is('!') { - let start_bpos = self.pos - BytePos(3); - while !self.is_eof() { - match self.curr.unwrap() { - '\n' => break, - '\r' => { - if self.nextch_is('\n') { - // CRLF - break - } else { - self.err_span_(self.last_pos, self.pos, - "bare CR not allowed in doc-comment"); - } + let doc_comment = self.curr_is('/') || self.curr_is('!'); + let start_bpos = self.pos - BytePos(3); + + while !self.is_eof() { + match self.curr.unwrap() { + '\n' => break, + '\r' => { + if self.nextch_is('\n') { + // CRLF + break + } else { + self.err_span_(self.last_pos, self.pos, + "bare CR not allowed in comment"); } - _ => () } - self.bump(); + _ => () } - return self.with_str_from(start_bpos, |string| { - // but comments with only more "/"s are not + self.bump(); + } + + 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) { token::DocComment(token::intern(string)) } else { token::Comment }; - return Some(TokenAndSpan{ + Some(TokenAndSpan { tok: tok, sp: codemap::mk_sp(start_bpos, self.last_pos) - }); - }); + }) + }) } else { - let start_bpos = self.last_pos - BytePos(2); - while !self.curr_is('\n') && !self.is_eof() { self.bump(); } - return Some(TokenAndSpan { + Some(TokenAndSpan { tok: token::Comment, sp: codemap::mk_sp(start_bpos, self.last_pos) - }); + }) } } Some('*') => { |
