[racket] syntax-case and multiple ellipsis
Here is a syntax-case only solution:
(define-syntax (foo stx)
(syntax-case stx (in def)
[(_ name . more)
#'(collect-defs () name . more)]))
(define-syntax (collect-defs stx)
(syntax-case stx (in def)
[(_ (defs-seen ...) name (def a ...) . more)
#'(collect-defs (defs-seen ... (def a ...)) name . more)]
[(_ defs name . more)
#'(collect-ins defs () name . more)]))
(define-syntax (collect-ins stx)
(syntax-case stx (in def)
[(_ defs (ins-seen ...) name (in clause ...) . more)
#'(collect-ins defs (ins-seen ... (in clause ...)) name . more)]
[(_ defs ins name . more)
#'(finish defs ins name . more)]))
(define-syntax (finish stx)
(syntax-case stx ()
[(_ defs ins name . more)
#''((definitions: defs)
(ins: ins)
(name: name)
(more: more))]))
(foo "a-name"
(def x 41)
(def y 42)
(in a)
(in b)
"yada")
/Jens Axel
2014-06-17 20:08 GMT+02:00 Spencer Florence <spencer at florence.io>:
> Unfortunately I'm working in typed racket, which (as far as I can tell)
> doesn't play nice with syntax-parse. Any other ideas?
>
>
> On Tue, Jun 17, 2014 at 1:04 PM, Jens Axel Søgaard <jensaxel at soegaard.net>
> wrote:
>>
>> Hi Spencer,
>>
>> The problem is that syntax-case pattern doesn't allow allow
>> pattern of the form (x ... y ...) that is with two ellipsis on the
>> same level.
>>
>> Luckily syntax-parse allow these:
>>
>> (require syntax/parse)
>>
>> (syntax-parse #'(a a a a 41 42 43)
>> [(c ... d ...)
>> #''((c ...) (d ...))])
>>
>> (syntax-parse #'(a a a a 41 42 43)
>> [(c:id ... d ...)
>> #''((c ...) (d ...))])
>>
>>
>> /Jens Axel
>>
>>
>>
>>
>> 2014-06-17 19:46 GMT+02:00 Spencer Florence <florence at northwestern.edu>:
>> > Hey all,
>> >
>> > I'm trying to write a macro with syntax-case that looks something like
>> > this:
>> >
>> > (syntax-case stx (in def)
>> > [(_ name
>> > (def a ...) ...
>> > (in clause do ...) ...)
>> > stuff])
>> >
>> > But, this gives me the error "syntax-case: misplaced ellipsis in pattern
>> > (follows other ellipsis)" on the last ellipsis. Does anyone know a way
>> > around this?
>> >
>> > --spencer
>> >
>> > ____________________
>> > Racket Users list:
>> > http://lists.racket-lang.org/users
>> >
>>
>>
>>
>> --
>> --
>> Jens Axel Søgaard
>>
>> ____________________
>> Racket Users list:
>> http://lists.racket-lang.org/users
>
>
--
--
Jens Axel Søgaard