summary refs log tree commit diff
path: root/src/rustbook
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2015-01-24 09:15:42 -0800
committerBrian Anderson <banderson@mozilla.com>2015-01-25 01:20:55 -0800
commit63fcbcf3ce8f0ca391c18b2d61833ae6beb3ac70 (patch)
treec732033c0822f25f2aebcdf193de1b257bac1855 /src/rustbook
parentb44ee371b8beea77aa1364460acbba14a8516559 (diff)
parent0430a43d635841db44978bb648e9cf7e7cfa1bba (diff)
downloadrust-63fcbcf3ce8f0ca391c18b2d61833ae6beb3ac70.tar.gz
rust-63fcbcf3ce8f0ca391c18b2d61833ae6beb3ac70.zip
Merge remote-tracking branch 'rust-lang/master'
Conflicts:
	mk/tests.mk
	src/liballoc/arc.rs
	src/liballoc/boxed.rs
	src/liballoc/rc.rs
	src/libcollections/bit.rs
	src/libcollections/btree/map.rs
	src/libcollections/btree/set.rs
	src/libcollections/dlist.rs
	src/libcollections/ring_buf.rs
	src/libcollections/slice.rs
	src/libcollections/str.rs
	src/libcollections/string.rs
	src/libcollections/vec.rs
	src/libcollections/vec_map.rs
	src/libcore/any.rs
	src/libcore/array.rs
	src/libcore/borrow.rs
	src/libcore/error.rs
	src/libcore/fmt/mod.rs
	src/libcore/iter.rs
	src/libcore/marker.rs
	src/libcore/ops.rs
	src/libcore/result.rs
	src/libcore/slice.rs
	src/libcore/str/mod.rs
	src/libregex/lib.rs
	src/libregex/re.rs
	src/librustc/lint/builtin.rs
	src/libstd/collections/hash/map.rs
	src/libstd/collections/hash/set.rs
	src/libstd/sync/mpsc/mod.rs
	src/libstd/sync/mutex.rs
	src/libstd/sync/poison.rs
	src/libstd/sync/rwlock.rs
	src/libsyntax/feature_gate.rs
	src/libsyntax/test.rs
Diffstat (limited to 'src/rustbook')
-rw-r--r--src/rustbook/book.rs85
-rw-r--r--src/rustbook/build.rs7
-rw-r--r--src/rustbook/main.rs3
3 files changed, 45 insertions, 50 deletions
diff --git a/src/rustbook/book.rs b/src/rustbook/book.rs
index 20346449fd1..3047e93137f 100644
--- a/src/rustbook/book.rs
+++ b/src/rustbook/book.rs
@@ -13,7 +13,6 @@
 use std::io::BufferedReader;
 use std::iter;
 use std::iter::AdditiveIterator;
-use regex::Regex;
 
 pub struct BookItem {
     pub title: String,
@@ -94,8 +93,6 @@ pub fn parse_summary<R: Reader>(input: R, src: &Path) -> Result<Book, Vec<String
         }
     }
 
-    let regex = r"(?P<indent>[\t ]*)\*[:space:]*\[(?P<title>.*)\]\((?P<path>.*)\)";
-    let item_re = Regex::new(regex).unwrap();
     let mut top_items = vec!();
     let mut stack = vec!();
     let mut errors = vec!();
@@ -117,45 +114,51 @@ pub fn parse_summary<R: Reader>(input: R, src: &Path) -> Result<Book, Vec<String
             }
         };
 
