about summary refs log tree commit diff
path: root/src/libsyntax/parse/comments.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-03-02 08:31:33 -0800
committerbors <bors@rust-lang.org>2014-03-02 08:31:33 -0800
commit910012aabae3dfd4b7190f46e88cde75804b5cb0 (patch)
treeac07696b5bb7a8ba6dacd1b2abd3926b59621058 /src/libsyntax/parse/comments.rs
parentbaf79083aedb8ae64efddbcf28b358841cfd1157 (diff)
parent355932407ba324d33cd9353a69203f7f76c059a6 (diff)
downloadrust-910012aabae3dfd4b7190f46e88cde75804b5cb0.tar.gz
rust-910012aabae3dfd4b7190f46e88cde75804b5cb0.zip
auto merge of #12637 : pcwalton/rust/devecing, r=alexcrichton
r? @alexcrichton
Diffstat (limited to 'src/libsyntax/parse/comments.rs')
-rw-r--r--src/libsyntax/parse/comments.rs47
1 files changed, 24 insertions, 23 deletions
diff --git a/src/libsyntax/parse/comments.rs b/src/libsyntax/parse/comments.rs
index bd1c4f9babb..c2a2097de24 100644
--- a/src/libsyntax/parse/comments.rs
+++ b/src/libsyntax/parse/comments.rs
@@ -20,6 +20,7 @@ use parse::token;
 use std::io;
 use std::str;
 use std::uint;
