about summary refs log tree commit diff
path: root/src/libsyntax/parse/comments.rs
diff options
context:
space:
mode:
authorKang Seonghoon <public+git@mearie.org>2013-02-13 11:37:07 +0900
committerKang Seonghoon <public+git@mearie.org>2013-02-13 11:39:13 +0900
commit6d98ca94ccab88be224eb2703fb496c2d003a562 (patch)
tree0dd09a705cd6800d979e159df4372e777efa34da /src/libsyntax/parse/comments.rs
parent1a394e57f7a622e67c13eae8bc26848eea31334a (diff)
downloadrust-6d98ca94ccab88be224eb2703fb496c2d003a562.tar.gz
rust-6d98ca94ccab88be224eb2703fb496c2d003a562.zip
libsyntax: don't parse ////, /***/ as doc comments
Diffstat (limited to 'src/libsyntax/parse/comments.rs')
-rw-r--r--src/libsyntax/parse/comments.rs66
1 files changed, 38 insertions, 28 deletions
diff --git a/src/libsyntax/parse/comments.rs b/src/libsyntax/parse/comments.rs
index a8db06fe085..7a0fdd6b1b0 100644
--- a/src/libsyntax/parse/comments.rs
+++ b/src/libsyntax/parse/comments.rs
@@ -1,4 +1,4 @@
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
 // file at the top-level directory of this distribution and at
 // http://rust-lang.org/COPYRIGHT.
 //
@@ -15,6 +15,7 @@ use codemap::{BytePos, CharPos, CodeMap, FileMap, Pos};
 use diagnostic;
 use parse::lexer::{is_whitespace, get_str_from, reader};
 use parse::lexer::{StringReader, bump, is_eof, nextch, TokenAndSpan};
+use parse::lexer::{is_line_non_doc_comment, is_block_non_doc_comment};
 use parse::lexer;
 use parse::token;
 use parse;
@@ -46,9 +47,9 @@ impl cmnt_style : cmp::Eq {
 pub type cmnt = {style: cmnt_style, lines: ~[~str], pos: BytePos};
 
 pub fn is_doc_comment(s: ~str) -> bool {
-    s.starts_with(~"///") ||
+    (s.starts_with(~"///") && !is_line_non_doc_comment(s)) ||
     s.starts_with(~"//!") ||
-    s.starts_with(~"/**") ||
+    (s.starts_with(~"/**") && !is_block_non_doc_comment(s)) ||
     s.starts_with(~"/*!")
 }
 
@@ -231,47 +232,56 @@ fn read_block_comment(rdr: @mut StringReader,
     bump(rdr);
     bump(rdr);
 
+    let mut curr_line = ~"/*";
+
     // doc-comments are not really comments, they are attributes
     if rdr.curr == '*' || rdr.curr == '!' {
         while !(rdr.curr == '*' && nextch(rdr) == '/') && !is_eof(rdr) {
+            str::push_char(&mut curr_line, rdr.curr);
             bump(rdr);
         }
         if !is_eof(rdr) {
+            curr_line += ~"*/";
             bump(rdr);
             bump(rdr);
         }
-        return;
-    }
-
-    let mut curr_line = ~"/*";
-    let mut level: int = 1;
-    while level > 0 {
-        debug!("=== block comment level %d", level);
-        if is_eof(rdr) {(rdr as reader).fatal(~"unterminated block comment");}
-        if rdr.curr == '\n' {
-            trim_whitespace_prefix_and_push_line(&mut lines, curr_line, col);
-            curr_line = ~"";
-            bump(rdr);
-        } else {
-            str::push_char(&mut curr_line, rdr.curr);
-            if rdr.curr == '/' && nextch(rdr) == '*' {
-                bump(rdr);
+        if !is_block_non_doc_comment(curr_line) { return; }
+        assert !curr_line.contains_char('\n');
+        lines.push(curr_line);
+    } else {
+        let mut level: int = 1;
+        while level > 0 {
+            debug!("=== block comment level %d", level);
+            if is_eof(rdr) {
+                (rdr as reader).fatal(~"unterminated block comment");
+            }
+            if rdr.curr == '\n' {
+                trim_whitespace_prefix_and_push_line(&mut lines, curr_line,
+                                                     col);
+                curr_line = ~"";
                 bump(rdr);
-                curr_line += ~"*";
-                level += 1;
             } else {
-                if rdr.curr == '*' && nextch(rdr) == '/' {
+                str::push_char(&mut curr_line, rdr.curr);
+                if rdr.curr == '/' && nextch(rdr) == '*' {
                     bump(rdr);
                     bump(rdr);
-                    curr_line += ~"/";
-                    level -= 1;
-                } else { bump(rdr); }
+                    curr_line += ~"*";
+                    level += 1;
+                } else {
+                    if rdr.curr == '*' && nextch(rdr) == '/' {
+                        bump(rdr);
+                        bump(rdr);
+                        curr_line += ~"/";
+                        level -= 1;
+                    } else { bump(rdr); }
+                }
             }
         }
+        if str::len(curr_line) != 0 {
+            trim_whitespace_prefix_and_push_line(&mut lines, curr_line, col);
+        }
     }
-    if str::len(curr_line) != 0 {
-        trim_whitespace_prefix_and_push_line(&mut lines, curr_line, col);
-    }
+
     let mut style = if code_to_the_left { trailing } else { isolated };
     consume_non_eol_whitespace(rdr);
     if !is_eof(rdr) && rdr.curr != '\n' && vec::len(lines) == 1u {