aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaghuram Subramani <raghus2247@gmail.com>2025-07-27 18:23:42 +0530
committerRaghuram Subramani <raghus2247@gmail.com>2025-07-27 18:24:07 +0530
commit119012f284233587f6622669da2b76da7fd073e2 (patch)
tree4c48899c8890e97bf061d23ef87884b316b359ae
parent2870df21c361d00650c026f9c98ab70107d496f5 (diff)
lexer: for->eachdo
-rw-r--r--compromyse.xyz/index.html4
-rw-r--r--compromyse.xyz/posts/a.html4
-rw-r--r--compromyse.xyz/posts/b.md3
-rw-r--r--include/lexer.h15
-rw-r--r--src/engine.c15
-rw-r--r--src/lexer.c27
6 files changed, 36 insertions, 32 deletions
diff --git a/compromyse.xyz/index.html b/compromyse.xyz/index.html
index 2a2e994..a2421db 100644
--- a/compromyse.xyz/index.html
+++ b/compromyse.xyz/index.html
@@ -1,8 +1,8 @@
-{{ for post : posts }}
+{{ eachdo posts }}
KSFAISO
ASHIAUHSFI
HERE
-{{ endfor }}
+{{ endeachdo }}
<div class="p-16">
<div class="flex flex-wrap gap-8">
diff --git a/compromyse.xyz/posts/a.html b/compromyse.xyz/posts/a.html
index e69de29..79d75da 100644
--- a/compromyse.xyz/posts/a.html
+++ b/compromyse.xyz/posts/a.html
@@ -0,0 +1,4 @@
+title: A.html
+---
+
+<p>a.html</p>
diff --git a/compromyse.xyz/posts/b.md b/compromyse.xyz/posts/b.md
index 2e45ad2..58e2fea 100644
--- a/compromyse.xyz/posts/b.md
+++ b/compromyse.xyz/posts/b.md
@@ -1,3 +1,6 @@
+title: B.md
+---
+
# Hi there!!!!
```
diff --git a/include/lexer.h b/include/lexer.h
index b9dbf1c..4621f6f 100644
--- a/include/lexer.h
+++ b/include/lexer.h
@@ -12,8 +12,8 @@ typedef enum {
CONTENTFOR,
ENDCONTENT,
BODY,
- FOR,
- ENDFOR
+ EACHDO,
+ ENDEACHDO
} directive_e;
typedef struct {
@@ -35,9 +35,8 @@ typedef struct {
typedef struct {
char *key;
- char *source;
char *content;
-} for_operand_t;
+} eachdo_operands_t;
list_t *lex(char *buffer);
directive_t *find_directive(char *content, key_match_t *match);
@@ -57,9 +56,9 @@ void lexer_handle_content(directive_t *directive,
key_match_t *match,
char *buffer,
size_t n);
-void lexer_handle_for(directive_t *directive,
- key_match_t *match,
- char *buffer,
- size_t n);
+void lexer_handle_eachdo(directive_t *directive,
+ key_match_t *match,
+ char *buffer,
+ size_t n);
#endif
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;