expanders.scrbl (1889B)
1 #lang scribble/manual 2 @(require "doc-util.rkt") 3 4 @title{Expanders And Transformers} 5 6 Generic expanders are implemented as values of the @racket[expander?] struct 7 bound with @racket[define-syntax], that store both a type and a transformer 8 procedure. Future versions of this library may support storing an additional 9 transformer for use outside expander-contexts in normal syntax parsing. This 10 could be used for better error messages, or for an expander meant to have 11 meaning in both a particularly typed expansion context and a normal expression 12 expansion context. 13 14 @defstruct*[expander ([type expander-type?] [transformer (-> syntax? syntax?)])]{ 15 A structure type for generic syntax expanders. A generic syntax expander 16 has an associated @italic{type} and @italic{transformer}. The transformer 17 can be any arbitrary function that accepts a syntax object in the same 18 manner a transformer given to @racket[define-syntax] would behave.} 19 20 @defproc[(expander-of-type? [type expander-type?] [expander expander?]) boolean?]{ 21 Returns @racket[#t] if the @racket[expander] has type @racket[type], 22 according to the semantics of @racket[expander-type-includes?], and 23 returns @racket[#f] otherwise. 24 @generic-syntax-examples[ 25 (define A (make-expander-type)) 26 (define exp (expander A (λ (stx) stx))) 27 (expander-of-type? A exp)]} 28 29 @defproc[(expand-syntax-tree-with-expanders-of-type [type expander-type?] [syntax syntax?]) syntax?]{ 30 Recursively searches through @racket[syntax] for identifiers bound to 31 generic syntax expanders of the given type. When an expander is found, 32 its transformer is called with the given syntax value of its location 33 in the tree. The returned syntax object with have all expanders of the 34 given type fully expanded, but nothing else will be expanded. Due to 35 how expanders are bound to identifiers, this procedure can only be 36 called in a transformer environment.}