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

cgay at gwydiondylan.org cgay at gwydiondylan.org
Wed Nov 28 05:38:41 CET 2007


Author: cgay
Date: Wed Nov 28 05:38:40 2007
New Revision: 11505

Added:
   trunk/libraries/regular-expressions/tests/regression-tests.txt   (contents, props changed)
Modified:
   trunk/libraries/regular-expressions/parse.dylan
   trunk/libraries/regular-expressions/tests/new-api-test-suite.dylan
Log:
Job: 7357
Fixed [^]] character classes.
Added regression-tests.txt, same format as pcre-testoutput1.txt.

Modified: trunk/libraries/regular-expressions/parse.dylan
==============================================================================
--- trunk/libraries/regular-expressions/parse.dylan	(original)
+++ trunk/libraries/regular-expressions/parse.dylan	Wed Nov 28 05:38:40 2007
@@ -52,17 +52,17 @@
 define abstract class <parsed-regexp> (<object>)
 end class <parsed-regexp>;
 
+define class <mark> (<parsed-regexp>)
+  slot child :: <parsed-regexp>,  required-init-keyword: #"child";
+  constant slot group-number :: <integer>, required-init-keyword: #"group";
+end class <mark>;
+
 // The root of the parsed regexp, i.e., this is what's returned by the parser.
 define class <regexp> (<mark>)
   constant slot regexp-pattern :: <string>, required-init-keyword: #"pattern";
   constant slot regexp-group-count :: <integer>, required-init-keyword: #"group-count";
 end class <regexp>;
 
-define class <mark> (<parsed-regexp>)
-  slot child :: <parsed-regexp>,  required-init-keyword: #"child";
-  constant slot group-number :: <integer>, required-init-keyword: #"group";
-end class <mark>;
-
 define class <union> (<parsed-regexp>)          //    |
   slot left  :: <parsed-regexp>, required-init-keyword: #"left";
   slot right :: <parsed-regexp>, required-init-keyword: #"right";
@@ -340,38 +340,45 @@
 // make(<character-set>) do the real parsing.
 //
 define inline function parse-character-set
-    (s :: <parse-string>, info :: <parse-info>)
+    (str :: <parse-string>, info :: <parse-info>)
  => (set :: <parsed-set>)
   let set-string = make(<deque>);
-  let start-index = s.parse-index;
+  let start-index = str.parse-index;
   local method peek ()
-          lookahead(s)
-            | parse-error(s.parse-string,
+          lookahead(str)
+            | parse-error(str.parse-string,
                           "Unterminated character set starting at at index %d.",
                           start-index);
         end;
   block (done)
     for (char = peek() then peek(),
          charset-index from 0)
-      consume(s);
-      if (char == ']')
-        if (charset-index == 0)
-          push-last(set-string, char);  // e.g., []] is the set containing ']'.
-        else
-          done();
-        end;
-      elseif (char == '\\')
-        let char2 = peek();
-        consume(s);  // Eat escaped char
-        if (char2 == ']')
-          push-last(set-string, ']');
-        else
-          push-last(set-string, '\\');
-          push-last(set-string, char2);
-        end if;
-      else
-        push-last(set-string, char);
-      end if;
+      consume(str);
+      select (char)
+        ']' =>
+          if (charset-index == 0)
+            push-last(set-string, char);  // e.g., []] is the set containing ']'
+          else
+            done();
+          end;
+        '^' =>
+          push-last(set-string, '^');
+          if (peek() == ']')
+            consume(str);
+            push-last(set-string, ']');  // e.g., [^]] is the set without ']'
+          end;
+        '\\' =>
+          let char2 = peek();
+          consume(str);  // Eat escaped char
+          if (char2 == ']')
+            push-last(set-string, ']');
+          else
+            push-last(set-string, '\\');
+            push-last(set-string, char2);
+          end if;
+        otherwise =>
+          push-last(set-string, char);
+      end select
     end for;
   end block;
   make(<parsed-set>, set: make(info.set-type, description: set-string))

Modified: trunk/libraries/regular-expressions/tests/new-api-test-suite.dylan
==============================================================================
--- trunk/libraries/regular-expressions/tests/new-api-test-suite.dylan	(original)
+++ trunk/libraries/regular-expressions/tests/new-api-test-suite.dylan	Wed Nov 28 05:38:40 2007
@@ -224,9 +224,9 @@
                                    "libraries",
                                    "regular-expressions",
                                    "tests");
-    run-pcre-checks(make(<file-locator>,
-                         directory: dir,
-                         name: "pcre-testoutput1.txt"));
+    for (filename in #("pcre-testoutput1.txt", "regression-tests.txt"))
+      run-pcre-checks(make(<file-locator>, directory: dir, name: filename));
+    end;
   else
     signal(make(<simple-error>,
                 format-string: "pcre-test requires the OPEN_DYLAN_USER_SOURCES environment "

Added: trunk/libraries/regular-expressions/tests/regression-tests.txt
==============================================================================
--- (empty file)
+++ trunk/libraries/regular-expressions/tests/regression-tests.txt	Wed Nov 28 05:38:40 2007
@@ -0,0 +1,22 @@
+/[]]/
+    ]
+ 0: ]
+    a
+No match
+
+/[]a-z]+/
+    a]z
+ 0: a]z
+    abcD
+ 0: abc
+    ABC
+No match
+
+/^[^]a]+$/
+    bbb
+ 0: bbb
+    bab
+No match
+    b]b
+No match
+



More information about the chatter mailing list