Change parser to use ^Expr rather than string for the foreign import paths

This commit is contained in:
gingerBill
2024-05-28 00:27:13 +01:00
parent a1b8749e74
commit d91054b615
3 changed files with 8 additions and 6 deletions
+1 -1
View File
@@ -538,7 +538,7 @@ Foreign_Import_Decl :: struct {
import_tok: tokenizer.Token, import_tok: tokenizer.Token,
name: ^Ident, name: ^Ident,
collection_name: string, collection_name: string,
fullpaths: []string, fullpaths: []^Expr,
comment: ^Comment_Group, comment: ^Comment_Group,
} }
+6 -4
View File
@@ -1190,12 +1190,12 @@ parse_foreign_decl :: proc(p: ^Parser) -> ^ast.Decl {
error(p, name.pos, "illegal foreign import name: '_'") error(p, name.pos, "illegal foreign import name: '_'")
} }
fullpaths: [dynamic]string fullpaths: [dynamic]^ast.Expr
if allow_token(p, .Open_Brace) { if allow_token(p, .Open_Brace) {
for p.curr_tok.kind != .Close_Brace && for p.curr_tok.kind != .Close_Brace &&
p.curr_tok.kind != .EOF { p.curr_tok.kind != .EOF {
path := expect_token(p, .String) path := parse_expr(p, false)
append(&fullpaths, path.text) append(&fullpaths, path)
allow_token(p, .Comma) or_break allow_token(p, .Comma) or_break
} }
@@ -1203,7 +1203,9 @@ parse_foreign_decl :: proc(p: ^Parser) -> ^ast.Decl {
} else { } else {
path := expect_token(p, .String) path := expect_token(p, .String)
reserve(&fullpaths, 1) reserve(&fullpaths, 1)
append(&fullpaths, path.text) bl := ast.new(ast.Basic_Lit, path.pos, end_pos(path))
bl.tok = tok
append(&fullpaths, bl)
} }
if len(fullpaths) == 0 { if len(fullpaths) == 0 {
+1 -1
View File
@@ -4894,7 +4894,7 @@ gb_internal Ast *parse_foreign_decl(AstFile *f) {
while (f->curr_token.kind != Token_CloseBrace && while (f->curr_token.kind != Token_CloseBrace &&
f->curr_token.kind != Token_EOF) { f->curr_token.kind != Token_EOF) {
Ast *path = parse_expr(f, true); Ast *path = parse_expr(f, false);
array_add(&filepaths, path); array_add(&filepaths, path);
if (!allow_field_separator(f)) { if (!allow_field_separator(f)) {