syntax-properties.rkt (1154B)
1 #lang racket 2 3 (provide first-comments/c 4 comments-after/c 5 with-first-comments 6 with-comments-after 7 extract-first-comments 8 extract-comments-after) 9 10 (define first-comments/c 11 (flat-rec-contract R (cons/c (or/c #f (cons/c (syntax/c 'saved-props+srcloc) 12 R)) #| nested |# 13 (listof syntax?) #| comments |#))) 14 (define comments-after/c 15 (listof syntax?)) 16 17 (define/contract (with-first-comments e c) 18 (-> syntax? 19 (or/c #f first-comments/c) 20 syntax?) 21 (if (or (not c) (and (= (length c) 1) (not (first c)))) 22 e 23 (syntax-property e 'first-comments c))) 24 25 (define/contract (with-comments-after e c) 26 (-> syntax? (or/c #f comments-after/c) syntax?) 27 (if (or (not c) (null? c)) 28 e 29 (syntax-property e 'comments-after c))) 30 31 (define/contract (extract-first-comments stx) 32 (-> syntax? (or/c #f first-comments/c)) 33 (syntax-property stx 'first-comments)) 34 35 (define/contract (extract-comments-after stx) 36 (-> syntax? (or/c #f comments-after/c)) 37 (syntax-property stx 'comments-after))