|
|
@ -62,10 +62,15 @@
|
|
|
|
;; The null or `(:) means match nothing. The null carat `(^) means match
|
|
|
|
;; The null or `(:) means match nothing. The null carat `(^) means match
|
|
|
|
;; any character. The null intersection `(&) means match string.)
|
|
|
|
;; any character. The null intersection `(&) means match string.)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define loc:make-range is:make-range)
|
|
|
|
|
|
|
|
(define loc:union is:union)
|
|
|
|
|
|
|
|
(define loc:split is:split)
|
|
|
|
|
|
|
|
(define loc:complement is:complement)
|
|
|
|
|
|
|
|
|
|
|
|
;; ->re : s-re cache -> re
|
|
|
|
;; ->re : s-re cache -> re
|
|
|
|
(define (->re exp cache)
|
|
|
|
(define (->re exp cache)
|
|
|
|
(match exp
|
|
|
|
(match exp
|
|
|
|
((? char?) (build-char-set (is:make-range (char->integer exp)) cache))
|
|
|
|
((? char?) (build-char-set (loc:make-range (char->integer exp)) cache))
|
|
|
|
((? string?) (->re `(@ ,@(string->list exp)) cache))
|
|
|
|
((? string?) (->re `(@ ,@(string->list exp)) cache))
|
|
|
|
((? re?) exp)
|
|
|
|
((? re?) exp)
|
|
|
|
(`(epsilon) (build-epsilon))
|
|
|
|
(`(epsilon) (build-epsilon))
|
|
|
@ -80,12 +85,12 @@
|
|
|
|
(build-or (list e c) cache))))
|
|
|
|
(build-or (list e c) cache))))
|
|
|
|
(`(: ,rs ...)
|
|
|
|
(`(: ,rs ...)
|
|
|
|
(build-or (flatten-res (map (lambda (r) (->re r cache)) rs)
|
|
|
|
(build-or (flatten-res (map (lambda (r) (->re r cache)) rs)
|
|
|
|
orR? orR-res is:union cache)
|
|
|
|
orR? orR-res loc:union cache)
|
|
|
|
cache))
|
|
|
|
cache))
|
|
|
|
(`(& ,rs ...)
|
|
|
|
(`(& ,rs ...)
|
|
|
|
(build-and (flatten-res (map (lambda (r) (->re r cache)) rs)
|
|
|
|
(build-and (flatten-res (map (lambda (r) (->re r cache)) rs)
|
|
|
|
andR? andR-res (lambda (a b)
|
|
|
|
andR? andR-res (lambda (a b)
|
|
|
|
(let-values (((i _ __) (is:split a b))) i))
|
|
|
|
(let-values (((i _ __) (loc:split a b))) i))
|
|
|
|
cache)
|
|
|
|
cache)
|
|
|
|
cache))
|
|
|
|
cache))
|
|
|
|
(`(~ ,r)
|
|
|
|
(`(~ ,r)
|
|
|
@ -99,14 +104,14 @@
|
|
|
|
(let ((i1 (char->integer (if (string? c1) (string-ref c1 0) c1)))
|
|
|
|
(let ((i1 (char->integer (if (string? c1) (string-ref c1 0) c1)))
|
|
|
|
(i2 (char->integer (if (string? c2) (string-ref c2 0) c2))))
|
|
|
|
(i2 (char->integer (if (string? c2) (string-ref c2 0) c2))))
|
|
|
|
(if (<= i1 i2)
|
|
|
|
(if (<= i1 i2)
|
|
|
|
(build-char-set (is:make-range i1 i2) cache)
|
|
|
|
(build-char-set (loc:make-range i1 i2) cache)
|
|
|
|
z)))
|
|
|
|
z)))
|
|
|
|
(`(^ ,crs ...)
|
|
|
|
(`(^ ,crs ...)
|
|
|
|
(let ((cs (->re `(: ,@crs) cache)))
|
|
|
|
(let ((cs (->re `(: ,@crs) cache)))
|
|
|
|
(cond
|
|
|
|
(cond
|
|
|
|
((zeroR? cs) (build-char-set (is:make-range 0 255) cache))
|
|
|
|
((zeroR? cs) (build-char-set (loc:make-range 0 255) cache))
|
|
|
|
((char-setR? cs)
|
|
|
|
((char-setR? cs)
|
|
|
|
(build-char-set (is:complement (char-setR-chars cs) 0 255) cache))
|
|
|
|
(build-char-set (loc:complement (char-setR-chars cs) 0 255) cache))
|
|
|
|
(else z))))))
|
|
|
|
(else z))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -140,9 +145,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
(define (build-zero) z)
|
|
|
|
(define (build-zero) z)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define loc:integer-set-contents is:integer-set-contents)
|
|
|
|
|
|
|
|
|
|
|
|
;; build-char-set : char-set cache -> re
|
|
|
|
;; build-char-set : char-set cache -> re
|
|
|
|
(define (build-char-set cs cache)
|
|
|
|
(define (build-char-set cs cache)
|
|
|
|
(let ((l (is:integer-set-contents cs)))
|
|
|
|
(let ((l (loc:integer-set-contents cs)))
|
|
|
|
(cond
|
|
|
|
(cond
|
|
|
|
((null? l) z)
|
|
|
|
((null? l) z)
|
|
|
|
(else
|
|
|
|
(else
|
|
|
|