~ chicken-core (chicken-5) /tests/meta-syntax-test.scm


 1;;;; meta-syntax-test.scm
 2
 3;;
 4;; A module's syntax definitions should be accessible through either of
 5;; the following import forms:
 6;;
 7;;   (import-syntax-for-syntax (foo)) ; meta environment
 8;;
 9;;   (begin-for-syntax                ; compiler environment
10;;     (import-syntax (foo)))         ; note that `import` will not work here
11;;
12
13(module foo (bar listify)
14  (import scheme chicken.syntax)
15  (begin-for-syntax
16   (define (baz x) 
17     (list (cadr x))))
18  (define-syntax bar
19    (er-macro-transformer
20     (lambda (x r c)
21       `(,(r 'list) (baz (list 1 ,(cadr x)))))))
22  (begin-for-syntax
23   (define-syntax call-it-123
24     (syntax-rules ()
25       ((_ x)
26        '(x 'x 1 2 3)))))
27  (define-syntax listify
28    (er-macro-transformer
29     (lambda (e r c)
30       (call-it-123 list)))))
31
32(module test-import-syntax-for-syntax (test)
33  (import scheme chicken.syntax)
34  (import-syntax-for-syntax (prefix foo foo:))
35  (define-syntax test-import-syntax-for-syntax
36    (er-macro-transformer
37     (lambda (x r c)
38       `(,(r 'quote) ,@(foo:bar 1 2)))))
39  (define (test)
40    (test-import-syntax-for-syntax)))
41
42(module test-begin-for-syntax (test)
43  (import scheme chicken.syntax)
44  (begin-for-syntax
45    (import-syntax (prefix foo foo:)))
46  (define-syntax test-begin-for-syntax
47    (er-macro-transformer
48     (lambda (x r c)
49       `(,(r 'quote) ,@(foo:bar 1 2)))))
50  (define (test)
51    (test-begin-for-syntax)))
Trap