Move identifier-syntax to (chibi ast)

This commit is contained in:
Daphne Preston-Kendal 2022-03-15 10:27:56 +01:00
parent 86e8b56289
commit 9a0212efff
3 changed files with 33 additions and 4 deletions

View file

@ -109,6 +109,34 @@
((opcode? x) (cond ((opcode-name x) => string->symbol) (else x)))
(else x)))))
;;> \section{Identifier Macros}
;;> \procedure{(make-variable-transformer proc)}
;;> Returns a new procedure wrapping the input procedure \var{proc}.
;;> The returned procedure, if used as a macro transformer procedure,
;;> can expand an instance of \scheme{set!} with its keyword on the
;;> left hand side.
;;> \macro{(identifier-syntax clauses ...)}
;;> A high-level form for creating identifier macros. See
;;> \hyperlink["http://www.r6rs.org/final/html/r6rs/r6rs-Z-H-14.html#node_idx_796"]{the R6RS specification.}
(define-syntax identifier-syntax
(syntax-rules (set!)
((_ template)
(syntax-rules ()
((_ xs (... ...))
(template xs (... ...)))
(x template)))
((_ (id_1 template_1) ((set! id_2 pattern) template_2))
(make-variable-transformer
(syntax-rules (set!)
((set! id_2 pattern) template_2)
((id_1 xs (... ...)) (template_1 xs (... ...)))
(id_1 template_1))))))
;;> \section{Types}
;;> All objects have an associated type, and types may have parent

View file

@ -1,7 +1,8 @@
(define-library (chibi ast)
(export
analyze optimize env-cell ast->sexp macroexpand type-of
analyze optimize env-cell ast->sexp macroexpand identifier-syntax
type-of
Object Input-Port Output-Port Opcode Procedure Bytecode Macro Env
Number Bignum Flonum Integer Complex Char Boolean
Symbol String Byte-Vector Vector Pair File-Descriptor

View file

@ -84,11 +84,11 @@
;; this could be fixed in theory)
(modules
(test-begin "identifier syntax")
(define syntax-test-env (environment '(chibi)))
(define syntax-test-env (environment '(chibi) '(chibi ast)))
(eval
'(define-syntax low-level-id-macro
(er-macro-transformer*
(er-macro-transformer
(lambda (expr rename compare)
(if (pair? expr)
(list (rename 'quote) 'operator)
@ -102,7 +102,7 @@
(eval
'(define-syntax low-level-vt
(make-variable-transformer
(er-macro-transformer*
(er-macro-transformer
(lambda (expr rename compare)
(list (rename 'quote)
(if (pair? expr)