(let ((converted-set
(let loop ((import-set import-set) (filter (lambda (name) name)))
(case (car import-set)
- ((library)
- (let ((name (cadr import-set)))
- (filter-map (lambda (export)
- (let* ((to (library-export-to export))
- (filtered (filter to)))
- (and filtered
- (make-library-import name to filtered))))
- ((registered-library name db) 'get 'exports))))
((only)
(loop (cadr import-set)
(let ((names (cddr import-set)))
(filter
(let ((p (assq name renames)))
(if p
- (cdr p)
+ (cadr p)
name)))))))
(else
- (error "Unrecognized import set:" import-set))))))
+ (if (not (library-name? import-set))
+ (error "Unrecognized import set:" import-set))
+ (filter-map (lambda (export)
+ (let* ((to (library-export-to export))
+ (filtered (filter to)))
+ (and filtered
+ (make-library-import import-set
+ to
+ filtered))))
+ ((registered-library import-set db)
+ 'get 'exports)))))))
(if (duplicate-names? (map library-import-to converted-set))
(error "Import set has duplicate names:" import-set))
converted-set))
(define import-set-parser
(object-parser
- (alt (encapsulate (lambda (library-name) (list 'library library-name))
- (match-if library-name?))
+ (alt (match-if library-name?)
(encapsulate list
(alt (list (alt (match only) (match except))
(object import-set-parser)
(match-if symbol?))
(list (match rename)
(object import-set-parser)
- (* (encapsulate cons
+ (* (encapsulate list
(list (match-if symbol?)
(match-if symbol?)))))))
(sexp (parsing-error "import set")))))
lose)))
(define (parsed-import-library import)
- (case (car import)
- ((library) (cadr import))
- ((only except prefix rename) (parsed-import-library (cadr import)))
- (else (error "Unrecognized import:" import))))
+ (if (memq (car import) '(only except prefix rename))
+ (parsed-import-library (cadr import))
+ import))
(define (library-name? object)
- (and (list? object)
+ (and (pair? object)
+ (list? (cdr object))
(every (lambda (elt)
(or (interned-symbol? elt)
(exact-nonnegative-integer? elt)))
(define-comparator library-export=? 'library-export=?)
(define-comparator library-import=? 'library-import=?)
-(define (convert-import import)
- (case (car import)
- ((only except prefix)
- `(,(car import)
- ,(convert-import (cadr import))
- ,@(cddr import)))
- ((rename)
- `(,(car import)
- ,(convert-import (cadr import))
- ,@(map (lambda (p)
- (cons (car p) (cadr p)))
- (cddr import))))
- (else
- `(library ,import))))
-
(define (convert-export export)
(if (symbol? export)
(make-library-export export)
'(foo bar))
(assert-lset= equal?
(library-parsed-imports library)
- (map convert-import ex1-imports))
+ ex1-imports)
(assert-lset= library-export=?
(library-exports library)
(map convert-export ex1-exports))
'(foo bar))
(assert-lset= equal?
(library-parsed-imports library)
- (map convert-import (append ex1-imports ex2-extra-imports)))
+ (append ex1-imports ex2-extra-imports))
(assert-lset= library-export=?
(library-exports library)
(map convert-export (append ex1-exports ex2-extra-exports)))
(example life))))
(let ((program (r7rs-source-program source)))
(assert-equal (library-parsed-imports program)
- '((library (scheme base))
- (only (library (example life)) life)
- (rename (prefix (library (example grid)) grid-)
- (grid-make . make-grid))))
+ '((scheme base)
+ (only (example life) life)
+ (rename (prefix (example grid) grid-)
+ (grid-make make-grid))))
(assert-equal (library-parsed-contents program)
'((begin
(define grid (make-grid 24 24))