From 55479cbf9e4a8f36afe41d84df687f05fc7661f0 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 25 Aug 2025 12:12:02 -0400 Subject: Initial work to pass metadata for code --- src/parse/functions.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/parse/functions.c') diff --git a/src/parse/functions.c b/src/parse/functions.c index 0779bb7b..e820182b 100644 --- a/src/parse/functions.c +++ b/src/parse/functions.c @@ -13,8 +13,8 @@ #include "context.h" #include "controlflow.h" #include "errors.h" -#include "functions.h" #include "expressions.h" +#include "functions.h" #include "types.h" #include "utils.h" @@ -32,15 +32,15 @@ arg_ast_t *parse_args(parse_ctx_t *ctx, const char **pos) { name_list_t *names = NULL; for (;;) { - whitespace(pos); + whitespace(ctx, pos); const char *name = get_id(pos); if (!name) break; - whitespace(pos); + whitespace(ctx, pos); if (match(pos, ":")) { type = expect(ctx, *pos - 1, pos, parse_type, "I expected a type here"); names = new (name_list_t, .name = name, .next = names); - whitespace(pos); + whitespace(ctx, pos); if (match(pos, "=")) default_val = expect(ctx, *pos - 1, pos, parse_term, "I expected a value after this '='"); break; @@ -66,7 +66,7 @@ arg_ast_t *parse_args(parse_ctx_t *ctx, const char **pos) { for (; names; names = names->next) args = new (arg_ast_t, .name = names->name, .type = type, .value = default_val, .next = args); - if (!match_separator(pos)) break; + if (!match_separator(ctx, pos)) break; } REVERSE_LIST(args); @@ -87,19 +87,19 @@ ast_t *parse_func_def(parse_ctx_t *ctx, const char *pos) { arg_ast_t *args = parse_args(ctx, &pos); spaces(&pos); type_ast_t *ret_type = match(&pos, "->") ? optional(ctx, &pos, parse_type) : NULL; - whitespace(&pos); + whitespace(ctx, &pos); bool is_inline = false; ast_t *cache_ast = NULL; - for (bool specials = match(&pos, ";"); specials; specials = match_separator(&pos)) { + for (bool specials = match(&pos, ";"); specials; specials = match_separator(ctx, &pos)) { const char *flag_start = pos; if (match_word(&pos, "inline")) { is_inline = true; } else if (match_word(&pos, "cached")) { if (!cache_ast) cache_ast = NewAST(ctx->file, pos, pos, Int, .str = "-1"); } else if (match_word(&pos, "cache_size")) { - whitespace(&pos); + whitespace(ctx, &pos); if (!match(&pos, "=")) parser_err(ctx, flag_start, pos, "I expected a value for 'cache_size'"); - whitespace(&pos); + whitespace(ctx, &pos); cache_ast = expect(ctx, start, &pos, parse_expr, "I expected a maximum size for the cache"); } } @@ -121,19 +121,19 @@ ast_t *parse_convert_def(parse_ctx_t *ctx, const char *pos) { arg_ast_t *args = parse_args(ctx, &pos); spaces(&pos); type_ast_t *ret_type = match(&pos, "->") ? optional(ctx, &pos, parse_type) : NULL; - whitespace(&pos); + whitespace(ctx, &pos); bool is_inline = false; ast_t *cache_ast = NULL; - for (bool specials = match(&pos, ";"); specials; specials = match_separator(&pos)) { + for (bool specials = match(&pos, ";"); specials; specials = match_separator(ctx, &pos)) { const char *flag_start = pos; if (match_word(&pos, "inline")) { is_inline = true; } else if (match_word(&pos, "cached")) { if (!cache_ast) cache_ast = NewAST(ctx->file, pos, pos, Int, .str = "-1"); } else if (match_word(&pos, "cache_size")) { - whitespace(&pos); + whitespace(ctx, &pos); if (!match(&pos, "=")) parser_err(ctx, flag_start, pos, "I expected a value for 'cache_size'"); - whitespace(&pos); + whitespace(ctx, &pos); cache_ast = expect(ctx, start, &pos, parse_expr, "I expected a maximum size for the cache"); } } -- cgit v1.2.3 From 1f78aa8783eba223427509834d64f8f5214f1a98 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 25 Aug 2025 14:00:30 -0400 Subject: Improved formatting --- src/parse/functions.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/parse/functions.c') diff --git a/src/parse/functions.c b/src/parse/functions.c index e820182b..b50519b7 100644 --- a/src/parse/functions.c +++ b/src/parse/functions.c @@ -26,6 +26,7 @@ arg_ast_t *parse_args(parse_ctx_t *ctx, const char **pos) { type_ast_t *type = NULL; typedef struct name_list_s { + const char *start, *end; const char *name; struct name_list_s *next; } name_list_t; @@ -35,21 +36,22 @@ arg_ast_t *parse_args(parse_ctx_t *ctx, const char **pos) { whitespace(ctx, pos); const char *name = get_id(pos); if (!name) break; + const char *name_start = *pos; whitespace(ctx, pos); if (match(pos, ":")) { type = expect(ctx, *pos - 1, pos, parse_type, "I expected a type here"); - names = new (name_list_t, .name = name, .next = names); whitespace(ctx, pos); if (match(pos, "=")) default_val = expect(ctx, *pos - 1, pos, parse_term, "I expected a value after this '='"); + names = new (name_list_t, .start = name_start, .end = *pos, .name = name, .next = names); break; } else if (strncmp(*pos, "==", 2) != 0 && match(pos, "=")) { default_val = expect(ctx, *pos - 1, pos, parse_term, "I expected a value after this '='"); - names = new (name_list_t, .name = name, .next = names); + names = new (name_list_t, .start = name_start, .end = *pos, .name = name, .next = names); break; } else if (name) { - names = new (name_list_t, .name = name, .next = names); + names = new (name_list_t, .start = name_start, .end = *pos, .name = name, .next = names); spaces(pos); if (!match(pos, ",")) break; } else { @@ -64,7 +66,8 @@ arg_ast_t *parse_args(parse_ctx_t *ctx, const char **pos) { REVERSE_LIST(names); for (; names; names = names->next) - args = new (arg_ast_t, .name = names->name, .type = type, .value = default_val, .next = args); + args = new (arg_ast_t, .start = names->start, .end = names->end, .name = names->name, .type = type, + .value = default_val, .next = args); if (!match_separator(ctx, pos)) break; } -- cgit v1.2.3 From 500ea505a88233b81a0e22a99efe62a868f5d449 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 31 Aug 2025 15:36:02 -0400 Subject: Merge fixes --- src/parse/functions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/parse/functions.c') diff --git a/src/parse/functions.c b/src/parse/functions.c index 6cb085b7..826fdbef 100644 --- a/src/parse/functions.c +++ b/src/parse/functions.c @@ -41,7 +41,7 @@ arg_ast_t *parse_args(parse_ctx_t *ctx, const char **pos) { const char *alias = NULL; if (match(pos, "|")) { - whitespace(pos); + whitespace(ctx, pos); alias = get_id(pos); if (!alias) parser_err(ctx, *pos, *pos, "I expected an argument alias after `|`"); } -- cgit v1.2.3 From db6107c33df6a4fdb592ad29074d1159c37dc048 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 31 Aug 2025 16:22:29 -0400 Subject: Bugfix for argument aliases (merge issue) --- src/parse/functions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/parse/functions.c') diff --git a/src/parse/functions.c b/src/parse/functions.c index 826fdbef..ceb0a8bc 100644 --- a/src/parse/functions.c +++ b/src/parse/functions.c @@ -76,7 +76,7 @@ arg_ast_t *parse_args(parse_ctx_t *ctx, const char **pos) { REVERSE_LIST(names); for (; names; names = names->next) - args = new (arg_ast_t, .start = names->start, .end = names->end, .name = names->name, .alias = names->name, + args = new (arg_ast_t, .start = names->start, .end = names->end, .name = names->name, .alias = names->alias, .type = type, .value = default_val, .next = args); if (!match_separator(ctx, pos)) break; -- cgit v1.2.3