scoped-transformers.scrbl (1685B)
1 #lang scribble/manual 2 @(require "doc-util.rkt") 3 4 @title{Lens Scoped Syntax Transformers} 5 6 This module uses the @racket[lens] package to create syntax transformers 7 that affect only some small subpiece of a syntax object and compose them 8 with other transformers. This allows for the creation of a macro that cedes 9 control to other macros to pre-expand parts of its body before the macro 10 expands. Combined with the syntax transformer produced by @racket[define-expander-type], 11 this makes it easy to define a macro that expands all instances of a generic 12 expander type in a specific subpiece of its body, turning it into an 13 extensible macro. 14 15 @defproc[((with-scoped-pre-transformer 16 [transformer (-> syntax? syntax?)] 17 [stx-lens lens?] 18 [pre-transformer (-> syntax? syntax?)]) 19 [stx syntax?]) 20 syntax?]{ 21 Transformers @racket[stx] in two passes. First, the piece of @racket[stx] 22 that @racket[stx-lens] views is transformed with @racket[pre-transformer]. 23 Then, the entire resulting syntax object is transformed with @racket[transformer].} 24 25 @defproc[((with-scoped-pre-transformers 26 [transformer (-> syntax? syntax?)] 27 [pre-transformer-lens-pairs 28 (listof (list/c lens? 29 (-> syntax? syntax?)))]) 30 [stx syntax?]) 31 syntax?]{ 32 Similar to @racket[with-scoped-pre-transformer]. Given @racket[pre-transformer-lens-pairs], 33 a list of pairs of lenses and transformers, @racket[transformer] is wrapped 34 with @racket[with-scoped-pre-transformer] with the pair's pre-transformer 35 and lens. The last pair in @racket[pre-transformer-lens-pairs] is applied 36 to @racket[stx] first.}