diff options
| author | Joel Martin <github@martintribe.org> | 2015-03-05 23:09:34 -0600 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2015-03-05 23:09:34 -0600 |
| commit | a6b7d1334b329817077fa3123b5b081c3c21a4d4 (patch) | |
| tree | 2b484792a265b1f785465f6ae8c366e7dc6a4419 | |
| parent | 9106a221b8fa2c06ab7d66e54c0f9c9b6efa3ba6 (diff) | |
| parent | 9522f103b34a5c35cd0a004f55afe6cc0194a435 (diff) | |
| download | mal-a6b7d1334b329817077fa3123b5b081c3c21a4d4.tar.gz mal-a6b7d1334b329817077fa3123b5b081c3c21a4d4.zip | |
Merge pull request #28 from BurntSushi/master
Replace `pcre` with Rust-implemented regex crate (based on RE2).
| -rw-r--r-- | rust/Cargo.toml | 3 | ||||
| -rw-r--r-- | rust/src/lib.rs | 1 | ||||
| -rw-r--r-- | rust/src/reader.rs | 23 |
3 files changed, 7 insertions, 20 deletions
diff --git a/rust/Cargo.toml b/rust/Cargo.toml index da6cdb7..c7c9519 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -8,6 +8,3 @@ authors = [ "Your name <you@example.com>" ] time = "0.1" regex = "0.1" libc = "0.1" - -[dependencies.pcre] -git = "https://github.com/alexcrichton/rust-pcre" diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 04eda85..63fab44 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -1,7 +1,6 @@ #![feature(io, fs, core, std_misc, collections)] extern crate libc; -extern crate pcre; extern crate regex; extern crate time; diff --git a/rust/src/reader.rs b/rust/src/reader.rs index 4750c46..94093db 100644 --- a/rust/src/reader.rs +++ b/rust/src/reader.rs @@ -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,21 +31,12 @@ impl Reader { fn tokenize(str: String) -> Vec<String> { let mut results = vec![]; - - 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()); + 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()); } results } |
