aboutsummaryrefslogtreecommitdiff
path: root/src/lexer.c
diff options
context:
space:
mode:
authorRaghuram Subramani <raghus2247@gmail.com>2025-06-22 11:37:28 +0530
committerRaghuram Subramani <raghus2247@gmail.com>2025-06-22 11:37:28 +0530
commit751068c825d4eef93aab6f8c708fe0f64cf27323 (patch)
treed5aaf252aee2da09119e5802e38ef7e87d42a283 /src/lexer.c
parentea43c3a535f964067f5a20dec867bc366c155ae7 (diff)
(lexer,engine): add support for parsing contentfor
Diffstat (limited to 'src/lexer.c')
-rw-r--r--src/lexer.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/lexer.c b/src/lexer.c
index 44462bb..8a04df1 100644
--- a/src/lexer.c
+++ b/src/lexer.c
@@ -2,6 +2,7 @@
#include <ctype.h>
#include <lexer.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -76,6 +77,9 @@ found_start:
}
directive->operands = operand;
+ } else if (strncmp(buffer + n, "endcontent", strlen("endcontent")) == 0) {
+ directive->type = ENDCONTENT;
+ directive->operands = NULL;
} else if (strncmp(buffer + n, "contentfor", strlen("contentfor")) == 0) {
directive->type = CONTENTFOR;
contentfor_operands_t *operands = malloc(sizeof(contentfor_operands_t));
@@ -87,6 +91,44 @@ found_start:
break;
}
+ buffer = content + match->length + match->offset;
+
+ size_t content_length = 0;
+
+ key_match_t *new_match;
+ directive_t *new_directive;
+
+ while (true) {
+ new_match = find_next_key(buffer);
+ if (new_match == NULL) {
+ printf("Cannot find endcontent\n");
+ free(new_directive);
+ free(new_match);
+ free(directive);
+ return NULL;
+ }
+
+ new_directive = find_directive(buffer, new_match);
+ if (new_directive == NULL) {
+ printf("Cannot find directive: %.*s\n",
+ new_match->length,
+ buffer + new_match->offset);
+ free(new_directive);
+ free(new_match);
+ free(directive);
+ return NULL;
+ }
+
+ if (new_directive->type == ENDCONTENT) {
+ break;
+ }
+ }
+
+ asprintf(&operands->content, "%.*s", new_match->offset, buffer);
+
+ free(new_directive);
+ free(new_match);
+
directive->operands = operands;
} else {
free(directive);