From 9d5df43fd85808ddb7140a1b051791849758fc23 Mon Sep 17 00:00:00 2001
From: Chris Hanson <org/chris-hanson/cph>
Date: Mon, 30 May 2005 02:46:52 +0000
Subject: [PATCH] Add expressions to implement limited repeating patterns.

---
 v7/src/runtime/rexp.scm    | 36 +++++++++++++++++++++++++++++++++---
 v7/src/runtime/runtime.pkg |  6 +++++-
 2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/v7/src/runtime/rexp.scm b/v7/src/runtime/rexp.scm
index cdc9dd232..fcfd3b97b 100644
--- a/v7/src/runtime/rexp.scm
+++ b/v7/src/runtime/rexp.scm
@@ -1,8 +1,8 @@
 #| -*-Scheme-*-
 
-$Id: rexp.scm,v 1.22 2003/02/14 18:28:33 cph Exp $
+$Id: rexp.scm,v 1.23 2005/05/30 02:45:04 cph Exp $
 
-Copyright (c) 2000, 2001, 2002 Massachusetts Institute of Technology
+Copyright 2000,2001,2002,2005 Massachusetts Institute of Technology
 
 This file is part of MIT/GNU Scheme.
 
@@ -235,4 +235,34 @@ USA.
 			 (char-downcase (car chars))
 			 chars*)
 		  chars*))
-	(apply char-set chars*))))
\ No newline at end of file
+	(apply char-set chars*))))
+
+(define (rexp-n*m n m . rexps)
+  (guarantee-exact-nonnegative-integer n 'REXP-N*M)
+  (guarantee-exact-nonnegative-integer m 'REXP-N*M)
+  (if (not (<= n m))
+      (error:bad-range-argument m 'REXP-N*M))
+  (let ((rexp (apply rexp-sequence rexps)))
+    (let loop ((i 1))
+      (cond ((<= i n)
+	     (rexp-sequence rexp (loop (+ i 1))))
+	    ((<= i m)
+	     (rexp-optional rexp (loop (+ i 1))))
+	    (else
+	     (rexp-sequence))))))
+
+(define (rexp-n*n n . rexps)
+  (apply rexp-n*m n n rexps))
+
+(define (rexp-0*n n . rexps)
+  (apply rexp-n*m 0 n rexps))
+
+(define (rexp-n* n . rexps)
+  (guarantee-exact-nonnegative-integer n 'REXP-N*)
+  (let ((rexp (apply rexp-sequence rexps)))
+    (if (= n 0)
+	(rexp* rexp)
+	(let loop ((i 1))
+	  (if (< i n)
+	      (rexp-sequence rexp (loop (+ i 1)))
+	      (rexp+ rexp))))))
\ No newline at end of file
diff --git a/v7/src/runtime/runtime.pkg b/v7/src/runtime/runtime.pkg
index 10a1a1100..191beee82 100644
--- a/v7/src/runtime/runtime.pkg
+++ b/v7/src/runtime/runtime.pkg
@@ -1,6 +1,6 @@
 #| -*-Scheme-*-
 
-$Id: runtime.pkg,v 14.546 2005/05/26 17:43:15 cph Exp $
+$Id: runtime.pkg,v 14.547 2005/05/30 02:46:52 cph Exp $
 
 Copyright 1988,1989,1990,1991,1992,1993 Massachusetts Institute of Technology
 Copyright 1994,1995,1996,1997,1998,1999 Massachusetts Institute of Technology
@@ -4491,6 +4491,7 @@ USA.
   (export ()
 	  rexp*
 	  rexp+
+	  rexp-0*n
 	  rexp->regexp
 	  rexp-alternatives
 	  rexp-any-char
@@ -4499,6 +4500,9 @@ USA.
 	  rexp-group
 	  rexp-line-end
 	  rexp-line-start
+	  rexp-n*
+	  rexp-n*m	  
+	  rexp-n*n
 	  rexp-not-syntax-char
 	  rexp-not-word-char
 	  rexp-not-word-edge
-- 
2.25.1