www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

syntax-parse.scrbl (3578B)


      1 #lang scribble/manual
      2 @require[racket/require
      3          "utils.rkt"
      4          @for-label[phc-toolkit/syntax-parse
      5                     racket/base
      6                     syntax/parse]]
      7 
      8 @title{@racket[syntax-parse] helpers}
      9 @author{@author+email["Suzanne Soy" "racket@suzanne.soy"]}
     10 
     11 @defmodule[phc-toolkit/syntax-parse
     12            #:use-sources
     13            [(submod (lib "phc-toolkit/syntax-parse.rkt") typed)]]
     14 
     15 @defidform[stx]{
     16  This identifier can only be used in the body of some forms,
     17  like @racket[define-syntax]. It is an error to use it as an
     18  expression elsewhere.}
     19 
     20 @defform[(define-syntax/case (name . args) (literal-id ...) . body)]{
     21  This form is roughly equivalent to:
     22  
     23  @racketblock[(define-syntax (name stx)
     24                 (syntax-case stx (literal-id ...)
     25                   [(_ . args) (let () . body)]))]
     26  
     27  Within @racket[body], the syntax parameter @racket[stx] can be used to refer to
     28  the whole syntax given as an argument to @racket[name].}
     29 
     30 
     31 @(define ntax-patterns (tech #:doc '(lib "syntax/scribblings/syntax.scrbl")
     32                              #:key "syntax pattern"
     33                              "syntax-patterns"))
     34 @(define ttern-directive (tech #:doc '(lib "syntax/scribblings/syntax.scrbl")
     35                                #:key "pattern-directive"
     36                                "pattern-directive"))
     37 
     38 @(define tterns
     39    @seclink["stx-patterns"
     40             #:doc '(lib "scribblings/reference/reference.scrbl")]{patterns})
     41 
     42 @(define ttern
     43    @seclink["stx-patterns"
     44             #:doc '(lib "scribblings/reference/reference.scrbl")]{pattern})
     45 
     46 @defform[(define-syntax/parse (name . #,ntax-patterns)
     47            #,ttern-directive ... . body)]{
     48  This form is roughly equivalent to:
     49 
     50  @racketblock[(define-syntax (name stx)
     51                 (syntax-parse stx
     52                   [(_ . #,ntax-patterns) #,ttern-directive ... . body]))]
     53  
     54  Within the @racket[#,ntax-patterns], the @racket[#,ttern-directive] and the
     55  @racket[body], the syntax parameter @racket[stx] can be used to refer to the
     56  whole syntax given as an argument to @racket[name].}
     57 
     58 @defform[(λ/syntax-parse (name . #,ntax-patterns)
     59            #,ttern-directive ... . body)]{
     60  This form is roughly equivalent to:
     61 
     62  @racketblock[(λ (stx)
     63                 (syntax-parse stx
     64                   [(_ . #,ntax-patterns) #,ttern-directive ... . body]))]
     65  
     66  Within the @racket[#,ntax-patterns], the @racket[#,ttern-directive] and the
     67  @racket[body], the syntax parameter @racket[stx] can be used to refer to the
     68  whole syntax given as an argument to the function.}
     69 
     70 @defform[(define-for-syntax/case-args (name (pattern ...)) . body)]{
     71  This form is roughly equivalent to:
     72 
     73  @racketblock[(define-for-syntax (name _arg ...)
     74                 (with-syntax ([pattern _arg] ...)
     75                   . body))]
     76 
     77  where each @racket[_arg] is a fresh identifier.}
     78 
     79 
     80 @defform[(λ/syntax-case #,tterns (literal ...) . body)]{
     81  This form is roughly equivalent to:
     82 
     83  @racketblock[(λ (stx)
     84                 (syntax-case stx (literal ...)
     85                   [(_ . #,tterns) ... . body]))]
     86  
     87  Within the @racket[#,tterns], and the @racket[body], the syntax parameter
     88  @racket[stx] can be used to refer to the whole syntax given as an argument to
     89  the function.}
     90 
     91 @defform[(define/case-args (name (#,ttern ...)) . body)]{
     92  This form is roughly equivalent to:
     93 
     94  @racketblock[(define (name _arg ...)
     95                 (with-syntax ([#,ttern _arg] ...)
     96                   . body))]
     97 
     98  where each @racket[_arg] is a fresh identifier.}
     99 
    100 @include-section{syntax-parse-pattern-expanders.scrbl}
    101 @include-section{syntax-parse-untyped.scrbl}