about summary refs log tree commit diff
path: root/src/compiletest/errors.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-01-20 10:45:29 -0800
committerAlex Crichton <alex@alexcrichton.com>2015-01-23 21:04:10 -0800
commit6c29708bf906fa9075bb96b76fd7f6cc81eda43c (patch)
treef34f763e8ee24bba284b7902496d370667e2a1f5 /src/compiletest/errors.rs
parent494896f2dd4ff541c371a8952b8f38cb02409835 (diff)
downloadrust-6c29708bf906fa9075bb96b76fd7f6cc81eda43c.tar.gz
rust-6c29708bf906fa9075bb96b76fd7f6cc81eda43c.zip
regex: Remove in-tree version
The regex library was largely used for non-critical aspects of the compiler and
various external tooling. The library at this point is duplicated with its
out-of-tree counterpart and as such imposes a bit of a maintenance overhead as
well as compile time hit for the compiler itself.

The last major user of the regex library is the libtest library, using regexes
for filters when running tests. This removal means that the filtering has gone
back to substring matching rather than using regexes.
Diffstat (limited to 'src/compiletest/errors.rs')
-rw-r--r--src/compiletest/errors.rs73
1 files changed, 38 insertions, 35 deletions
diff --git a/src/compiletest/errors.rs b/src/compiletest/errors.rs
index dcfac688c7f..fc815d66a4d 100644
--- a/src/compiletest/errors.rs
+++ b/src/compiletest/errors.rs
@@ -9,9 +9,7 @@
 // except according to those terms.
 use self::WhichLine::*;
 
-use std::ascii::AsciiExt;
 use std::io::{BufferedReader, File};
-use regex::Regex;
 
 pub struct ExpectedError {
     pub line: uint,
@@ -19,6 +17,9 @@ pub struct ExpectedError {
     pub msg: String,
 }
 
+#[derive(PartialEq, Show)]
+enum WhichLine { ThisLine, FollowPrevious(uint), AdjustBackward(uint) }
+
 /// Looks for either "//~| KIND MESSAGE" or "//~^^... KIND MESSAGE"
 /// The former is a "follow" that inherits its target from the preceding line;
 /// the latter is an "adjusts" that goes that many lines up.
@@ -26,15 +27,8 @@ pub struct ExpectedError {
 /// Goal is to enable tests both like: //~^^^ ERROR go up three
 /// and also //~^ ERROR message one for the preceding line, and
 ///          //~| ERROR message two for that same line.
-
-pub static EXPECTED_PATTERN : &'static str =
-    r"//~(?P<follow>\|)?(?P<adjusts>\^*)\s*(?P<kind>\S*)\s*(?P<msg>.*)";
-
-#[derive(PartialEq, Show)]
-enum WhichLine { ThisLine, FollowPrevious(uint), AdjustBackward(uint) }
-
 // Load any test directives embedded in the file
-pub fn load_errors(re: &Regex, testfile: &Path) -> Vec<ExpectedError> {
+pub fn load_errors(testfile: &Path) -> Vec<ExpectedError> {
     let mut rdr = BufferedReader::new(File::open(testfile).unwrap());
 
     // `last_nonfollow_error` tracks the most recently seen
@@ -50,7 +44,7 @@ pub fn load_errors(re: &Regex, testfile: &Path) -> Vec<ExpectedError> {
     rdr.lines().enumerate().filter_map(|(line_no, ln)| {
         parse_expected(last_nonfollow_error,
                        line_no + 1,
-                       ln.unwrap().as_slice(), re)
+                       ln.unwrap().as_slice())
             .map(|(which, error)| {
                 match which {
                     FollowPrevious(_) => {}
@@ -63,30 +57,39 @@ pub fn load_errors(re: &Regex, testfile: &Path) -> Vec<ExpectedError> {
 
 fn parse_expected(last_nonfollow_error: Option<uint>,
                   line_num: uint,
-                  line: &str,
-                  re: &Regex) -> Option<(WhichLine, ExpectedError)> {
-    re.captures(line).and_then(|caps| {
-        let adjusts = caps.name("adjusts").unwrap_or("").len();
-        let kind = caps.name("kind").unwrap_or("").to_ascii_lowercase();
-        let msg = caps.name("msg").unwrap_or("").trim().to_string();
-        let follow = caps.name("follow").unwrap_or("").len() > 0;
+                  line: &str) -> Option<(WhichLine, ExpectedError)> {
+    let start = match line.find_str("//~") { Some(i) => i, None => return None };
+    let (follow, adjusts) = if line.char_at(start + 3) == '|' {
+        (true, 0)
+    } else {
+        (false, line[start + 3..].chars().take_while(|c| *c == '^').count())
+    };
+    let kind_start = start + 3 + adjusts + (follow as usize);
+    let letters = line[kind_start..].chars();
+    let kind = letters.skip_while(|c| c.is_whitespace())
+                      .take_while(|c| !c.is_whitespace())
+                      .map(|c| c.to_lowercase())
+                      .collect::<String>();
+    let letters = line[kind_start..].chars();
+    let msg = letters.skip_while(|c| c.is_whitespace())
+                     .skip_while(|c| !c.is_whitespace())
+                     .collect::<String>().trim().to_string();
 
-        let (which, line) = if follow {
-            assert!(adjusts == 0, "use either //~| or //~^, not both.");
-            let line = last_nonfollow_error.unwrap_or_else(|| {
-                panic!("encountered //~| without preceding //~^ line.")
-            });
-            (FollowPrevious(line), line)
-        } else {
-            let which =
-                if adjusts > 0 { AdjustBackward(adjusts) } else { ThisLine };
-            let line = line_num - adjusts;
-            (which, line)
-        };
+    let (which, line) = if follow {
+        assert!(adjusts == 0, "use either //~| or //~^, not both.");
+        let line = last_nonfollow_error.unwrap_or_else(|| {
+            panic!("encountered //~| without preceding //~^ line.")
+        });
+        (FollowPrevious(line), line)
+    } else {
+        let which =
+            if adjusts > 0 { AdjustBackward(adjusts) } else { ThisLine };
+        let line = line_num - adjusts;
+        (which, line)
+    };
 
-        debug!("line={} which={:?} kind={:?} msg={:?}", line_num, which, kind, msg);
-        Some((which, ExpectedError { line: line,
-                                     kind: kind,
-                                     msg: msg, }))
-    })
+    debug!("line={} which={:?} kind={:?} msg={:?}", line_num, which, kind, msg);
+    Some((which, ExpectedError { line: line,
+                                 kind: kind,
+                                 msg: msg, }))
 }