1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-22 19:44:10 +02:00

Implement R7RS 'syntax-error'.

* module/ice-9/psyntax.scm (syntax-error): New macro.
  (syntax-rules): Handle 'syntax-error' templates specially
  for improved error reporting.

* module/ice-9/psyntax-pp.scm: Regenerate.

* doc/ref/api-macros.texi (Syntax Rules): Add new subsection "Reporting
  Syntax Errors in Macros".

* test-suite/tests/syntax.test: Add tests.
This commit is contained in:
Mark H Weaver 2013-12-19 13:22:50 -05:00
parent 1624e149f7
commit 0e18163366
4 changed files with 172 additions and 21 deletions

View file

@ -363,6 +363,30 @@ Cast into this form, our @code{when} example is significantly shorter:
(if c (begin e ...)))
@end example
@subsubsection Reporting Syntax Errors in Macros
@deffn {Syntax} syntax-error message [arg ...]
Report an error at macro-expansion time. @var{message} must be a string
literal, and the optional @var{arg} operands can be arbitrary expressions
providing additional information.
@end deffn
@code{syntax-error} is intended to be used within @code{syntax-rules}
templates. For example:
@example
(define-syntax simple-let
(syntax-rules ()
((_ (head ... ((x . y) val) . tail)
body1 body2 ...)
(syntax-error
"expected an identifier but got"
(x . y)))
((_ ((name val) ...) body1 body2 ...)
((lambda (name ...) body1 body2 ...)
val ...))))
@end example
@subsubsection Specifying a Custom Ellipsis Identifier
When writing macros that generate macro definitions, it is convenient to