From 55a253cbce32b854e4f062798aa90989d4bcda79 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Thu, 5 Mar 2015 23:22:56 -0600 Subject: Revert "Revert "Replace `pcre` with Rust-implemented regex crate (based on RE2)."" This reverts commit 30794b71110f6c3cbd8f446de6acab3954f6555c. --- rust/src/reader.rs | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'rust/src/reader.rs') 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 { 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 } -- cgit v1.2.3