From 3fcf803cc5244bc0499440df2bfadd724f338457 Mon Sep 17 00:00:00 2001
From: Chris Hanson <org/chris-hanson/cph>
Date: Mon, 31 May 2010 01:32:12 -0700
Subject: [PATCH] Fix swapped conditional arms in RE-COMPILE-CHAR-SET; then
 split off part of it as RE-CHAR-PATTERN->SCALAR-VALUES.

---
 src/runtime/rgxcmp.scm  | 21 ++++++++++++---------
 src/runtime/runtime.pkg |  1 +
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/runtime/rgxcmp.scm b/src/runtime/rgxcmp.scm
index 6f4caca18..c85dc018d 100644
--- a/src/runtime/rgxcmp.scm
+++ b/src/runtime/rgxcmp.scm
@@ -259,6 +259,14 @@ USA.
 ;;; #\^ must appear anywhere except as the first character in the set.
 
 (define (re-compile-char-set pattern negate?)
+  (receive (scalar-values negate?*)
+      (re-char-pattern->scalar-values pattern)
+    (let ((char-set (scalar-values->char-set scalar-values)))
+      (if (if negate? (not negate?*) negate?*)
+	  (char-set-invert char-set)
+	  char-set))))
+
+(define (re-char-pattern->scalar-values pattern)
   (define (loop pattern scalar-values)
     (if (pair? pattern)
 	(if (and (pair? (cdr pattern))
@@ -274,15 +282,10 @@ USA.
 	scalar-values))
 
   (let ((pattern (string->list pattern)))
-    (receive (pattern negate?)
-	(if (and (pair? pattern)
-		 (char=? (car pattern) #\^))
-	    (values (cdr pattern) (not negate?))
-	    (values pattern negate?))
-      (let ((char-set (scalar-values->char-set (loop pattern '()))))
-	(if negate?
-	    char-set
-	    (char-set-invert char-set))))))
+    (if (and (pair? pattern)
+	     (char=? (car pattern) #\^))
+	(values (loop (cdr pattern) '()) #t)
+	(values (loop pattern '()) #f))))
 
 ;;;; Translation Tables
 
diff --git a/src/runtime/runtime.pkg b/src/runtime/runtime.pkg
index d4d6fe6c9..cea35327b 100644
--- a/src/runtime/runtime.pkg
+++ b/src/runtime/runtime.pkg
@@ -5083,6 +5083,7 @@ USA.
 	  compiled-regexp/byte-stream
 	  compiled-regexp/translation-table
 	  condition-type:re-compile-pattern
+	  re-char-pattern->scalar-values
 	  re-compile-char
 	  re-compile-char-set
 	  re-compile-pattern
-- 
2.25.1