aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaghuram Subramani <raghus2247@gmail.com>2025-07-02 15:25:47 +0530
committerRaghuram Subramani <raghus2247@gmail.com>2025-07-02 15:25:47 +0530
commit914fcfbc213fdc07a0328ffa39ef94e983683e87 (patch)
treeb91f54f1a366f9f4e62e14adeed3a6363c8fa8f7
parentb5829262c78c7801b0babfcb007ed4ee5d332414 (diff)
(lexer): add CONTENT directive
-rw-r--r--include/lexer.h2
-rw-r--r--src/engine.c1
-rw-r--r--src/lexer.c12
3 files changed, 14 insertions, 1 deletions
diff --git a/include/lexer.h b/include/lexer.h
index dc6c744..ca2b351 100644
--- a/include/lexer.h
+++ b/include/lexer.h
@@ -1,7 +1,7 @@
#ifndef __LEXER_H
#define __LEXER_H
-typedef enum { INCLUDE, CONTENTFOR, ENDCONTENT, BODY } directive_e;
+typedef enum { INCLUDE, CONTENT, CONTENTFOR, ENDCONTENT, BODY } directive_e;
typedef struct {
unsigned int offset;
diff --git a/src/engine.c b/src/engine.c
index da61df8..2bdc43d 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -109,6 +109,7 @@ ingest(char **buffer)
/* TODO: Handle this gracefully */
case BODY:
+ case CONTENT:
case ENDCONTENT:
break;
}
diff --git a/src/lexer.c b/src/lexer.c
index 2a80ddb..28dee8a 100644
--- a/src/lexer.c
+++ b/src/lexer.c
@@ -77,6 +77,18 @@ found_start:
}
directive->operands = operand;
+ } else if (strncmp(buffer + n, "content ", strlen("content")) == 0) {
+ directive->type = CONTENT;
+
+ char *operand = NULL;
+ for (size_t i = n + strlen("content"); i < match->length - n; i++)
+ if (isalnum(buffer[i])) {
+ sscanf(buffer + i, "%ms\"", &operand);
+ operand[strlen(operand) - 1] = '\0';
+ break;
+ }
+
+ directive->operands = operand;
} else if (strncmp(buffer + n, "endcontent", strlen("endcontent")) == 0) {
directive->type = ENDCONTENT;
directive->operands = NULL;