mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-17 01:37:34 +02:00
Helper for prefix and rename
This commit is contained in:
parent
3f6f22d4b6
commit
02a8676e59
1 changed files with 44 additions and 17 deletions
|
@ -274,11 +274,11 @@
|
||||||
;; TODO: how to handle if a var is renamed more than once? really just want one mapping from lib-var-name => renamed-var-name
|
;; TODO: how to handle if a var is renamed more than once? really just want one mapping from lib-var-name => renamed-var-name
|
||||||
|
|
||||||
;; TODO: if import-set is not library name, recursively process it, then deal with results here
|
;; TODO: if import-set is not library name, recursively process it, then deal with results here
|
||||||
; (unless (lib:import-set:library-name? import-set)
|
(unless (lib:import-set:library-name? import-set)
|
||||||
; (let ((result (lib:import-set/exports->imports
|
(let ((result (lib:import-set/exports->imports
|
||||||
; (lib:import-set->import-set import-set)
|
(lib:import-set->import-set import-set)
|
||||||
; exports)))
|
exports)))
|
||||||
; (set! exports result)))
|
(set! exports result)))
|
||||||
|
|
||||||
(cond
|
(cond
|
||||||
((tagged-list? 'only import-set)
|
((tagged-list? 'only import-set)
|
||||||
|
@ -294,26 +294,53 @@
|
||||||
;; TODO: not good enough, need to handle renamed identifiers
|
;; TODO: not good enough, need to handle renamed identifiers
|
||||||
(not (member sym (cddr import-set))))
|
(not (member sym (cddr import-set))))
|
||||||
exports))
|
exports))
|
||||||
;;((tagged-list? 'prefix import-set)
|
((tagged-list? 'prefix import-set)
|
||||||
;; same as rename, but add given prefix to all exports
|
;; same as rename, but add given prefix to all exports
|
||||||
|
(let* ((prefix (caddr import-set))
|
||||||
;;((tagged-list? 'rename import-set)
|
(prestr (symbol->string prefix)))
|
||||||
;; for each rename
|
(map
|
||||||
;; let's keep it simple and replace "ident" in exports with
|
(lambda (e)
|
||||||
;; the mapping "(ident rename)". of course, that punts the
|
(cons
|
||||||
;; job of dealing with the rename back to the caller, but
|
;; Renamed identifier with prefix
|
||||||
;; I think that will be OK.
|
(string->symbol
|
||||||
|
(string-append
|
||||||
|
prestr
|
||||||
|
(symbol->string
|
||||||
|
(if (pair? e)
|
||||||
|
(car e)
|
||||||
|
e))))
|
||||||
|
;; Original identifier
|
||||||
|
(if (pair? e)
|
||||||
|
(cdr e)
|
||||||
|
e)))
|
||||||
|
exports)))
|
||||||
|
((tagged-list? 'rename import-set)
|
||||||
|
(let ((renames (cddr import-set)))
|
||||||
|
(map
|
||||||
|
(lambda (e)
|
||||||
|
(let ((rename (assoc
|
||||||
|
(if (pair? e) (car e) e)
|
||||||
|
renames)))
|
||||||
|
(if rename
|
||||||
|
(cons
|
||||||
|
(cadr rename) ;; Renamed identifier
|
||||||
|
(if (pair? e) (cdr e) e) ;; Original identifier from library
|
||||||
|
)
|
||||||
|
e)))
|
||||||
|
exports)))
|
||||||
(else
|
(else
|
||||||
exports)))
|
exports)))
|
||||||
;; TODO: test cases for above:
|
;; Test cases for above:
|
||||||
;cyclone> (lib:import-set/exports->imports '(lib) '(a b c d e))
|
;cyclone> (lib:import-set/exports->imports '(lib) '(a b c d e))
|
||||||
;(a b c d e)
|
;(a b c d e)
|
||||||
;cyclone> (lib:import-set/exports->imports '(except (lib) a) '(a b c d e))
|
;cyclone> (lib:import-set/exports->imports '(except (lib) a) '(a b c d e))
|
||||||
;(b c d e)
|
;(b c d e)
|
||||||
;cyclone> (lib:import-set/exports->imports '(rename (lib) (a a1) (d d1)) '(a b c d e))
|
;cyclone> (lib:import-set/exports->imports '(rename (lib) (a a1) (d d1)) '(a b c d e))
|
||||||
;((a a1) b c (d d1) e)
|
;((a1 . a) b c (d1 . d) e)
|
||||||
|
;cyclone> (lib:import-set/exports->imports '(rename (rename (lib) (a a1) (d d1)) (d1 d2)) '(a b c d e))
|
||||||
|
;((a1 . a) b c (d2 . d) e)
|
||||||
;cyclone> (lib:import-set/exports->imports '(prefix (lib) my-) '(a b c d e))
|
;cyclone> (lib:import-set/exports->imports '(prefix (lib) my-) '(a b c d e))
|
||||||
;(my-a my-b my-c my-d my-e)
|
;((my-a . a) (my-b . b) (my-c . c) (my-d . d) (my-e . e))
|
||||||
|
|
||||||
;; Take a list of imports and resolve it to the imported vars
|
;; Take a list of imports and resolve it to the imported vars
|
||||||
;(define (lib:resolve-imports imports)
|
;(define (lib:resolve-imports imports)
|
||||||
|
|
Loading…
Add table
Reference in a new issue