When annotating regexp states with the leftmost longest match,

prefer the leftmost even if the end of either match has not
yet been completed.  If two matches start on the same state,
prefer an uncompleted end to a completed one.
Fixes issue #229.
This commit is contained in:
Alex Shinn 2014-07-10 22:59:12 +09:00
parent 8b39d35dc1
commit 53c7dfd71e
2 changed files with 12 additions and 6 deletions

View file

@ -267,15 +267,16 @@
(regexp-match-ref m2 (+ i 1)))) (regexp-match-ref m2 (+ i 1))))
(lp (+ i 2))) (lp (+ i 2)))
((and (string-cursor? (regexp-match-ref m2 i)) ((and (string-cursor? (regexp-match-ref m2 i))
(string-cursor? (regexp-match-ref m2 (+ i 1)))
(or (not (string-cursor? (regexp-match-ref m1 i))) (or (not (string-cursor? (regexp-match-ref m1 i)))
(not (string-cursor? (regexp-match-ref m1 (+ i 1))))
(string-cursor<? (regexp-match-ref m2 i) (string-cursor<? (regexp-match-ref m2 i)
(regexp-match-ref m1 i)) (regexp-match-ref m1 i))
(and (string-cursor=? (regexp-match-ref m2 i) (and
(regexp-match-ref m1 i)) (string-cursor=? (regexp-match-ref m2 i)
(string-cursor>? (regexp-match-ref m2 (+ i 1)) (regexp-match-ref m1 i))
(regexp-match-ref m1 (+ i 1)))))) (or (not (string-cursor? (regexp-match-ref m2 (+ i 1))))
(and (string-cursor? (regexp-match-ref m1 (+ i 1)))
(string-cursor>? (regexp-match-ref m2 (+ i 1))
(regexp-match-ref m1 (+ i 1))))))))
#f) #f)
(else (else
#t))))) #t)))))

View file

@ -72,6 +72,11 @@
(regexp-matches '(or (-> foo "ab") (-> foo "cd")) "cd") (regexp-matches '(or (-> foo "ab") (-> foo "cd")) "cd")
'foo)) 'foo))
;; non-deterministic case from issue #229
(let* ((elapsed '(: (** 1 2 num) ":" num num (? ":" num num)))
(span (rx ,elapsed "-" ,elapsed)))
(test-re-search '("1:45:02-2:06:13") span " 1:45:02-2:06:13 "))
(test-re '("ababc" "abab") (test-re '("ababc" "abab")
'(: bos ($ (* "ab")) "c") '(: bos ($ (* "ab")) "c")
"ababc") "ababc")