engine: resources, lang: funcs, parser: Add panic magic
It's valuable to check your runtime values and to shut down the entire engine in case something doesn't match. This patch adds some magic plumbing to support a "panic" mechanism. A new "panic" statement gets transparently converted into a panic function and panic resource. The former errors if the input is not empty. The latter must be present to consume the value, but doesn't actually do anything.
This commit is contained in:
@@ -92,6 +92,7 @@ func init() {
|
||||
%token CLASS_IDENTIFIER INCLUDE_IDENTIFIER
|
||||
%token IMPORT_IDENTIFIER AS_IDENTIFIER
|
||||
%token COMMENT ERROR
|
||||
%token PANIC_IDENTIFIER
|
||||
|
||||
// precedence table
|
||||
// "Operator precedence is determined by the line ordering of the declarations;
|
||||
@@ -169,6 +170,11 @@ stmt:
|
||||
posLast(yylex, yyDollar) // our pos
|
||||
$$.stmt = $1.stmt
|
||||
}
|
||||
| panic
|
||||
{
|
||||
posLast(yylex, yyDollar) // our pos
|
||||
$$.stmt = $1.stmt
|
||||
}
|
||||
| resource
|
||||
{
|
||||
posLast(yylex, yyDollar) // our pos
|
||||
@@ -919,6 +925,22 @@ bind:
|
||||
}
|
||||
}
|
||||
;
|
||||
panic:
|
||||
// panic("some error")
|
||||
PANIC_IDENTIFIER OPEN_PAREN call_args CLOSE_PAREN
|
||||
{
|
||||
posLast(yylex, yyDollar) // our pos
|
||||
call := &ast.ExprCall{
|
||||
Name: $1.str,
|
||||
Args: $3.exprs,
|
||||
//Var: false, // default
|
||||
}
|
||||
$$.stmt = &ast.StmtBind{
|
||||
Ident: interfaces.PanicVarName, // make up a placeholder var
|
||||
Value: call,
|
||||
}
|
||||
}
|
||||
;
|
||||
/* TODO: do we want to include this?
|
||||
// resource bind
|
||||
rbind:
|
||||
|
||||
Reference in New Issue
Block a user