Handle the regexp matching the empty string specially, as POSIX

requires it to be "()", not "()".

This closes bug

[ 1005026 ] sre: (** 0 0 "foo") raises error
This commit is contained in:
sperber 2004-08-22 14:22:29 +00:00
parent 43e5f6fb8c
commit ce9da610e6
1 changed files with 25 additions and 9 deletions

View File

@ -338,24 +338,40 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Also, re-empty and re-trivial.
(define-record re-string
chars ; String
(posix #f) ; Posix record
((disclose self) (list "re-string" (re-string:chars self))))
(define-record-type re-string :re-string
(really-make-re-string chars posix)
re-string?
(chars re-string:chars set-re-string:chars)
(posix re-string:posix set-re-string:posix))
(define-record-discloser :re-string
(lambda (r)
(list 're-string
(re-string:chars r))))
;; Kludge: POSIX wants "()" for "the empty string".
(define (make-re-string chars)
(if (string=? "" chars)
re-trivial
(really-make-re-string chars #f)))
(define re-string make-re-string) ; For consistency w/other re makers.
;;; This is only used in code that (RE ...) macro produces for static regexps.
(define (make-re-string/posix chars posix-str tvec)
(let ((re (make-re-string chars)))
(set-re-string:posix re (new-cre posix-str tvec))
re))
(if (string=? "" chars)
re-trivial
(really-make-re-string chars (new-cre posix-str tvec))))
(define re-empty-string (really-make-re-string "" #f))
;;; Matches the empty string anywhere.
(define re-trivial (make-re-string/posix "" "" '#()))
(define re-trivial (make-re-dsm/posix re-empty-string
1 0 "()" '#()))
(define (re-trivial? re)
(and (re-string? re) (zero? (string-length (re-string:chars re)))))
(eq? re re-trivial))
(define-record re-char-set
cset ; A character set (Macro expander abuses.)