[plt-scheme] paren-shape bug?
At Tue, 28 Apr 2009 18:03:23 -0400 (EDT), Dimitris Vyzovitis wrote:
> Actually, this is something that has been bugging me for a while with
> compiled code, but I don't know the right way to fix it.
> The straightforward syntax walk with syntax/quasisyntax wrapper macros
> doesn't work:
It's difficult, at best, and you'd have to wrap the patter-variable
binders so that you could keep track of pattern variables. But I did
this for R6RS, where `syntax' has different wrapping rules than in
`scheme/base'.
I've now extracted and generalized that R6RS-support code as a new
`syntax/template' library (and also added `syntax-pattern-variable?' to
`scheme/base', so that no wrapper is needed on the pattern-binding
forms).
At Tue, 28 Apr 2009 19:22:10 -0400, Ryan Culpepper wrote:
> It could also be fixed at the level of 'syntax-case', 'syntax' etc.
> They could store the shape separately from the pattern. You could
> generalize that to storing other properties, too. The code is in
> scheme/private/stxclass and scheme/private/sc, though; I don't see a
> good way to change or reuse it from outside.
So, `syntax/template' is now supposed to be the reusable and
generalizable layer.
Here's an example use of `syntax/template' to implements a
`syntax/shape' form that preserves the 'paren-shape property:
(define-for-syntax (get-shape-prop stx)
(syntax-property stx 'paren-shape))
(define (add-shape-prop v stx datum)
(syntax-property (datum->syntax stx datum stx stx stx)
'paren-shape
v))
(define-syntax (syntax/shape stx)
(syntax-case stx ()
[(_ tmpl)
(transform-template #'tmpl
#:save get-shape-prop
#:restore-stx #'add-shape-prop)]))