racket / scribble

Other
194 stars 90 forks source link

Add constraints that descriptions must be non-keyword #360

Closed sorawee closed 1 year ago

sorawee commented 1 year ago

The following program:

@defform[(stream elem-expr ...)
         #:literals (values)
         #:grammar ([elem-expr (values single-expr ...)
                               single-expr])]{
  Description ...
}

is faulty because #:literals (values) is misplaced. It should come before (stream elem-expr ...). However, the error that occurs is very confusing.

elem-expr: misuse of an identifier (not in `racket', etc.) that is bound as a code-typesetting variable

When parsing the form, #:literals ... #:grammar ... becomes a part of the description because there is no constraint that the description must not be keywords. The resulting expansion is (list #:literals .... #:grammar <grammar> ....), which happens to be valid, though <grammar> is not meant to be an expression. This is the cause of the mentioned confusing error message.

This PR adds the constraint that desc must be non-keyword, so that the above program errors appropriately on parsing.