[racket] Abstract datum literal out of syntax class
Asumu found a solution that works reasonably well:
(define-splicing-syntax-class (maybe-clause expected-clause-name
default-value)
#:attributes (ast)
(pattern (clause-name elements ...)
#:when (eq? (syntax-e #'clause-name) (syntax-e
expected-clause-name))
#:attr ast #'(clause-name elements ...))
(pattern (~seq) #:attr ast default-value))
Explicitly doing the comparison instead of allowing syntax-parse to do it
for me isn't ideal, but since this is isolated to one bit of code, it's
fine. I think what I'd really like requires some sort of reflection on
syntax patterns, which may be available, but I'm not going to spend time to
look into it right now.
On Mon, Feb 17, 2014 at 4:24 PM, Jonathan Schuster <schuster at ccs.neu.edu>wrote:
> Is there a way to abstract datum literals out of a (splicing) syntax
> class? I have a number of patterns that look something like this:
>
> (~optional (clause-name: element ...))
>
> and I'd like to factor that out into a common syntax class, but be able to
> specialize it according to the specific clause name I'm expecting. For
> example, instead of something like this:
>
> (~optional (my-clause: element ...))
>
> I would have a syntax class called "maybe-clause" and just write
>
> (~var clause (maybe-clause my-clause:))
>
> Is this possible?
>
> P.S. I know that I should be using literals instead of datum literals, but
> that's a refactoring that needs to happen to this code later on. In any
> case, I assume one has the same problems with literals, too.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140217/b4217acd/attachment.html>