Ticket #281: irregex-chicken-and-named-submatch-stacking.patch
File irregex-chicken-and-named-submatch-stacking.patch, 5.4 KB (added by , 14 years ago) |
---|
-
irregex-chicken.scm
diff -r afe5d137e816 -r 3becabcea570 irregex-chicken.scm
a b 1 1 2 ( cond-expand3 ( compiling4 (declare5 (export6 irregex string->irregex sre->irregex7 string->sre maybe-string->sre8 irregex? irregex-match-data?9 irregex-new-matches irregex-reset-matches!10 irregex-search irregex-search/matches irregex-match11 irregex-search/chunked irregex-match/chunked make-irregex-chunker12 irregex-match-substring irregex-match-subchunk13 irregex-match-start-source irregex-match-start-index14 irregex-match-end-source irregex-match-end-index15 irregex-match-num-submatches16 irregex-fold irregex-replace irregex-replace/all17 irregex-dfa irregex-dfa/search irregex-dfa/extract18 irregex-nfa irregex-flags irregex-lengths irregex-names19 irregex-num-submatches20 ))))21 2 (module irregex 3 (irregex string->irregex sre->irregex 4 string->sre maybe-string->sre 5 irregex? irregex-match-data? 6 irregex-new-matches irregex-reset-matches! 7 irregex-search irregex-search/matches irregex-match 8 irregex-search/chunked irregex-match/chunked make-irregex-chunker 9 irregex-match-substring irregex-match-subchunk 10 irregex-match-start-chunk irregex-match-start-index 11 irregex-match-end-chunk irregex-match-end-index 12 irregex-match-num-submatches 13 irregex-fold irregex-replace irregex-replace/all 14 irregex-dfa irregex-dfa/search irregex-dfa/extract 15 irregex-nfa irregex-flags irregex-lengths irregex-names 16 irregex-num-submatches 17 ) 18 (import scheme) 19 (import chicken) 20 (include "irregex.scm") 21 ) -
irregex.doc
diff -r afe5d137e816 -r 3becabcea570 irregex.doc
a b 170 170 Returns \q{#t} iff the object is a successful match result from 171 171 \q{irregex-search} or \q{irregex-match}. 172 172 173 \subsubsection*{(irregex-num-submatches <irx>)} 174 \subsubsection*{(irregex-match-num-submatches <match>)} 175 176 Returns the number of numbered submatches that are defined in the 177 irregex or match object. 178 179 \subsubsection*{(irregex-names <irx>)} 180 \subsubsection*{(irregex-match-names <match>)} 181 182 Returns an association list of named submatches that are defined in 183 the irregex or match object. The \q{car} of each item in this list is 184 the name of a submatch, the \q{cdr} of each item is the numerical 185 submatch corresponding to this name. If a named submatch occurs 186 multiple times in the irregex, it will also occur multiple times in 187 this list. 188 173 189 \subsubsection*{(irregex-match-substring <match> [<index-or-name>])} 174 190 \subsubsection*{(irregex-match-start-index <match> <index-or-name>)} 175 191 \subsubsection*{(irregex-match-end-index <match> <index-or-name>)} -
irregex.scm
diff -r afe5d137e816 -r 3becabcea570 irregex.scm
a b 155 155 156 156 (define (irregex-match-index m opt) 157 157 (if (pair? opt) 158 (cond ((number? (car opt)) (car opt)) 159 ((assq (car opt) (irregex-match-names m)) => cdr) 160 (else (error "unknown match name" (car opt)))) 158 (if (number? (car opt)) 159 (car opt) 160 (let lp ((ls (irregex-match-names m))) 161 (cond ((null? ls) (error "unknown match name" (car opt))) 162 ((and (eq? (car opt) (caar ls)) 163 (%irregex-match-start-chunk m (cdar ls))) 164 (cdar ls)) 165 (else (lp (cdr ls)))))) 161 166 0)) 162 167 163 168 (define (%irregex-match-valid-index? m n) -
irregex.setup
diff -r afe5d137e816 -r 3becabcea570 irregex.setup
a b 1 (define has-exports? (string>=? (chicken-version) "2.310"))2 1 3 (compile irregex.scm -s -O2 -f -inline -lambda-lift -disable-interrupts ;-d0 4 -prologue irregex-chicken.scm 5 ,@(if has-exports? 6 '(-check-imports -emit-exports irregex.exports) 7 '()) 8 -o irregex.so) 2 (compile irregex-chicken.scm -s -O3 -f -inline -lambda-lift -disable-interrupts ;-d0 3 -j irregex -o irregex.so) 4 (compile irregex.import.scm -s -Os -d0) 9 5 (install-extension 10 6 'irregex 11 7 '("irregex.so") 12 `((version 0.7.0) 13 (documentation "irregex.html") 14 ,@(if has-exports? `((exports "irregex.exports")) '()))) 8 `((version 0.8.1) 9 (documentation "irregex.html"))) -
test-irregex.scm
diff -r afe5d137e816 -r 3becabcea570 test-irregex.scm
a b 283 283 (lambda (src i s) (reverse s)))) 284 284 ) 285 285 286 287 (define (extract name irx str) 288 (irregex-match-substring (irregex-match irx str) name)) 289 290 (test-group "named submatches" 291 (test "matching alternative is used" 292 "first" (extract 'sub `(or (submatch-named sub "first") 293 (submatch-named sub "second")) 294 "first")) 295 (test "matching alternative is used (second match)" 296 "second" (extract 'sub `(or (submatch-named sub "first") 297 (submatch-named sub "second")) 298 "second")) 299 (test "last match is used with multiple matches for a name" 300 "second" (extract 'sub `(seq (submatch-named sub "first") 301 space 302 (submatch-named sub "second")) 303 "first second"))) 304 286 305 (test-end) 287 306