diff options
author | Raghuram Subramani <raghus2247@gmail.com> | 2025-08-29 09:27:00 -0400 |
---|---|---|
committer | Raghuram Subramani <raghus2247@gmail.com> | 2025-08-29 09:27:00 -0400 |
commit | afd988c193eb132f76421d32f6d1e9529207713d (patch) | |
tree | 5f9a1437c25cce98637d4428e89f32072278aa0b | |
parent | 9430a0c1a919cd4264fac9650e20c265e1bbb9e1 (diff) |
lexer: if EACHDO is encountered, don't lex anything until ENDEACHDO
-rw-r--r-- | include/lexer.h | 1 | ||||
-rw-r--r-- | src/lexer.c | 32 | ||||
-rw-r--r-- | src/template.c | 1 |
3 files changed, 25 insertions, 9 deletions
diff --git a/include/lexer.h b/include/lexer.h index 543cd93..429648a 100644 --- a/include/lexer.h +++ b/include/lexer.h @@ -24,6 +24,7 @@ #define DIRECTIVE_IS(key) strncmp(buffer + n, key, strlen(key)) == 0 typedef enum { + _NONE, _RAW, INCLUDE, CONTENT, diff --git a/src/lexer.c b/src/lexer.c index a81d950..5f0b99c 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -32,6 +32,7 @@ lex(char *buffer) { list_t *directives = list_create(sizeof(directive_t)); size_t current_offset = 0; + directive_e skip_until_directive = _NONE; while (true) { key_match_t *match = find_next_key(buffer, 0); @@ -45,21 +46,36 @@ lex(char *buffer) current_offset += match->length + match->offset; - if (current_offset != 0) { - char *raw_content = strndup(buffer, match->offset); + if (directive->type == skip_until_directive + || skip_until_directive == _NONE) { - directive_t *raw_directive = malloc(sizeof(directive_t)); + /* don't add _RAW for the part before the skip_until directive */ + if (skip_until_directive == _NONE) { + if (current_offset != 0) { + char *raw_content = strndup(buffer, match->offset); - raw_directive->type = _RAW; - raw_directive->operands = raw_content; - list_add(directives, raw_directive); + directive_t *raw_directive = malloc(sizeof(directive_t)); - free(raw_directive); + raw_directive->type = _RAW; + raw_directive->operands = raw_content; + list_add(directives, raw_directive); + + free(raw_directive); + } + } + + list_add(directives, directive); + + skip_until_directive = _NONE; } buffer += match->offset + match->length; - list_add(directives, directive); + if (directive->type == EACHDO) + skip_until_directive = ENDEACHDO; + + if (directive->type == CONTENTFOR) + skip_until_directive = ENDCONTENT; free(directive); free(match); diff --git a/src/template.c b/src/template.c index f892eb7..d325621 100644 --- a/src/template.c +++ b/src/template.c @@ -173,7 +173,6 @@ template_write(engine_t *engine, FILE *f, void *doc, bool is_markdown) case BODY: { if (is_markdown) { - mkd_flag_t *flags = mkd_flags(); mkd_set_flag_num(flags, MKD_FENCEDCODE); markdown(doc, f, flags); |