1999-09-23 10:27:41 -04:00
|
|
|
;;; Procedures that appear in code produced by (RX ...).
|
|
|
|
|
|
|
|
;;; In sexp syntax, a ,<exp> or ,@<exp> form may evaluate to a string, char,
|
|
|
|
;;; char-set, or regexp value. Coerce one of these to a regexp value.
|
|
|
|
|
|
|
|
(define (coerce-dynamic-regexp x)
|
2002-10-30 07:33:51 -05:00
|
|
|
(cond
|
|
|
|
((string? x) (make-re-string x))
|
|
|
|
((char? x) (make-re-string (string x)))
|
|
|
|
((char-set? x) (make-re-char-set x))
|
|
|
|
((regexp? x) x)
|
|
|
|
(else (error "Cannot coerce value to regular expression." x))))
|
1999-09-23 10:27:41 -04:00
|
|
|
|
|
|
|
;;; In a char-set context (e.g., as an operand of the SRE - operator),
|
|
|
|
;;; a ,<exp> or form must be coercable to a char-set.
|
|
|
|
|
|
|
|
(define (coerce-dynamic-charset x)
|
2002-10-30 07:33:51 -05:00
|
|
|
(cond
|
|
|
|
((string? x)
|
|
|
|
(if (= 1 (string-length x)) (string->char-set x)
|
|
|
|
(error "Multi-char string not allowed as ,<exp> or ,@<exp> SRE in char-class context."
|
|
|
|
x)))
|
|
|
|
((char? x) (char-set x))
|
|
|
|
((char-set? x) x)
|
|
|
|
((re-char-set? x) (re-char-set:cset x))
|
|
|
|
(else (error "Cannot coerce value to character set" x))))
|
1999-09-23 10:27:41 -04:00
|
|
|
|
|
|
|
|
|
|
|
(define (spec->char-set in? loose ranges)
|
|
|
|
(let ((doit (lambda (loose ranges)
|
|
|
|
(fold (lambda (r cset)
|
|
|
|
(let ((from (char->ascii (car r)))
|
|
|
|
(to (char->ascii (cdr r))))
|
|
|
|
(do ((i from (+ i 1))
|
|
|
|
(cs cset (char-set-adjoin! cs (ascii->char i))))
|
|
|
|
((> i to) cs))))
|
|
|
|
(string->char-set loose)
|
|
|
|
ranges))))
|
|
|
|
(if in?
|
|
|
|
(doit loose ranges)
|
2001-03-23 05:52:09 -05:00
|
|
|
(char-set-complement! (doit loose ranges)))))
|
1999-09-23 10:27:41 -04:00
|
|
|
|