mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-20 14:19:18 +02:00
Returning the first defined submatch with a given name when
there are multiple instances of the name.
This commit is contained in:
parent
89edcc85ae
commit
056eb0c6ce
2 changed files with 18 additions and 2 deletions
|
@ -102,8 +102,14 @@
|
|||
(vector-length (regexp-match-matches md)))
|
||||
|
||||
(define (regexp-match-name-offset md name)
|
||||
(cond ((assq name (regexp-match-names md)) => cdr)
|
||||
(else (error "unknown match name" md name))))
|
||||
(let lp ((ls (regexp-match-names md)) (first #f))
|
||||
(cond
|
||||
((null? ls) (or first (error "unknown match name" md name)))
|
||||
((eq? name (caar ls))
|
||||
(if (regexp-match-submatch-start+end md (cdar ls))
|
||||
(cdar ls)
|
||||
(lp (cdr ls) (or first (cdar ls)))))
|
||||
(else (lp (cdr ls) first)))))
|
||||
|
||||
(define (regexp-match-ref md n)
|
||||
(vector-ref (regexp-match-matches md)
|
||||
|
|
|
@ -62,6 +62,16 @@
|
|||
'(: (* (*$ (or "ab" "cd"))) "c")
|
||||
"abcdc")
|
||||
|
||||
(test "ab"
|
||||
(regexp-match-submatch
|
||||
(regexp-matches '(or (-> foo "ab") (-> foo "cd")) "ab")
|
||||
'foo))
|
||||
|
||||
(test "cd"
|
||||
(regexp-match-submatch
|
||||
(regexp-matches '(or (-> foo "ab") (-> foo "cd")) "cd")
|
||||
'foo))
|
||||
|
||||
(test-re '("ababc" "abab")
|
||||
'(: bos ($ (* "ab")) "c")
|
||||
"ababc")
|
||||
|
|
Loading…
Add table
Reference in a new issue