[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reference implementation dependencies?



On Tue, Oct 15, 2013 at 02:27:54PM -0400, John Cowan wrote:
> Peter Bex scripsit:
> 
> > I just tried the reference implementation in CHICKEN, but it gave me
> > several warnings upon load, and errors when trying to use something:
> 
> It's a Chibi-specific library for efficient iteration in UTF-8 strings.
> https://code.google.com/p/chibi-scheme/source/browse/lib/chibi/regexp.sld
> (the R7RS library file) includes a cond-expand that provides a portable
> implementation.  Just convert it to a Chicken module, which is trivial.

It also seems to be broken.  I fiddled with it for a bit, and came up
with the attached patch.  Hopefully it's correct...

Cheers,
Peter
-- 
http://www.more-magic.net
diff -r 4c3e6fe661ad lib/chibi/regexp.sld
--- a/lib/chibi/regexp.sld	Tue Oct 15 15:23:23 2013 +0900
+++ b/lib/chibi/regexp.sld	Tue Oct 15 21:09:35 2013 +0200
@@ -28,9 +28,9 @@
    (else
     (begin
       (define (string-start-arg s o)
-        (if (pair? o) (string-index->offset (car o)) 0))
+        (if (pair? o) (string-index->offset s (car o)) 0))
       (define (string-end-arg s o)
-        (if (pair? o) (string-index->offset (car o)) (string-length s)))
+        (if (pair? o) (string-index->offset s (car o)) (string-length s)))
       (define string-cursor=? =)
       (define string-cursor<? <)
       (define string-cursor<=? <=)
@@ -39,6 +39,9 @@
       (define string-cursor-ref string-ref)
       (define substring-cursor substring)
       (define (string-offset->index str off) off)
+      (define (string-offset->index str i) i)
+      (define (string-cursor-next s i) (+ i 1))
+      (define (string-cursor-prev s i) (- i 1))
       (define (string-concatenate-reverse ls)
         (apply string-append (reverse ls))))))
   (include "regexp.scm"))