[Gd-chatter] r11647 - in trunk/libraries: regular-expressions regular-expressions/tests strings strings/tests

cgay at gwydiondylan.org cgay at gwydiondylan.org
Sun Jan 20 16:47:32 CET 2008


Author: cgay
Date: Sun Jan 20 16:47:31 2008
New Revision: 11647

Modified:
   trunk/libraries/regular-expressions/regex.dylan
   trunk/libraries/regular-expressions/tests/regular-expressions-test-suite.dylan
   trunk/libraries/strings/library.dylan
   trunk/libraries/strings/strings.dylan
   trunk/libraries/strings/tests/library.dylan
   trunk/libraries/strings/tests/strings-test-suite.dylan
Log:
job: minor
Added split method for <regex>, with a minimal amount of testing.
Fixed bug in regular-expressions related to start:/end: arguments.

Modified: trunk/libraries/regular-expressions/regex.dylan
==============================================================================
--- trunk/libraries/regular-expressions/regex.dylan	(original)
+++ trunk/libraries/regular-expressions/regex.dylan	Sun Jan 20 16:47:31 2008
@@ -115,13 +115,11 @@
       let bpos = marks[index];
       let epos = marks[index + 1];
       if (bpos & epos)
-        // It would be nice to make <substring> a real sequence, and possibly unify
-        // it with the substring implementation in Koala.
-        let text = copy-sequence(substring.entire-string,
-                                 start: substring.start-index + bpos,
-                                 end: substring.start-index + epos);
         add-group(regex-match,
-                  make(<match-group>, text: text, start: bpos, end: epos),
+                  make(<match-group>,
+                       text: copy-sequence(string, start: bpos, end: epos),
+                       start: bpos,
+                       end: epos),
                   group-name);
       else
         // This group wasn't matched.

Modified: trunk/libraries/regular-expressions/tests/regular-expressions-test-suite.dylan
==============================================================================
--- trunk/libraries/regular-expressions/tests/regular-expressions-test-suite.dylan	(original)
+++ trunk/libraries/regular-expressions/tests/regular-expressions-test-suite.dylan	Sun Jan 20 16:47:31 2008
@@ -76,7 +76,16 @@
                 "http://localhost/",
                 // groups...
                 "http://localhost/", "http:", "http", "//localhost", "localhost",
-                #f, #f, "localhost", #f, #f, "/", #f, #f, #f)
+                #f, #f, "localhost", #f, #f, "/", #f, #f, #f);
+  check-equal("start: works?",
+              regex-search("a", "a b c", start: 1),
+              #f);
+  check-equal("end: works?",
+              regex-search("c", "a b c", end: 4),
+              #f);
+  check-equal("start: and end: work?",
+              regex-search("a", "a b a", start: 1, end: 4),
+              #f);
 end test ad-hoc-regex-test;
 
 // All these regexes should signal <invalid-regex> on compilation.

Modified: trunk/libraries/strings/library.dylan
==============================================================================
--- trunk/libraries/strings/library.dylan	(original)
+++ trunk/libraries/strings/library.dylan	Sun Jan 20 16:47:31 2008
@@ -10,6 +10,7 @@
     import: { streams };
   use string-extensions,
     import: { string-hacking };
+  use regular-expressions;
   export strings;
 end;
 
@@ -84,7 +85,6 @@
 // Implementation module
 //
 define module strings-implementation
-
   use strings;            // Use API module
   use common-dylan,
     exclude: { split };
@@ -100,4 +100,10 @@
               <case-sensitive-character-set>,
               <case-insensitive-character-set>,
               <byte-character-table> };
+  use regular-expressions,
+    import: { <regex>,
+              regex-search,
+              match-group,
+              group-start,
+              group-end };
 end module strings-implementation;

Modified: trunk/libraries/strings/strings.dylan
==============================================================================
--- trunk/libraries/strings/strings.dylan	(original)
+++ trunk/libraries/strings/strings.dylan	Sun Jan 20 16:47:31 2008
@@ -813,7 +813,6 @@
   end
 end method join;
 
-
 // In common-dylan library...
 // Split a sequence into parts at each occurrance of the 'separator'
 // and return a sequence containing the parts.  The sequence is
@@ -935,7 +934,6 @@
 end method split;
 
 // In regular-expressions library
-/*
 define method split
     (seq :: <string>, separator :: <regex>,
      #key start :: <integer> = 0,
@@ -947,15 +945,14 @@
                            epos :: false-or(<integer>))
           let match = regex-search(separator, seq, start: bpos, end: epos);
           if (match)
-            let group0 = match-group(match, 0);
-            values(group0.group-start, group0.group-end);
+            let (ignore, match-start, match-end) = match-group(match, 0);
+            values(match-start, match-end)
           else
             #f
           end
         end method find-regex;
   split(seq, find-regex, start: start, end: _end, count: count);
 end method split;
-*/
 
 
 // todo -- should this be exported?

Modified: trunk/libraries/strings/tests/library.dylan
==============================================================================
--- trunk/libraries/strings/tests/library.dylan	(original)
+++ trunk/libraries/strings/tests/library.dylan	Sun Jan 20 16:47:31 2008
@@ -8,14 +8,19 @@
   use strings;
   use testworks;
   use testworks-specs;
+  use regular-expressions;
   export strings-test-suite;
 end;
 
 define module strings-test-suite
-  use common-dylan, exclude: { split };
+  use common-dylan,
+    exclude: { split };
   use strings;
   use testworks;
   use testworks-specs;
+  use regular-expressions,
+    import: { compile-regex,
+              match-group };
   export strings-test-suite;
 end;
 

Modified: trunk/libraries/strings/tests/strings-test-suite.dylan
==============================================================================
--- trunk/libraries/strings/tests/strings-test-suite.dylan	(original)
+++ trunk/libraries/strings/tests/strings-test-suite.dylan	Sun Jan 20 16:47:31 2008
@@ -265,6 +265,12 @@
   check-equal("basic start/end test",
               split("a b c d", ' ', start: 1),
               #["", "b", "c", "d"]);
+
+  // Tests for splitting on regular expressions
+  check-equal("basic regex split",
+              split("a b c", compile-regex(" ")),
+              #["a", "b", "c"]);
+
 end function-test split;
 
 define function replacement-test (mutating?)



More information about the chatter mailing list