diff options
author | Raghuram Subramani <raghus2247@gmail.com> | 2025-08-03 12:14:04 +0530 |
---|---|---|
committer | Raghuram Subramani <raghus2247@gmail.com> | 2025-08-03 12:14:04 +0530 |
commit | 8226b60889654518074983f5fd8fc7389d8f5268 (patch) | |
tree | 6f8a751b224671cb2ebfc9143dde74b6586797b4 | |
parent | fb9b501e886bd2c27f1e6884fd4097d55bb19743 (diff) |
lexer: eachdo must also have a operand to hold the source
-rw-r--r-- | include/lexer.h | 1 | ||||
-rw-r--r-- | src/lexer.c | 17 |
2 files changed, 16 insertions, 2 deletions
diff --git a/include/lexer.h b/include/lexer.h index 611e014..ae64759 100644 --- a/include/lexer.h +++ b/include/lexer.h @@ -54,6 +54,7 @@ typedef struct { } contentfor_operand_t; typedef struct { + char *source; char *key; char *content; size_t length; diff --git a/src/lexer.c b/src/lexer.c index e9b98de..8947687 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -207,8 +207,20 @@ lexer_handle_eachdo(directive_t *directive, directive->type = EACHDO; eachdo_operands_t *operands = malloc(sizeof(eachdo_operands_t)); - operands->key = strndup(buffer + n + strlen("eachdo"), - match->length - n - strlen("eachdo") - 2); + char *subbuffer = strndup(buffer + n + strlen("eachdo"), + match->length - n - strlen("eachdo") - 2); + char *original_subbuffer = subbuffer; + + char *source = trim(strsep(&subbuffer, ".")); + if (subbuffer == NULL) { + printf("Failed to split eachdo operands by .\n"); + return; + } + + operands->key = strdup(subbuffer); + operands->source = strdup(source); + + free(original_subbuffer); buffer += match->length; key_match_t *new_match; @@ -365,6 +377,7 @@ directive_delete(directive_t *directive) eachdo_operands_t *operands = directive->operands; free(operands->content); free(operands->key); + free(operands->source); free(operands); break; } |