Modified syntax-case & friends to use with-pvars. Closes 181 current-pvars: use in syntax-case, with-syntax, define/with-syntax, is there any with-parse?

This commit is contained in:
Georges Dupéron 2017-01-23 19:55:26 +01:00
parent 22053c0e0b
commit e117e4f919
4 changed files with 48 additions and 9 deletions

10
case.rkt Normal file
View File

@ -0,0 +1,10 @@
(module case '#%kernel
(#%require "case/stxloc.rkt"
"case/syntax.rkt"
"case/with-stx.rkt")
(#%provide syntax-case
syntax-case*
define/with-syntax
with-syntax
datum-case
with-datum))

View File

@ -4,6 +4,7 @@
(module stxcase '#%kernel (module stxcase '#%kernel
(#%require racket/private/stx racket/private/small-scheme '#%paramz '#%unsafe (#%require racket/private/stx racket/private/small-scheme '#%paramz '#%unsafe
racket/private/ellipses racket/private/ellipses
stxparse-info/current-pvars
(for-syntax racket/private/stx racket/private/small-scheme (for-syntax racket/private/stx racket/private/small-scheme
racket/private/member racket/private/sc '#%kernel)) racket/private/member racket/private/sc '#%kernel))
@ -484,9 +485,13 @@
null null
(if fender (if fender
(list (quote-syntax if) fender (list (quote-syntax if) fender
answer (list (quote-syntax with-pvars)
pattern-vars
answer)
do-try-next) do-try-next)
answer))) (list (quote-syntax with-pvars)
pattern-vars
answer))))
do-try-next))]) do-try-next))])
(if fender (if fender
(list (list

View File

@ -1,5 +1,6 @@
#lang racket/base #lang racket/base
(require (only-in "stxloc.rkt" syntax-case) (require (only-in "stxloc.rkt" syntax-case)
stxparse-info/current-pvars
(for-syntax racket/base (for-syntax racket/base
racket/private/sc)) racket/private/sc))
(provide define/with-syntax (provide define/with-syntax
@ -45,7 +46,8 @@
(values (pvar-value pvar) ...))) (values (pvar-value pvar) ...)))
(define-syntax pvar (define-syntax pvar
(make-syntax-mapping 'depth (quote-syntax valvar))) (make-syntax-mapping 'depth (quote-syntax valvar)))
...)))])) ...
(define-pvars (pvar ...)))))]))
;; Ryan: alternative name: define/syntax-pattern ?? ;; Ryan: alternative name: define/syntax-pattern ??
;; auxiliary macro ;; auxiliary macro

View File

@ -19,12 +19,12 @@
Source code: @url{https://github.com/jsmaniac/stxparse-info} Source code: @url{https://github.com/jsmaniac/stxparse-info}
@defmodule[stxparse-info/parse] @defmodule[stxparse-info]
The module @racketmodname[stxparse-info/parse] is a patched version of This library provides some patched versions of @racketmodname[syntax/parse]
@racketmodname[syntax/parse] which tracks which syntax pattern variables are and the @racket[syntax-case] family. These patched versions track which syntax
bound. This allows some libraries to change the way syntax pattern variables pattern variables are bound. This allows some libraries to change the way
work. syntax pattern variables work.
For example, @racketmodname[phc-graph/subtemplate] automatically derives For example, @racketmodname[phc-graph/subtemplate] automatically derives
temporary identifiers when a template contains @racket[yᵢ …], and @racket[xᵢ] temporary identifiers when a template contains @racket[yᵢ …], and @racket[xᵢ]
@ -32,6 +32,23 @@ is a pattern variable. To know from which @racket[varᵢ] the @racket[yᵢ …]
identifiers must be derived, @racketmodname[phc-graph/subtemplate] needs to identifiers must be derived, @racketmodname[phc-graph/subtemplate] needs to
know which syntax pattern variables are within scope. know which syntax pattern variables are within scope.
@section{Tracking currently-bound pattern variables with @racket[syntax-parse]}
@defmodule[stxparse-info/parse]
The module @racketmodname[stxparse-info/parse] provides patched versions of
@racketmodname[syntax/parse] @racketmodname[define/syntax-parse] which track
which syntax pattern variables are bound.
@section{Tracking currently-bound pattern variables with @racket[syntax-parse]}
@defmodule[stxparse-info/case]
The module @racketmodname[stxparse-info/case] provides patched versions of
@racket[syntax-case], @racket[syntax-case*], @racket[with-syntax],
@racket[define/with-syntax], @racket[datum-case] and @racket[with-datum] which
track which syntax or datum pattern variables are bound.
@section{Reading and updating the list of currently-bound pattern variables} @section{Reading and updating the list of currently-bound pattern variables}
@defmodule[stxparse-info/current-pvars] @defmodule[stxparse-info/current-pvars]
@ -40,7 +57,12 @@ know which syntax pattern variables are within scope.
(current-pvars) (listof identifier?)]{ (current-pvars) (listof identifier?)]{
This for-syntax procedure returns the list of syntax pattern variables which This for-syntax procedure returns the list of syntax pattern variables which
are known to be bound. The most recently bound variables are at the beginning are known to be bound. The most recently bound variables are at the beginning
of the list.} of the list.
It is the responsibility of the reader to check that the identifiers are
bound, and that they are bound to syntax pattern variables, for example using
@racket[identifier-binding] and @racket[syntax-pattern-variable?]. This allows
libraries to also track variables bound by match-like forms, for example.}
@defform[(with-pvars (pvar ...) . body) @defform[(with-pvars (pvar ...) . body)
#:contracts ([pvar identifier?])]{ #:contracts ([pvar identifier?])]{