diff options
| author | Raghuram Subramani <raghus2247@gmail.com> | 2025-07-27 18:23:42 +0530 |
|---|---|---|
| committer | Raghuram Subramani <raghus2247@gmail.com> | 2025-07-27 18:24:07 +0530 |
| commit | 119012f284233587f6622669da2b76da7fd073e2 (patch) | |
| tree | 4c48899c8890e97bf061d23ef87884b316b359ae /src | |
| parent | 2870df21c361d00650c026f9c98ab70107d496f5 (diff) | |
lexer: for->eachdo
Diffstat (limited to 'src')
| -rw-r--r-- | src/engine.c | 15 | ||||
| -rw-r--r-- | src/lexer.c | 27 |
2 files changed, 20 insertions, 22 deletions
diff --git a/src/engine.c b/src/engine.c index 7477d16..d377bee 100644 --- a/src/engine.c +++ b/src/engine.c @@ -74,16 +74,15 @@ handle_contentfor(char **buffer, void handle_for(char **buffer, key_match_t *match, directive_t *directive) { - for_operand_t *operand = directive->operands; + eachdo_operands_t *operands = directive->operands; #ifdef DEBUG - printf("KEY: %s\n", operand->key); - printf("SOURCE: %s\n", operand->source); - printf("CONTENT: %s\n", operand->content); - exit(1); + printf("KEY: %s\n", operands->key); + printf("CONTENT: %s\n", operands->content); #endif - free(operand); + exit(1); + free(operands); } list_t * @@ -125,11 +124,11 @@ ingest(char **buffer) case CONTENTFOR: handle_contentfor(buffer, match, directive, content_headers); break; - case FOR: + case EACHDO: handle_for(buffer, match, directive); break; - case ENDFOR: + case ENDEACHDO: case BODY: case CONTENT: case ENDCONTENT: diff --git a/src/lexer.c b/src/lexer.c index caddf17..e44ae50 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -171,22 +171,21 @@ lexer_handle_contentfor(directive_t *directive, } void -lexer_handle_for(directive_t *directive, - key_match_t *match, - char *buffer, - size_t n) +lexer_handle_eachdo(directive_t *directive, + key_match_t *match, + char *buffer, + size_t n) { - directive->type = FOR; - for_operand_t *operands = malloc(sizeof(for_operand_t)); + directive->type = EACHDO; + eachdo_operands_t *operands = malloc(sizeof(eachdo_operands_t)); char *tempbuffer = strdup(buffer); /* For free() */ void *orig = tempbuffer; tempbuffer += n; - tempbuffer += strlen("for"); + tempbuffer += strlen("eachdo"); operands->key = strdup(trim(strtok(tempbuffer, ":"))); - operands->source = strdup(trim(strtok(NULL, "}"))); free(orig); @@ -196,7 +195,7 @@ lexer_handle_for(directive_t *directive, while (true) { new_match = find_next_key(buffer, 0); if (new_match == NULL) { - printf("Cannot find endfor\n"); + printf("Cannot find endeachdo\n"); free(new_match); free(directive); /* TODO: Handle early returns */ @@ -214,7 +213,7 @@ lexer_handle_for(directive_t *directive, return; } - if (new_directive->type == ENDFOR) { + if (new_directive->type == ENDEACHDO) { free(new_directive); break; } @@ -279,8 +278,8 @@ found_start: } else if (DIRECTIVE_IS("endcontent")) { directive->type = ENDCONTENT; directive->operands = NULL; - } else if (DIRECTIVE_IS("endfor")) { - directive->type = ENDFOR; + } else if (DIRECTIVE_IS("endeachdo")) { + directive->type = ENDEACHDO; directive->operands = NULL; } else if (DIRECTIVE_IS("body")) { directive->type = BODY; @@ -289,8 +288,8 @@ found_start: lexer_handle_contentfor(directive, match, buffer, content, n); } else if (DIRECTIVE_IS("content")) { lexer_handle_content(directive, match, buffer, n); - } else if (DIRECTIVE_IS("for")) { - lexer_handle_for(directive, match, buffer, n); + } else if (DIRECTIVE_IS("eachdo")) { + lexer_handle_eachdo(directive, match, buffer, n); } else { free(directive); return NULL; |
