From 23898b76180b3bbcc7e482492f2af0c59e3efe12 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 11 Feb 2024 15:22:32 -0500 Subject: Handle empty cords correctly --- compile.c | 6 ++++-- parse.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/compile.c b/compile.c index a4dbc8eb..90741253 100644 --- a/compile.c +++ b/compile.c @@ -100,6 +100,8 @@ CORD compile(ast_t *ast) } case StringLiteral: { const char *str = Match(ast, StringLiteral)->str; + if (!str || strlen(str) == 0) + return "(CORD)CORD_EMPTY"; CORD code = "\""; for (; *str; ++str) { switch (*str) { @@ -125,7 +127,7 @@ CORD compile(ast_t *ast) case StringJoin: { ast_list_t *chunks = Match(ast, StringJoin)->children; if (!chunks) { - return "\"\""; + return "(CORD)CORD_EMPTY"; } else if (!chunks->next) { CORD code = compile(chunks->ast); if (chunks->ast->tag != StringLiteral) @@ -164,7 +166,7 @@ CORD compile(ast_t *ast) } case Assign: { auto assign = Match(ast, Assign); - CORD code = NULL; + CORD code = CORD_EMPTY; for (ast_list_t *target = assign->targets, *value = assign->values; target && value; target = target->next, value = value->next) { CORD_sprintf(&code, "%r = %r", compile(target->ast), compile(value->ast)); if (target->next) code = CORD_cat(code, ", "); diff --git a/parse.c b/parse.c index d7d8ff74..c24cd071 100644 --- a/parse.c +++ b/parse.c @@ -910,7 +910,7 @@ PARSER(parse_string) { } ast_list_t *chunks = NULL; - CORD chunk = NULL; + CORD chunk = CORD_EMPTY; const char *chunk_start = pos; for (; pos < ctx->file->text + ctx->file->len && *pos != close_quote; ++pos) { if (*pos == start_interp) { -- cgit v1.2.3