Fix bugs in char-set->regexp rewrite.
authorChris Hanson <org/chris-hanson/cph>
Sun, 30 Apr 2017 06:44:01 +0000 (23:44 -0700)
committerChris Hanson <org/chris-hanson/cph>
Sun, 30 Apr 2017 06:44:01 +0000 (23:44 -0700)
src/runtime/regexp.scm

index 3f3cb6d1eef512203b9a0fe84ba5b81172e6643f..cd1b4d498feb21a3b47bd789ead5071a3afc6aa3 100644 (file)
@@ -187,27 +187,22 @@ USA.
   (let ((chars (char-set-members char-set)))
     (if (pair? chars)
        (if (pair? (cdr chars))
-           (let ((ranges
-                  (push #\^ (pull #\- (pull #\] (compute-ranges chars))))))
-             (let ((n
-                    (let loop ((ranges ranges) (n 2))
-                      (if (pair? ranges)
-                          (loop (cdr ranges)
-                                (fix:+ n (if (pair? (car ranges)) 3 1)))
-                          n))))
-               (let ((builder (string-builder)))
-                 (builder #\[)
-                 (let loop ((ranges ranges))
-                   (if (pair? ranges)
-                       (let ((range (car ranges)))
-                         (if (pair? range)
-                             (begin
-                               (builder (car range))
-                               (builder #\-)
-                               (builder (cdr range)))
-                             (builder range)))
-                       (loop (cdr ranges))))
-                 (builder #\])
-                 (builder))))
+           (let ((builder (string-builder)))
+             (builder #\[)
+             (let loop
+                 ((ranges
+                   (push #\^ (pull #\- (pull #\] (compute-ranges chars))))))
+               (if (pair? ranges)
+                   (begin
+                     (let ((range (car ranges)))
+                       (if (pair? range)
+                           (begin
+                             (builder (car range))
+                             (builder #\-)
+                             (builder (cdr range)))
+                           (builder range)))
+                     (loop (cdr ranges)))))
+             (builder #\])
+             (builder))
            (re-quote-string (string (car chars))))
        "")))
\ No newline at end of file