[R6RS] Syntax errors

Michael Sperber sperber at informatik.uni-tuebingen.de
Sun Aug 13 05:14:13 EDT 2006

As per the recent exchange between Matthew and myself, I propose that
we add the following condition type:

(define-condition-type &syntax &defect
  (expression syntax-defect-expression)
  (subexpression syntax-defect-subexpression))

... and the following convenience procedure to the syntax-case library
(essentially corresponding to MzScheme's `raise-syntax-error'):

(syntax-defect name string expr)
(syntax-defect name string expr subexpr)

raises an exception condition types &who and &syntax.  The field of
&who is initialized according to name and expr.  The expr and
optionally the subexpr arguments become the corresponding fields of
&syntax.  To save myself work for now, I replicate the docs from the
MzScheme manual.  Not all details match, but they should be clear

> Macros use this procedure to report syntax errors. The name argument
> is usually #f when expr is provided; it is described in more detail
> below. The message-string is used as the main body of the error
> message. The optional expr argument is the erroneous source syntax
> object or S-expression. The optional sub-expr argument is a syntax
> object or S-expression within expr that more precisely locates the
> error. If sub-expr is provided, it is used (in syntax form) for the
> exprs field of the generated exception record, else the expr is used
> if provided, otherwise the exprs field is the empty list. Source
> location information in the error-message text is similarly
> extracted from sub-expr or expr, when at least one is a syntax
> object.

> The form name used in the generated error message is determined
> through a combination of the name, expr, and sub-expr arguments. The
> name argument can #f or a symbol:

> * #f: When name is #f, and when expr is either an identifier or a
>   #syntax pair containing an identifier as its first element, then
>   #the form name from the error message is the identifier's symbol.

>   If expr is not provided, or if it is not an identifier or a syntax
>   pair containing and identifier as its first element, then the form
>   name in the error message is "?".

> * symbol: When name is a symbol, then the symbol is used as the form
>   name in the generated error message.

Cheers =8-} Mike
Friede, Völkerverständigung und überhaupt blabla

More information about the R6RS mailing list