stage1 使用切片表达字符串而非C字符串 提供属性系统
This commit is contained in:
1 parent
a64a96f9a4
commit
72ae6d6994
14 files changed
+685
-1256
No files matched your search
+12
-4
@@ -92,6 +92,7 @@ static spl_ast_node_ref_t new_node(parser_t *p, spl_ast_node_kind_t kind, const
|
||||
n.kind = kind;
|
||||
n.resolved_def_id = 0;
|
||||
n.resolved_lang_tid = 0;
|
||||
vec_init(n.attrs);
|
||||
if (tok) {
|
||||
n.dbg.dbg_name = spl_ast_kind_name(kind);
|
||||
n.dbg.fname = tok->fname;
|
||||
@@ -199,13 +200,15 @@ static char parse_char_literal(const spl_tok_t *t) {
|
||||
return c;
|
||||
}
|
||||
|
||||
static char *parse_string_literal(parser_t *p, const spl_tok_t *t) {
|
||||
static char *parse_string_literal(parser_t *p, const spl_tok_t *t, usize *out_len) {
|
||||
const char *src = t->lexeme + 1;
|
||||
const char *end = t->lexeme + t->len - 1;
|
||||
usize cap = t->len + 1;
|
||||
char *tmp = malloc(cap);
|
||||
if (!tmp)
|
||||
if (!tmp) {
|
||||
*out_len = 0;
|
||||
return NULL;
|
||||
}
|
||||
char *dst = tmp;
|
||||
while (src < end) {
|
||||
char c;
|
||||
@@ -216,7 +219,7 @@ static char *parse_string_literal(parser_t *p, const spl_tok_t *t) {
|
||||
src++;
|
||||
}
|
||||
}
|
||||
*dst = '\0';
|
||||
*out_len = (usize)(dst - tmp);
|
||||
char *interned = intern_string(p->ast, tmp, dst - tmp);
|
||||
free(tmp);
|
||||
return interned;
|
||||
@@ -1402,7 +1405,11 @@ static spl_ast_node_ref_t parse_primary(parser_t *p) {
|
||||
case TOK_STRING_LITERAL: {
|
||||
advance(p);
|
||||
spl_ast_node_ref_t ref = new_node(p, SPL_AST_EXPR_STRING_LIT, t);
|
||||
node_at(p->ast, ref)->string_lit.data = parse_string_literal(p, t);
|
||||
usize len = 0;
|
||||
const char *data = parse_string_literal(p, t, &len);
|
||||
spl_ast_node_t *node = node_at(p->ast, ref);
|
||||
node->string_lit.data = data;
|
||||
node->string_lit.len = len;
|
||||
return ref;
|
||||
}
|
||||
case KW_TRUE:
|
||||
@@ -2234,6 +2241,7 @@ void spl_ast_drop(spl_ast_t *ast) {
|
||||
return;
|
||||
vec_for(ast->str_buckets, idx) { free(vec_at(ast->str_buckets, idx)); }
|
||||
vec_free(ast->str_buckets);
|
||||
vec_for(ast->node_buckets, idx) { vec_free(vec_at(ast->node_buckets, idx).attrs); }
|
||||
vec_free(ast->node_buckets);
|
||||
vec_free(ast->input);
|
||||
ast->parsed = 0;
|
||||
|
||||
Reference in new issue
Block a user