+use std::vec_ng::Vec;
 
 #[deriving(Clone, Eq)]
 pub enum CommentStyle {
@@ -32,7 +33,7 @@ pub enum CommentStyle {
 #[deriving(Clone)]
 pub struct Comment {
     style: CommentStyle,
-    lines: ~[~str],
+    lines: Vec<~str> ,
     pos: BytePos
 }
 
@@ -54,28 +55,28 @@ pub fn doc_comment_style(comment: &str) -> ast::AttrStyle {
 
 pub fn strip_doc_comment_decoration(comment: &str) -> ~str {
     /// remove whitespace-only lines from the start/end of lines
-    fn vertical_trim(lines: ~[~str]) -> ~[~str] {
+    fn vertical_trim(lines: Vec<~str> ) -> Vec<~str> {
         let mut i = 0u;
         let mut j = lines.len();
         // first line of all-stars should be omitted
-        if lines.len() > 0 && lines[0].chars().all(|c| c == '*') {
+        if lines.len() > 0 && lines.get(0).chars().all(|c| c == '*') {
             i += 1;
         }
-        while i < j && lines[i].trim().is_empty() {
+        while i < j && lines.get(i).trim().is_empty() {
             i += 1;
         }
         // like the first, a last line of all stars should be omitted
-        if j > i && lines[j - 1].chars().skip(1).all(|c| c == '*') {
+        if j > i && lines.get(j - 1).chars().skip(1).all(|c| c == '*') {
             j -= 1;
         }
-        while j > i && lines[j - 1].trim().is_empty() {
+        while j > i && lines.get(j - 1).trim().is_empty() {
             j -= 1;
         }
-        return lines.slice(i, j).to_owned();
+        return lines.slice(i, j).iter().map(|x| (*x).clone()).collect();
     }
 
     /// remove a "[ \t]*\*" block from each line, if possible
-    fn horizontal_trim(lines: ~[~str]) -> ~[~str] {
+    fn horizontal_trim(lines: Vec<~str> ) -> Vec<~str> {
         let mut i = uint::MAX;
         let mut can_trim = true;
         let mut first = true;
@@ -122,7 +123,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> ~str {
         let lines = comment.slice(3u, comment.len() - 2u)
             .lines_any()
             .map(|s| s.to_owned())
-            .collect::<~[~str]>();
+            .collect::<Vec<~str> >();
 
         let lines = vertical_trim(lines);
         let lines = horizontal_trim(lines);
@@ -157,9 +158,9 @@ fn consume_non_eol_whitespace(rdr: &StringReader) {
     }
 }
 
-fn push_blank_line_comment(rdr: &StringReader, comments: &mut ~[Comment]) {
+fn push_blank_line_comment(rdr: &StringReader, comments: &mut Vec<Comment> ) {
     debug!(">>> blank-line comment");
-    let v: ~[~str] = ~[];
+    let v: Vec<~str> = Vec::new();
     comments.push(Comment {
         style: BlankLine,
         lines: v,
@@ -168,7 +169,7 @@ fn push_blank_line_comment(rdr: &StringReader, comments: &mut ~[Comment]) {
 }
 
 fn consume_whitespace_counting_blank_lines(rdr: &StringReader,
-                                           comments: &mut ~[Comment]) {
+                                           comments: &mut Vec<Comment> ) {
     while is_whitespace(rdr.curr.get()) && !is_eof(rdr) {
         if rdr.col.get() == CharPos(0u) && rdr.curr_is('\n') {
             push_blank_line_comment(rdr, &mut *comments);
@@ -179,22 +180,22 @@ fn consume_whitespace_counting_blank_lines(rdr: &StringReader,
 
 
 fn read_shebang_comment(rdr: &StringReader, code_to_the_left: bool,
-                                            comments: &mut ~[Comment]) {
+                                            comments: &mut Vec<Comment> ) {
     debug!(">>> shebang comment");
     let p = rdr.last_pos.get();
     debug!("<<< shebang comment");
     comments.push(Comment {
         style: if code_to_the_left { Trailing } else { Isolated },
-        lines: ~[read_one_line_comment(rdr)],
+        lines: vec!(read_one_line_comment(rdr)),
         pos: p
     });
 }
 
 fn read_line_comments(rdr: &StringReader, code_to_the_left: bool,
-                                          comments: &mut ~[Comment]) {
+                                          comments: &mut Vec<Comment> ) {
     debug!(">>> line comments");
     let p = rdr.last_pos.get();
-    let mut lines: ~[~str] = ~[];
+    let mut lines: Vec<~str> = Vec::new();
     while rdr.curr_is('/') && nextch_is(rdr, '/') {
         let line = read_one_line_comment(rdr);
         debug!("{}", line);
@@ -232,7 +233,7 @@ fn all_whitespace(s: &str, col: CharPos) -> Option<uint> {
     return Some(cursor);
 }
 
-fn trim_whitespace_prefix_and_push_line(lines: &mut ~[~str],
+fn trim_whitespace_prefix_and_push_line(lines: &mut Vec<~str> ,
                                         s: ~str, col: CharPos) {
     let len = s.len();
     let s1 = match all_whitespace(s, col) {
@@ -249,10 +250,10 @@ fn trim_whitespace_prefix_and_push_line(lines: &mut ~[~str],
 
 fn read_block_comment(rdr: &StringReader,
                       code_to_the_left: bool,
-                      comments: &mut ~[Comment]) {
+                      comments: &mut Vec<Comment> ) {
     debug!(">>> block comment");
     let p = rdr.last_pos.get();
-    let mut lines: ~[~str] = ~[];
+    let mut lines: Vec<~str> = Vec::new();
     let col: CharPos = rdr.col.get();
     bump(rdr);
     bump(rdr);
@@ -324,7 +325,7 @@ fn peeking_at_comment(rdr: &StringReader) -> bool {
 
 fn consume_comment(rdr: &StringReader,
                    code_to_the_left: bool,
-                   comments: &mut ~[Comment]) {
+                   comments: &mut Vec<Comment> ) {
     debug!(">>> consume comment");
     if rdr.curr_is('/') && nextch_is(rdr, '/') {
         read_line_comments(rdr, code_to_the_left, comments);
@@ -348,15 +349,15 @@ pub fn gather_comments_and_literals(span_diagnostic:
                                         @diagnostic::SpanHandler,
                                     path: ~str,
                                     srdr: &mut io::Reader)
-                                 -> (~[Comment], ~[Literal]) {
+                                 -> (Vec<Comment> , Vec<Literal> ) {
     let src = srdr.read_to_end().unwrap();
     let src = str::from_utf8_owned(src).unwrap();
     let cm = CodeMap::new();
     let filemap = cm.new_filemap(path, src);
     let rdr = lexer::new_low_level_string_reader(span_diagnostic, filemap);
 
-    let mut comments: ~[Comment] = ~[];
-    let mut literals: ~[Literal] = ~[];
+    let mut comments: Vec<Comment> = Vec::new();
+    let mut literals: Vec<Literal> = Vec::new();
     let mut first_read: bool = true;
     while !is_eof(&rdr) {
         loop {