forward-attributes.scrbl (2855B)
1 #lang scribble/manual 2 @require[scribble/example 3 "utils.rkt" 4 @for-label[(except-in phc-toolkit/untyped stx-cdr) 5 extensible-parser-specifications 6 generic-syntax-expanders 7 racket/base 8 syntax/parse 9 (only-in syntax/stx stx-cdr) 10 (only-in racket/base [... …])]] 11 12 @title{Chaining macro calls without re-parsing everything} 13 14 @defform[(define/syntax-parse+simple (name-or-curry . #,ntax-pattern) . body) 15 #:grammar 16 [(name-or-curry name 17 (name-or-curry arg ...)) 18 (maybe-define-class 19 (code:line) 20 (code:line #:define-syntax-class splicing-name)) 21 (maybe-define-splicing-class 22 (code:line) 23 (code:line #:define-splicing-syntax-class splicing-name)) 24 (name identifier?) 25 (class-name identifier?) 26 (splicing-name identifier?)]]{ 27 This macro works like @racket[define/syntax-parse] from @racket[phc-toolkit], 28 except that it also defines the function @racket[_name-forward-attributes], 29 which can be used by other macros to forward already parsed attributes to the 30 @racket[body], without the need to parse everything a second time. 31 32 The syntax pattern for the @racket[name] macro's arguments can be saved in a 33 splicing syntax class by specifying the @racket[#:define-splicing-syntax-class] 34 option. The pattern only includes the arguments after the name, i.e it matches 35 @racket[(stx-cdr stx)]. 36 37 The syntax pattern for the @racket[name] macro's arguments can be saved in a 38 syntax class by specifying the @racket[#:define-syntax-class] option. The 39 pattern only includes the arguments after the name, i.e it matches 40 @racket[(stx-cdr stx)]. 41 42 43 If the caller macro which uses @racket[(_name-forward-attributes)] parsed its 44 own @racket[stx] argument using @racket[class-id], then 45 @racket[(_name-forward-attributes)] is equivalent to expanding 46 @racket[(name stx)]. 47 48 The @racket[_name-forward-attributes] function is defined at the same meta 49 level as @racket[name], i.e. at the same meta-level where this library was 50 required. } 51 52 53 @defform[#:kind "for-template syntax" 54 (define-syntax/parse+simple (name . #,ntax-pattern) . body)]{ 55 This macro is provided for meta-level -1. 56 57 This is the same as @racket[define/syntax-parse+simple], except that it 58 operates at level -1 relative to this library, and defines at that level a 59 transformer binding (which therefore executes at the same meta-level as this 60 library. In other words, 61 @racket[(define-syntax/parse+simple (name . pat) . body)] is roughly equivalent 62 to: 63 64 @racketblock[ 65 (begin-for-syntax 66 (define/syntax-parse+simple (tmp . pat) . body) 67 (define name-forward-attributes tmp-forward-attributes)) 68 (define-syntax name tmp)]}