- Subject: Re: [slang-users] new slang 2 development snapshot released
- From: Michael Noble <mnoble@xxxxxxxxxxxxx>
- Date: Sun, 21 Nov 2004 19:31:12 -0500
> John, what we be required for s-lang to "verify" code syntax snippets.
>
> This would help out tremendously with my SLAG project, since I will be
> storing "functions" in files along with the display/print items ...
Below is what I use in VWhere (visual 'where, bundled with SLgtk) to
validate expressions users have typed into a text window. It consists
of an ERROR_BLOCK in S-Lang scope, and 2 C functions (one registered
as S-Lang intrinsic).
I think the exception handling mechanisms in SLang2 will make this
kind of stuff cleaner and more robust.
Cheers,
-Mike
-----------------------------------------------------------------------
ERROR_BLOCK
{
_clear_error();
_toggle_error_hook();
return vw_echo_status(vwd,
sprintf("could not evaluate expression: %s",expr),NULL);
}
% Custom error hook, to enable recovery from normally unrecoverable errs
variable nargs = _stkdepth();
_toggle_error_hook();
eval(expr);
_toggle_error_hook();
The toggle function is a C intrinsic, and looks something like
static void recover_unrecoverable_error_hook(char *error_msg)
{
fputs(error_msg,stderr); /* support function, which lets scripts */
fputs("\r\n", stderr); /* catch "unrecoverable" errors within */
fflush (stderr); /* an ERROR_BLOCK */
SLang_restart(0);
SLang_set_error(SL_USAGE_ERROR);
}
static void toggle_error_hook(void)
{
static void (*previous_error_hook)(char *);
if (SLang_Error_Hook == recover_unrecoverable_error_hook)
SLang_Error_Hook = previous_error_hook;
else {
previous_error_hook = SLang_Error_Hook;
SLang_Error_Hook = recover_unrecoverable_error_hook;
}
}
_______________________________________________
To unsubscribe, visit http://jedsoft.org/slang/mailinglists.html
[2004 date index]
[2004 thread index]
[Thread Prev] [Thread Next]
[Date Prev] [Date Next]