Hi all,

A nasty bug was found in irregex's matching of "bow" (beginning of word),
when using irregex-fold: in some situations, it would only match the
first occurrance correctly.  See the upstream issue for more details:
https://github.com/ashinn/irregex/issues/14

This patch simply applies the upstream patch, bringing us up-to-date
again.  It applies to master and chicken-5, and should go into both
branches I think.

Cheers,
Peter
From f1a57cb400cb4fb12abfd87a36a76ceab1d1bc46 Mon Sep 17 00:00:00 2001
From: Peter Bex <pe...@more-magic.net>
Date: Sat, 10 Sep 2016 11:29:55 +0200
Subject: [PATCH] Update irregex to upstream version 0.9.5

This fixes a bug with matching "bow" occurrances after the first match
with irregex-fold (or irregex-extract).

This is upstream issue #14: https://github.com/ashinn/irregex/issues/14
---
 NEWS                   |  4 ++++
 irregex-core.scm       | 12 ++++++------
 tests/test-irregex.scm |  2 ++
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/NEWS b/NEWS
index 0481245..d775d6f 100644
--- a/NEWS
+++ b/NEWS
@@ -31,6 +31,10 @@
   - The let-optionals* macro no longer needs "quote", "car" and "cdr"
     to be imported and bound to their default values (#806).
 
+- Core libraries
+  - Irregex has been updated to 0.9.5, which fixes matching of all "bow"
+    occurrances beyond the first with irregex-fold (upstream issue #14).
+
 4.11.0
 
 - Security fixes
diff --git a/irregex-core.scm b/irregex-core.scm
index bae78d9..2d6058c 100644
--- a/irregex-core.scm
+++ b/irregex-core.scm
@@ -1,6 +1,6 @@
 ;;;; irregex.scm -- IrRegular Expressions
 ;;
-;; Copyright (c) 2005-2015 Alex Shinn.  All rights reserved.
+;; Copyright (c) 2005-2016 Alex Shinn.  All rights reserved.
 ;; BSD-style license: http://synthcode.com/license.txt
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -30,6 +30,7 @@
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;; History
+;; 0.9.5: 2016/09/10 - fixed a bug in irregex-fold handling of bow
 ;; 0.9.4: 2015/12/14 - performance improvement for {n,m} matches
 ;; 0.9.3: 2014/07/01 - R7RS library
 ;; 0.9.2: 2012/11/29 - fixed a bug in -fold on conditional bos patterns
@@ -3486,11 +3487,10 @@
                (fail))))
         ((bow)
          (lambda (cnk init src str i end matches fail)
-           (if (and (or (if (> i ((chunker-get-start cnk) src))
-                            (not (char-alphanumeric? (string-ref str (- i 1))))
-                            (let ((ch (chunker-prev-char cnk src end)))
-                              (and ch (not (char-alphanumeric? ch)))))
-                        (and (eq? src (car init)) (eqv? i (cdr init))))
+           (if (and (if (> i ((chunker-get-start cnk) src))
+                        (not (char-alphanumeric? (string-ref str (- i 1))))
+                        (let ((ch (chunker-prev-char cnk init src)))
+                          (or (not ch) (not (char-alphanumeric? ch)))))
                     (if (< i end)
                         (char-alphanumeric? (string-ref str i))
                         (let ((next ((chunker-get-next cnk) src)))
diff --git a/tests/test-irregex.scm b/tests/test-irregex.scm
index d275421..1a46054 100644
--- a/tests/test-irregex.scm
+++ b/tests/test-irregex.scm
@@ -387,6 +387,8 @@
   (test-equal "xaac"
       (irregex-replace/all (irregex '(or (seq bos "a") "b") 'dfa)
                            "aaac" "x"))
+  (test-equal '("foo" " " "foo" " " "b" "a" "r" " " "foo")
+      (irregex-extract '(or (: bow "foo" eow) any) "foo foo bar foo"))
   )
 
 
-- 
2.1.4

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Chicken-hackers mailing list
Chicken-hackers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-hackers

Reply via email to