[racket] is there any way to tell syntax-parse to parse a pattern within a parametization ?
Two things:
1) syntax-classes can take parameters, so you can pass an argument to x that is a boolean, within-y?. You can't create a parameterization scope because this is all within the parsing code for syntax-parse. You could mutate a box or parameter with a ~do pattern and reset it after the patterns you want within that "scope," but c'mon. Don't do that.
(define-syntax-class (x within-y?)
(pattern _ #:when within-y?))
(define-syntax-class y
(pattern (~var dummy (x #t))))
[the use-case of nothing to the left of a : to indicate non-binding is something that should be extended to parameterized syntax-classes, probably.]
2) If you're communicating between macros and not syntax-classes, you want to use syntax-parameters.
(require racket/stxparam)
(define-syntax-parameter within-y? #f)
(define-syntax-rule (y body) (syntax-parameterize ([within-y? #t]) body))
(define-syntax-class x
(pattern _ #:when (syntax-parameter-value #'within-y?)))
-Ian
----- Original Message -----
From: "Alexander D. Knauth" <alexander at knauth.org>
To: "racket users list" <users at racket-lang.org>
Sent: Friday, August 1, 2014 12:23:21 PM GMT -05:00 US/Canada Eastern
Subject: [racket] is there any way to tell syntax-parse to parse a pattern within a parametization ?
Is there any way to tell syntax-parse to parse a pattern within a parametization ?
For example in something like this:
(define within-y? (make-parameter #f))
(define-syntax-class x
[pattern _ #:when (within-y?)])
(define-syntax-class y
[pattern :x])
(define (parse stx)
(syntax-parse stx
[:y #t]))
How do I tell it to parse the y syntax-class within a (parameterize ([within-y? #t]) …) form?
____________________
Racket Users list:
http://lists.racket-lang.org/users