[Gd-chatter] r11607 - in trunk/libraries/regular-expressions: . tests

cgay at gwydiondylan.org cgay at gwydiondylan.org
Sat Jan 5 15:01:47 CET 2008


Author: cgay
Date: Sat Jan  5 15:01:46 2008
New Revision: 11607

Modified:
   trunk/libraries/regular-expressions/parse.dylan
   trunk/libraries/regular-expressions/tests/regular-expressions-test-suite.dylan
Log:
Job: 7357
Fix bug turbo found.  Wasn't keeping track of current-group-number
correctly.

Modified: trunk/libraries/regular-expressions/parse.dylan
==============================================================================
--- trunk/libraries/regular-expressions/parse.dylan	(original)
+++ trunk/libraries/regular-expressions/parse.dylan	Sat Jan  5 15:01:46 2008
@@ -496,6 +496,9 @@
   if (save-group?)
     info.current-group-number := info.current-group-number + 1;
   end;
+  // Save the group number since it might be incremented while parsing
+  // the regex contained in this group.
+  let this-group-number = info.current-group-number;
   let regex = if (lookahead(str) == ')')
                 consume(str);
                 $empty-string
@@ -518,7 +521,7 @@
         info.group-number-to-name[info.current-group-number] := group-name;
       end;
     end;
-    make(<mark>, child: regex, group: info.current-group-number)
+    make(<mark>, child: regex, group: this-group-number)
   end if
 end function parse-simple-group;
 

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	Sat Jan  5 15:01:46 2008
@@ -29,11 +29,17 @@
   check-equal("atom-tan", "\<44>\<79>\<6c>\<61>\<6e>", "Dylan");
 end;
 
+// Note that flags must come at the end of groups-and-flags.
 define function check-matches
     (pattern, input-string, #rest groups-and-flags) => ()
   let string? = rcurry(instance?, <string>);
-  let groups = choose(string?, groups-and-flags);
-  let flags = choose(complement(string?), groups-and-flags);
+  let groups = groups-and-flags;
+  let flags = #[];
+  let flags-start = find-key(groups-and-flags, rcurry(instance?, <symbol>));
+  if (flags-start)
+    flags := copy-sequence(groups-and-flags, start: flags-start);
+    groups := copy-sequence(groups-and-flags, end: flags-start);
+  end;
   let regex = apply(compile-regex, pattern, flags);
   let match = regex-search(regex, input-string);
   if (empty?(groups))
@@ -64,6 +70,13 @@
   check-matches(".", "x", "x");
   check-matches(".", "\n", "\n", dot-matches-all: #t);
   check-matches("[a-]", "-", "-");
+  check-matches("(x)y", "xy", "xy", "x");
+  check-matches("((x)y)", "xy", "xy", "xy", "x");
+  check-matches("^(([^:/?#]+):)?(//((([^/?#]*)@)?([^/?#:]*)(:([^/?#]*))?))?([^?#]*)(\\?([^#]*))?(#(.*))?",
+                "http://localhost/",
+                // groups...
+                "http://localhost/", "http:", "http", "//localhost", "localhost",
+                #f, #f, "localhost", #f, #f, "/", #f, #f, #f)
 end test ad-hoc-regex-test;
 
 // All these regexes should signal <invalid-regex> on compilation.



More information about the chatter mailing list