[racket-dev] syntax-parse ~once keyword sometimes does not report too-few error?
On 07/25/2013 05:41 PM, Stephen Chang wrote:
> Here is a syntax-parse macro that requires one subexpression to be
> wrapped with an exclamation point.
>
> (define-syntax (test stx)
> (syntax-parse stx #:datum-literals (!)
> [((~or (~once (! x:expr) #:name "!")
> (~not (! y:expr))) ...)
> #'42]))
>
> Everything works like I would expect:
>
> (test (! 1) (! 2)) => test: too many occurrences of ! in: ()
> (test (! 1) 2) => 42
> (test 1 2) => test: missing required occurrence of ! in: ()
>
>
> Here is the same macro but with an extra ~seq and an extra pair of
> parens around the pattern:
>
> (define-syntax (test stx)
> (syntax-parse stx #:datum-literals (!)
> [((~seq (~or (~once (! x:expr) #:name "!")
> (~not (! y:expr))) ...))
> #'42]))
>
> Here are the same tests:
>
> (test (! 1) (! 2)) => test: too many occurrences of ! in: ()
> (test (! 1) 2) => 42
> (test 1 2) => test: bad syntax in: (test 1 2)
>
> I expected the same outputs as the first macro, but the last test
> example only reports "bad syntax" and not "too few". Is this expected
> behavior that I'm not understanding or a bug?
That's a bug. Two bugs, actually: your two examples should behave the
same, and "too-few" failures should be ranked higher. I'm working on a fix.
Ryan