[racket-dev] syntax-parse ~once keyword sometimes does not report too-few error?

From: Stephen Chang (stchang at ccs.neu.edu)
Date: Thu Jul 25 17:41:40 EDT 2013

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?

Posted on the dev mailing list.