Added guarded exception catches

This commit is contained in:
Jonathan Turner
2009-09-19 13:30:11 +00:00
parent 6a47846b84
commit 813fa055a3
5 changed files with 98 additions and 5 deletions

View File

@@ -947,11 +947,17 @@ namespace chaiscript
while (has_matches) {
while (Eol());
has_matches = false;
if (Keyword("catch", true)) {
if (Keyword("catch", false)) {
int catch_stack_top = match_stack.size();
if (Char('(')) {
if (!(Id(true) && Char(')'))) {
throw Eval_Error("Incomplete 'catch' expression", File_Position(line, col), filename);
}
if (Char(':')) {
if (!Expression()) {
throw Eval_Error("Missing guard expression for catch", File_Position(line, col), filename);
}
}
}
while (Eol());
@@ -959,7 +965,7 @@ namespace chaiscript
if (!Block()) {
throw Eval_Error("Incomplete 'catch' block", File_Position(line, col), filename);
}
build_match(Token_Type::Catch, catch_stack_top);
has_matches = true;
}
}