Revert "Replace `pcre` with Rust-implemented regex crate (based on RE2)."
authorJoel Martin <github@martintribe.org>
Fri, 6 Mar 2015 05:14:56 +0000 (23:14 -0600)
committerJoel Martin <github@martintribe.org>
Fri, 6 Mar 2015 05:14:56 +0000 (23:14 -0600)
rust/Cargo.toml
rust/src/lib.rs
rust/src/reader.rs

index c7c9519..da6cdb7 100644 (file)
@@ -8,3 +8,6 @@ authors = [ "Your name <you@example.com>" ]
 time = "0.1"
 regex = "0.1"
 libc = "0.1"
+
+[dependencies.pcre]
+git = "https://github.com/alexcrichton/rust-pcre"
index 63fab44..04eda85 100644 (file)
@@ -1,6 +1,7 @@
 #![feature(io, fs, core, std_misc, collections)]
 
 extern crate libc;
+extern crate pcre;
 extern crate regex;
 extern crate time;
 
index 94093db..4750c46 100644 (file)
@@ -1,8 +1,8 @@
-use std::borrow::ToOwned;
 use types::MalError::{ErrString, ErrMalVal};
 use types::{MalVal, MalRet,
             _nil, _true, _false, _int, symbol, string, list, vector, hash_mapv,
             err_str, err_string, err_val};
+use pcre::Pcre;
 use super::printer::unescape_str;
 
 #[derive(Debug, Clone)]
@@ -31,12 +31,21 @@ impl Reader {
 
 fn tokenize(str: String) -> Vec<String> {
     let mut results = vec![];
-    let re = regex!(r###"[\s,]*(~@|[\[\]{}()'`~^@]|"(?:\\.|[^\\"])*"|;.*|[^\s\[\]{}('"`,;)]*)"###);
-    for cap in re.captures_iter(&str) {
-        let group = cap.at(1).unwrap_or("");
-        if group == "" { break; }
-        if group.starts_with(";") { continue; }
-        results.push(group.to_owned());
+
+    let re = match Pcre::compile(r###"[\s,]*(~@|[\[\]{}()'`~^@]|"(?:\\.|[^\\"])*"|;.*|[^\s\[\]{}('"`,;)]*)"###) {
+        Err(_) => { panic!("failed to compile regex") },
+        Ok(re) => re
+    };
+
+    let mut it = re.matches(&str);
+    loop {
+        let opt_m = it.next();
+        if opt_m.is_none() { break; }
+        let m = opt_m.unwrap();
+        if m.group(1) == "" { break; }
+        if m.group(1).starts_with(";") { continue; }
+
+        results.push((*m.group(1)).to_string());
     }
     results
 }