lang: ast: implement parsing of try-catch-finally statements

This commit is contained in:
2025-01-16 13:15:48 +00:00
parent 143d61e329
commit 46d244a28d
6 changed files with 352 additions and 10 deletions

View File

@@ -37,6 +37,8 @@ extern struct ast_node_type pkg_static_node_ops;
extern struct ast_node_type pkg_static_item_node_ops;
extern struct ast_node_type pkg_dynamic_node_ops;
extern struct ast_node_type discard_node_ops;
extern struct ast_node_type try_node_ops;
extern struct ast_node_type try_catch_node_ops;
static const struct ast_node_type *node_ops[] = {
[IVY_AST_UNIT] = &unit_node_ops,
@@ -70,6 +72,8 @@ static const struct ast_node_type *node_ops[] = {
[IVY_AST_PKG_ITEM] = &pkg_static_item_node_ops,
[IVY_AST_PKG_DYNAMIC] = &pkg_dynamic_node_ops,
[IVY_AST_DISCARD] = &discard_node_ops,
[IVY_AST_TRY] = &try_node_ops,
[IVY_AST_TRY_CATCH] = &try_catch_node_ops,
};
static const size_t nr_node_ops = sizeof node_ops / sizeof node_ops[0];
@@ -116,7 +120,6 @@ enum token_expr_type get_token_expr_type(struct ivy_token *tok)
case IVY_KW_FOR:
case IVY_KW_WHILE:
case IVY_KW_TRY:
case IVY_KW_CATCH:
case IVY_KW_THROW:
return TOK_EXPR_BEGIN;
default:
@@ -283,6 +286,8 @@ const char *ivy_ast_node_type_to_string(enum ivy_ast_node_type v)
ENUM_STR(IVY_AST_PKG_ITEM);
ENUM_STR(IVY_AST_PKG_DYNAMIC);
ENUM_STR(IVY_AST_RETURN);
ENUM_STR(IVY_AST_TRY);
ENUM_STR(IVY_AST_TRY_CATCH);
ENUM_STR(IVY_AST_TYPE_COUNT);
default:
return "";