mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-11 23:17:34 +02:00
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:
parent
8b39d35dc1
commit
53c7dfd71e
2 changed files with 12 additions and 6 deletions
|
@ -267,15 +267,16 @@
|
|||
(regexp-match-ref m2 (+ i 1))))
|
||||
(lp (+ i 2)))
|
||||
((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)))
|
||||
(not (string-cursor? (regexp-match-ref m1 (+ i 1))))
|
||||
(string-cursor<? (regexp-match-ref m2 i)
|
||||
(regexp-match-ref m1 i))
|
||||
(and (string-cursor=? (regexp-match-ref m2 i)
|
||||
(regexp-match-ref m1 i))
|
||||
(string-cursor>? (regexp-match-ref m2 (+ i 1))
|
||||
(regexp-match-ref m1 (+ i 1))))))
|
||||
(and
|
||||
(string-cursor=? (regexp-match-ref m2 i)
|
||||
(regexp-match-ref m1 i))
|
||||
(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)
|
||||
(else
|
||||
#t)))))
|
||||
|
|
|
@ -72,6 +72,11 @@
|
|||
(regexp-matches '(or (-> foo "ab") (-> foo "cd")) "cd")
|
||||
'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")
|
||||
'(: bos ($ (* "ab")) "c")
|
||||
"ababc")
|
||||
|
|
Loading…
Add table
Reference in a new issue