lang: ast: get_token_expr_type now uses the operator table to discern expression symbols
This commit is contained in:
@@ -12,6 +12,7 @@ extern struct ast_node_type class_node_ops;
|
||||
extern struct ast_node_type msgh_node_ops;
|
||||
extern struct ast_node_type selector_node_ops;
|
||||
extern struct ast_node_type expr_node_ops;
|
||||
extern struct ast_node_type block_node_ops;
|
||||
|
||||
static const struct ast_node_type *node_ops[] = {
|
||||
[IVY_AST_UNIT] = &unit_node_ops,
|
||||
@@ -21,6 +22,7 @@ static const struct ast_node_type *node_ops[] = {
|
||||
[IVY_AST_MSGH] = &msgh_node_ops,
|
||||
[IVY_AST_SELECTOR] = &selector_node_ops,
|
||||
[IVY_AST_EXPR] = &expr_node_ops,
|
||||
[IVY_AST_BLOCK] = &block_node_ops,
|
||||
};
|
||||
static const size_t nr_node_ops = sizeof node_ops / sizeof node_ops[0];
|
||||
|
||||
@@ -35,6 +37,8 @@ const struct ast_node_type *get_ast_node_type(enum ivy_ast_node_type type)
|
||||
|
||||
enum token_expr_type get_token_expr_type(struct ivy_token *tok)
|
||||
{
|
||||
const struct ivy_operator *op = NULL;
|
||||
|
||||
switch (tok->t_type) {
|
||||
case IVY_TOK_IDENT:
|
||||
case IVY_TOK_INT:
|
||||
@@ -48,33 +52,11 @@ enum token_expr_type get_token_expr_type(struct ivy_token *tok)
|
||||
case IVY_SYM_LEFT_PAREN:
|
||||
case IVY_SYM_CARET:
|
||||
return TOK_EXPR_BEGIN;
|
||||
case IVY_SYM_PLUS:
|
||||
case IVY_SYM_HYPHEN:
|
||||
case IVY_SYM_FORWARD_SLASH:
|
||||
case IVY_SYM_ASTERISK:
|
||||
case IVY_SYM_PIPE:
|
||||
case IVY_SYM_COMMA:
|
||||
case IVY_SYM_SEMICOLON:
|
||||
case IVY_SYM_EQUAL:
|
||||
case IVY_SYM_PLUS_EQUAL:
|
||||
case IVY_SYM_HYPHEN_EQUAL:
|
||||
case IVY_SYM_FORWARD_SLASH_EQUAL:
|
||||
case IVY_SYM_ASTERISK_EQUAL:
|
||||
case IVY_SYM_AMPERSAND_EQUAL:
|
||||
case IVY_SYM_PIPE_EQUAL:
|
||||
case IVY_SYM_PERCENT_EQUAL:
|
||||
case IVY_SYM_CARET_EQUAL:
|
||||
case IVY_SYM_PERCENT:
|
||||
case IVY_SYM_AMPERSAND:
|
||||
case IVY_SYM_DOUBLE_EQUAL:
|
||||
case IVY_SYM_DOUBLE_LEFT_ANGLE:
|
||||
case IVY_SYM_DOUBLE_RIGHT_ANGLE:
|
||||
case IVY_SYM_DOUBLE_LEFT_ANGLE_EQUAL:
|
||||
case IVY_SYM_DOUBLE_RIGHT_ANGLE_EQUAL:
|
||||
case IVY_SYM_HYPHEN_RIGHT_ANGLE:
|
||||
return TOK_EXPR_ANY;
|
||||
default:
|
||||
return TOK_EXPR_NONE;
|
||||
op = ivy_operator_get(tok->t_symbol);
|
||||
return op ? TOK_EXPR_ANY : TOK_EXPR_NONE;
|
||||
}
|
||||
case IVY_TOK_KEYWORD:
|
||||
switch (tok->t_keyword) {
|
||||
@@ -85,14 +67,11 @@ enum token_expr_type get_token_expr_type(struct ivy_token *tok)
|
||||
case IVY_KW_WHILE:
|
||||
case IVY_KW_TRY:
|
||||
case IVY_KW_CATCH:
|
||||
case IVY_KW_NOT:
|
||||
case IVY_KW_THROW:
|
||||
return TOK_EXPR_BEGIN;
|
||||
case IVY_KW_IS:
|
||||
case IVY_KW_AND:
|
||||
case IVY_KW_OR:
|
||||
return TOK_EXPR_ANY;
|
||||
default:
|
||||
op = ivy_operator_get(tok->t_keyword);
|
||||
return op ? TOK_EXPR_ANY : TOK_EXPR_NONE;
|
||||
return TOK_EXPR_NONE;
|
||||
}
|
||||
default:
|
||||
@@ -229,6 +208,8 @@ const char *ivy_ast_node_type_to_string(enum ivy_ast_node_type v)
|
||||
ENUM_STR(IVY_AST_CLASS);
|
||||
ENUM_STR(IVY_AST_MSGH);
|
||||
ENUM_STR(IVY_AST_PROPERTY);
|
||||
ENUM_STR(IVY_AST_SELECTOR);
|
||||
ENUM_STR(IVY_AST_EXPR);
|
||||
ENUM_STR(IVY_AST_LAMBDA);
|
||||
ENUM_STR(IVY_AST_UNIT_PACKAGE);
|
||||
ENUM_STR(IVY_AST_UNIT_IMPORT);
|
||||
@@ -249,14 +230,3 @@ const char *ivy_ast_node_type_to_string(enum ivy_ast_node_type v)
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
const char *ivy_ast_msgh_recipient_type_to_string(enum ivy_ast_msgh_recipient_type v)
|
||||
{
|
||||
switch (v) {
|
||||
ENUM_STR(IVY_AST_MSGH_NONE);
|
||||
ENUM_STR(IVY_AST_MSGH_OBJECT);
|
||||
ENUM_STR(IVY_AST_MSGH_CLASS);
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user