Skip to content

Commit

Permalink
add finally to main try..catch
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed May 23, 2024
1 parent d734c47 commit d24e59a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/grammar.peg
Original file line number Diff line number Diff line change
Expand Up @@ -235,20 +235,20 @@
variable = make_identifier(variable);
return is_exit(variable, throw_expression(variable));
}
function main_try_catch(body) {
function main_try_catch(body, finalize) {
var err_var = make_identifier("e");
return try_catch_simple(body, 'e', [
is_not_exit(err_var,
expression_statement(gaiman_call('error', err_var))
)
]);
], finalize);
}
function try_catch(body, error_var, catch_clause) {
return try_catch_simple(body, error_var, [
throw_if_error(error_var)
].concat(catch_clause));
}
function try_catch_simple(body, error_var, catch_clause) {
function try_catch_simple(body, error_var, catch_clause, finalize) {
return {
"type": "TryStatement",
"block": make_block(body),
Expand All @@ -259,7 +259,8 @@
"name": error_var
},
"body": make_block(catch_clause)
}
},
"finalizer": finalize && make_block(finalize)
};
}
function jump(name) {
Expand Down Expand Up @@ -313,7 +314,7 @@
var extra_single = ["sleep*", "get*"];
var blacklist_properties = ["constructor", "__proto__", "prototype"];
var variable_prefix = '$_';
var stop_exception = make_identifier('Gaiman_Exit');
var stop_exception = make_identifier('Exit');
}}

{
Expand Down Expand Up @@ -402,8 +403,9 @@ Start = statements:statements {
"type": "Program",
"body": [
main([
main_try_catch(statements),
expression_statement(gaiman_call('exit'))
main_try_catch(statements, [
expression_statement(gaiman_call('exit'))
])
])
]
};
Expand Down

0 comments on commit d24e59a

Please sign in to comment.