summaryrefslogtreecommitdiff
path: root/doc/ref
diff options
context:
space:
mode:
authorMark H Weaver <mhw@netris.org>2013-12-19 13:22:50 -0500
committerMark H Weaver <mhw@netris.org>2014-01-09 17:43:53 -0500
commit0e18163366c2f2a0caecde18241dbd7987b4db7c (patch)
tree54b62c783506a8024fc2873f1997ca8783095cb0 /doc/ref
parent1624e149f75747310c9ce15db7db5324a538f8f8 (diff)
downloadguile-0e18163366c2f2a0caecde18241dbd7987b4db7c.tar.gz
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.
Diffstat (limited to 'doc/ref')
-rw-r--r--doc/ref/api-macros.texi24
1 files changed, 24 insertions, 0 deletions
diff --git a/doc/ref/api-macros.texi b/doc/ref/api-macros.texi
index 0d604004f..030daedb0 100644
--- a/doc/ref/api-macros.texi
+++ b/doc/ref/api-macros.texi
@@ -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