From: Willem B. <met...@gm...> - 2008-05-17 13:36:13
|
On Sat, May 17, 2008 at 3:12 PM, Richard M Kreuter <kr...@pr...> wrote: > "Willem Broekema" writes: >> In CLPython, certain Python syntax errors are detected during >> macroexpansion, and they throw my own SyntaxError condition. I'd like >> to handle these errors myself, instead of having the SBCL compiler >> catch and report them. The below patch makes that possible, by >> introducing the boolean *trap-macroexpand-errors*. > I may be misunderstanding your proposed change, but can't you use > *MACROEXPAND-HOOK* to set up your custom error handling? The following > seems to be a start: > > * (defvar *initial-macroexpand-hook* *macroexpand-hook*) > > *INITIAL-MACROEXPAND-HOOK* > * (setq *macroexpand-hook* > #'(lambda (expander form env) > (handler-bind ((error (lambda (e) > ;; Your stuff could go here. > (invoke-debugger e)))) > (funcall *initial-macroexpand-hook* expander form env)))) This would work if I always want to enter the debugger, when a macro gave SyntaxError. That is not the case, as there could be a handler for the condition outside the call to compile, like: (handler-case (compile nil '(lambda () (python-code))) (SyntaxError (c) ...)) ;; detected in macroexpansion Maybe you took the "myself" in "I'd like to handle these [SyntaxErrors] myself" a bit more literal than intended. :) - Willem |