I’m struggling with matching strings as part of a syntax-case
statement. In the context of a reader I’m making, I would like to be able to detect 2 or more strings containing a new line, followed by anything else. This is a minimal example: (define (detect-new-paragraph doc)
(syntax-case doc ()
[("\n" "\n" ... . tail)
#'(new-paragraph tail)]
[_
#`(something-else #,doc)]))
But when I try to match e.g. #'("\n" "\n" 'foo 'bar)
, I don’t get the expected result, which would be #'(new-paragraph 'foo 'bar)
. The problem seems to be with the ellipsis, because if I remove it, I can match exactly two newlines. Anybody has some idea what’s happening? Thanks! :blush:
This is either a limitation of syntax-case
, or a bug. In any case, I would suggest you to use syntax-parse
instead, which can handle your example correctly.
#lang racket
(require syntax/parse)
(define (detect-new-paragraph doc)
(syntax-parse doc
[("\n" "\n" ... . tail)
#'(new-paragraph tail)]
[_
#`(something-else #,doc)]))
(detect-new-paragraph #'("\n" "\n" 'foo 'bar))
Oh alright, thanks! In general, would you recommend syntax-parse
over syntax-case
?
Yep
Cool, thanks for the advice!