stage1 基于新的ast实现部分sema
This commit is contained in:
1 parent
98b35a98e3
commit
8aa7a89c7e
5 files changed
+1316
-1061
No files matched your search
+9
-6
@@ -1310,7 +1310,8 @@ static spl_ast_node_ref_t parse_postfix(parser_t *p) {
|
||||
}
|
||||
} else if (t->type == TOK_L_BRACKET) {
|
||||
advance(p);
|
||||
spl_ast_node_ref_t begin = parse_expr(p);
|
||||
int range_prec = binary_op_info[SPL_OP_RANGE].prec;
|
||||
spl_ast_node_ref_t begin = parse_expr_prec(p, range_prec + 1);
|
||||
if (peek(p) && peek(p)->type == TOK_RANGE) {
|
||||
advance(p);
|
||||
spl_ast_node_ref_t end = 0;
|
||||
@@ -1432,15 +1433,17 @@ static spl_ast_node_ref_t parse_primary(parser_t *p) {
|
||||
} else if (nx->type == TOK_L_BRACKET) {
|
||||
// 匿名数组字面量:. [ elems ]
|
||||
advance(p); // 消费 '['
|
||||
spl_ast_node_ref_t ref = new_node(p, SPL_AST_EXPR_ANON_ARRAY_LIT, t);
|
||||
spl_ast_node_t *arr = node_at(p->ast, ref);
|
||||
arr->anon_array_literal.elems = parse_expr_list(p);
|
||||
// 先解析元素列表,避免节点扩容导致 arr 指针失效
|
||||
spl_ast_node_ref_vec_t elems = parse_expr_list(p);
|
||||
const spl_tok_t *close = peek(p);
|
||||
if (!close || close->type != TOK_R_BRACKET) {
|
||||
SPL_FATAL(close, "expected ']'");
|
||||
return ref;
|
||||
return 0;
|
||||
}
|
||||
advance(p);
|
||||
advance(p); // 消费 ']'
|
||||
spl_ast_node_ref_t ref = new_node(p, SPL_AST_EXPR_ANON_ARRAY_LIT, t);
|
||||
spl_ast_node_t *arr = node_at(p->ast, ref);
|
||||
arr->anon_array_literal.elems = elems;
|
||||
return ref;
|
||||
} else {
|
||||
SPL_FATAL(nx, "expected '{' or '[' after '.'");
|
||||
|
||||
Reference in new issue
Block a user