1
- // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1
+ // Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2
2
// file at the top-level directory of this distribution and at
3
3
// http://rust-lang.org/COPYRIGHT.
4
4
//
@@ -15,6 +15,7 @@ use codemap::{BytePos, CharPos, CodeMap, FileMap, Pos};
15
15
use diagnostic;
16
16
use parse:: lexer:: { is_whitespace, get_str_from, reader} ;
17
17
use parse:: lexer:: { StringReader , bump, is_eof, nextch, TokenAndSpan } ;
18
+ use parse:: lexer:: { is_line_non_doc_comment, is_block_non_doc_comment} ;
18
19
use parse:: lexer;
19
20
use parse:: token;
20
21
use parse;
@@ -46,9 +47,9 @@ impl cmnt_style : cmp::Eq {
46
47
pub type cmnt = { style : cmnt_style , lines : ~[ ~str ] , pos : BytePos } ;
47
48
48
49
pub fn is_doc_comment( s : ~str ) -> bool {
49
- s. starts_with ( ~"///") ||
50
+ ( s. starts_with ( ~"///") && ! is_line_non_doc_comment ( s ) ) ||
50
51
s. starts_with ( ~"//!") ||
51
- s. starts_with ( ~"/* * ") ||
52
+ ( s. starts_with ( ~"/* * ") && !is_block_non_doc_comment(s) ) ||
52
53
s.starts_with(~" /*!")
53
54
}
54
55
@@ -231,47 +232,56 @@ fn read_block_comment(rdr: @mut StringReader,
231
232
bump(rdr);
232
233
bump(rdr);
233
234
235
+ let mut curr_line = ~"/*";
236
+
234
237
// doc-comments are not really comments, they are attributes
235
238
if rdr.curr == '*' || rdr.curr == '!' {
236
239
while !(rdr.curr == '*' && nextch(rdr) == '/') && !is_eof(rdr) {
240
+ str::push_char(&mut curr_line, rdr.curr);
237
241
bump(rdr);
238
242
}
239
243
if !is_eof(rdr) {
244
+ curr_line += ~"*/";
240
245
bump(rdr);
241
246
bump(rdr);
242
247
}
243
- return;
244
- }
245
-
246
- let mut curr_line = ~"/*";
247
- let mut level: int = 1;
248
- while level > 0 {
249
- debug!("=== block comment level %d", level);
250
- if is_eof(rdr) {(rdr as reader).fatal(~"unterminated block comment");}
251
- if rdr.curr == '\n' {
252
- trim_whitespace_prefix_and_push_line(&mut lines, curr_line, col);
253
- curr_line = ~"";
254
- bump(rdr);
255
- } else {
256
- str::push_char(&mut curr_line, rdr.curr);
257
- if rdr.curr == '/' && nextch(rdr) == '*' {
258
- bump(rdr);
248
+ if !is_block_non_doc_comment(curr_line) { return; }
249
+ assert !curr_line.contains_char('\n');
250
+ lines.push(curr_line);
251
+ } else {
252
+ let mut level: int = 1;
253
+ while level > 0 {
254
+ debug!("=== block comment level %d", level);
255
+ if is_eof(rdr) {
256
+ (rdr as reader).fatal(~"unterminated block comment");
257
+ }
258
+ if rdr.curr == '\n' {
259
+ trim_whitespace_prefix_and_push_line(&mut lines, curr_line,
260
+ col);
261
+ curr_line = ~"";
259
262
bump(rdr);
260
- curr_line += ~"*";
261
- level += 1;
262
263
} else {
263
- if rdr.curr == '*' && nextch(rdr) == '/' {
264
+ str::push_char(&mut curr_line, rdr.curr);
265
+ if rdr.curr == '/' && nextch(rdr) == '*' {
264
266
bump(rdr);
265
267
bump(rdr);
266
- curr_line += ~"/";
267
- level -= 1;
268
- } else { bump(rdr); }
268
+ curr_line += ~"*";
269
+ level += 1;
270
+ } else {
271
+ if rdr.curr == '*' && nextch(rdr) == '/' {
272
+ bump(rdr);
273
+ bump(rdr);
274
+ curr_line += ~"/";
275
+ level -= 1;
276
+ } else { bump(rdr); }
277
+ }
269
278
}
270
279
}
280
+ if str::len(curr_line) != 0 {
281
+ trim_whitespace_prefix_and_push_line(&mut lines, curr_line, col);
282
+ }
271
283
}
272
- if str::len(curr_line) != 0 {
273
- trim_whitespace_prefix_and_push_line(&mut lines, curr_line, col);
274
- }
284
+
275
285
let mut style = if code_to_the_left { trailing } else { isolated };
276
286
consume_non_eol_whitespace(rdr);
277
287
if !is_eof(rdr) && rdr.curr != '\n' && vec::len(lines) == 1u {
0 commit comments