lang: ast: fix incorrect return types; add function to determine expression tokens
This commit is contained in:
@@ -17,11 +17,17 @@ static const struct ast_node_type *node_ops[] = {
|
||||
[IVY_AST_UNIT_PACKAGE] = &unit_package_node_ops,
|
||||
[IVY_AST_UNIT_IMPORT] = &unit_import_node_ops,
|
||||
[IVY_AST_CLASS] = &class_node_ops,
|
||||
[IVY_AST_MSGH] = &msgh_node_ops,
|
||||
[IVY_AST_SELECTOR] = &selector_node_ops,
|
||||
[IVY_AST_MSGH] = &msgh_node_ops,
|
||||
[IVY_AST_SELECTOR] = &selector_node_ops,
|
||||
};
|
||||
static const size_t nr_node_ops = sizeof node_ops / sizeof node_ops[0];
|
||||
|
||||
enum tok_expr_type {
|
||||
TOK_EXPR_NONE = 0,
|
||||
TOK_EXPR_BEGIN,
|
||||
TOK_EXPR_ANY,
|
||||
};
|
||||
|
||||
const struct ast_node_type *get_ast_node_type(enum ivy_ast_node_type type)
|
||||
{
|
||||
if (type >= nr_node_ops) {
|
||||
@@ -31,6 +37,73 @@ const struct ast_node_type *get_ast_node_type(enum ivy_ast_node_type type)
|
||||
return node_ops[type];
|
||||
}
|
||||
|
||||
static enum tok_expr_type get_tok_expr_type(struct ivy_token *tok)
|
||||
{
|
||||
switch (tok->t_type) {
|
||||
case IVY_TOK_IDENT:
|
||||
case IVY_TOK_INT:
|
||||
case IVY_TOK_DOUBLE:
|
||||
case IVY_TOK_STRING:
|
||||
case IVY_TOK_STR_START:
|
||||
case IVY_TOK_ATOM:
|
||||
return TOK_EXPR_BEGIN;
|
||||
case IVY_TOK_SYMBOL:
|
||||
switch (tok->t_symbol) {
|
||||
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;
|
||||
}
|
||||
case IVY_TOK_KEYWORD:
|
||||
switch (tok->t_keyword) {
|
||||
case IVY_KW_IF:
|
||||
case IVY_KW_ELSE:
|
||||
case IVY_KW_MATCH:
|
||||
case IVY_KW_FOR:
|
||||
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:
|
||||
return TOK_EXPR_NONE;
|
||||
}
|
||||
default:
|
||||
return TOK_EXPR_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
token_parse_function get_token_parser(
|
||||
struct ivy_ast_node *context, struct ivy_token *tok)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user