-        item_re.captures(&line[]).map(|cap| {
-            let given_path = cap.name("path");
-            let title = cap.name("title").unwrap().to_string();
-
-            let path_from_root = match src.join(given_path.unwrap()).path_relative_from(src) {
-                Some(p) => p,
-                None => {
-                    errors.push(format!("paths in SUMMARY.md must be relative, \
-                                         but path '{}' for section '{}' is not.",
-                                         given_path.unwrap(), title));
-                    Path::new("")
-                }
-            };
-            let path_to_root = Path::new(iter::repeat("../")
-                                             .take(path_from_root.components().count() - 1)
-                                             .collect::<String>());
-            let item = BookItem {
-                title: title,
-                path: path_from_root,
-                path_to_root: path_to_root,
-                children: vec!(),
-            };
-            let level = cap.name("indent").unwrap().chars().map(|c| {
-                match c {
-                    ' ' => 1us,
-                    '\t' => 4,
-                    _ => unreachable!()
-                }
-            }).sum() / 4 + 1;
-
-            if level > stack.len() + 1 {
-                errors.push(format!("section '{}' is indented too deeply; \
-                                     found {}, expected {} or less",
-                                    item.title, level, stack.len() + 1));
-            } else if level <= stack.len() {
-                collapse(&mut stack, &mut top_items, level);
+        let star_idx = match line.find_str("*") { Some(i) => i, None => continue };
+
+        let start_bracket = star_idx + line[star_idx..].find_str("[").unwrap();
+        let end_bracket = start_bracket + line[start_bracket..].find_str("](").unwrap();
+        let start_paren = end_bracket + 1;
+        let end_paren = start_paren + line[start_paren..].find_str(")").unwrap();
+
+        let given_path = &line[start_paren + 1 .. end_paren];
+        let title = line[start_bracket + 1..end_bracket].to_string();
+        let indent = &line[..star_idx];
+
+        let path_from_root = match src.join(given_path).path_relative_from(src) {
+            Some(p) => p,
+            None => {
+                errors.push(format!("paths in SUMMARY.md must be relative, \
+                                     but path '{}' for section '{}' is not.",
+                                     given_path, title));
+                Path::new("")
             }
-            stack.push(item)
-        });
+        };
+        let path_to_root = Path::new(iter::repeat("../")
+                                         .take(path_from_root.components().count() - 1)
+                                         .collect::<String>());
+        let item = BookItem {
+            title: title,
+            path: path_from_root,
+            path_to_root: path_to_root,
+            children: vec!(),
+        };
+        let level = indent.chars().map(|c| {
+            match c {
+                ' ' => 1us,
+                '\t' => 4,
+                _ => unreachable!()
+            }
+        }).sum() / 4 + 1;
+
+        if level > stack.len() + 1 {
+            errors.push(format!("section '{}' is indented too deeply; \
+                                 found {}, expected {} or less",
+                                item.title, level, stack.len() + 1));
+        } else if level <= stack.len() {
+            collapse(&mut stack, &mut top_items, level);
+        }
+        stack.push(item)
     }
 
     if errors.is_empty() {
diff --git a/src/rustbook/build.rs b/src/rustbook/build.rs
index 50a6ad43aee..93601c0f61b 100644
--- a/src/rustbook/build.rs
+++ b/src/rustbook/build.rs
@@ -22,8 +22,6 @@ use book::{Book, BookItem};
 use css;
 use javascript;
 
-use regex::Regex;
-
 use rustdoc;
 
 struct Build;
@@ -81,9 +79,6 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> {
 
         let out_path = tgt.join(item.path.dirname());
 
-        let regex = r"\[(?P<title>[^]]*)\]\((?P<url_stem>[^)]*)\.(?P<ext>md|markdown)\)";
-        let md_urls = Regex::new(regex).unwrap();
-
         let src;
         if os::args().len() < 3 {
             src = os::getcwd().unwrap().clone();
@@ -94,7 +89,7 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> {
         let markdown_data = try!(File::open(&src.join(&item.path)).read_to_string());
         let preprocessed_path = tmp.path().join(item.path.filename().unwrap());
         {
-            let urls = md_urls.replace_all(&markdown_data[], "[$title]($url_stem.html)");
+            let urls = markdown_data.replace(".md)", ".html)");
             try!(File::create(&preprocessed_path)
                       .write_str(&urls[]));
         }
diff --git a/src/rustbook/main.rs b/src/rustbook/main.rs
index 6d9078c6687..3e571bad09c 100644
--- a/src/rustbook/main.rs
+++ b/src/rustbook/main.rs
@@ -14,11 +14,8 @@
 #![feature(io)]
 #![feature(os)]
 #![feature(path)]
-#![feature(rustc_private)]
 #![feature(rustdoc)]
 
-extern crate regex;
-
 extern crate rustdoc;
 
 use std::os;