From 75800c531d5b3426198bb185195a3448bfe1003d Mon Sep 17 00:00:00 2001 From: overflowerror Date: Tue, 8 Jun 2021 19:26:21 +0200 Subject: [PATCH] child handling done --- src/main.c | 18 ++++++++++++++++-- src/parser.y | 4 ++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main.c b/src/main.c index b76a0a5..23f6dc8 100644 --- a/src/main.c +++ b/src/main.c @@ -34,10 +34,12 @@ void generateHeader() { fprintf(output, "#include \n"); fprintf(output, "\n"); fprintf(output, "extern void _registerTemplate(const char*, bool, void (*)(FILE*, va_list), void (*)(FILE*, va_list), size_t (*)(va_list));\n"); - fprintf(output, "extern void renderTemplateStart(const char*, FILE*, ...);\n") - fprintf(output, "extern void renderTemplateEnd(const char*, FILE*, ...);\n") + fprintf(output, "extern void renderTemplateStart(const char*, FILE*, ...);\n"); + fprintf(output, "extern void renderTemplateEnd(const char*, FILE*, ...);\n"); fprintf(output, "\n"); fprintf(output, "#define _renderTemplate(f, t, ...) renderTemplate(t, f, __VA_ARGS__)\n"); + fprintf(output, "#define _renderTemplateStart(f, t, ...) renderTemplateStart(t, f, __VA_ARGS__)\n"); + fprintf(output, "#define _renderTemplateEnd(f, t, ...) renderTemplateEnd(t, f, __VA_ARGS__)\n"); fprintf(output, "\n"); for (size_t i = 0; i < result.stats.no; i++) { fprintf(output, "%s\n", result.stats.texts[i]); @@ -160,6 +162,10 @@ void generateSize() { fprintf(output, "\tsize_t %s = 0;\n", SIZE_ACCUMULATOR_VAR); generateArguments(); + if (result.parent != NULL) { + fprintf(output, "%s += sizeTemplate(%s);\n", SIZE_ACCUMULATOR_VAR, result.parent); + } + parseTreeSize(1, result.tree); fprintf(output, "\treturn %s;\n", SIZE_ACCUMULATOR_VAR); @@ -230,8 +236,16 @@ void generateTree() { fprintf(output, "static void %s_%s_(FILE* out, va_list argptr) {\n", PRINT_PREFIX, name); generateArguments(); + if (result.parent != NULL) { + fprintf(output, "\t_renderTemplateStart(out, %s);\n", result.parent); + } + parseTree(1, result.tree); + if (result.parent != NULL) { + fprintf(output, "\t_renderTemplateEnd(out, %s);\n", result.parent); + } + fprintf(output, "}\n"); } diff --git a/src/parser.y b/src/parser.y index 91e3b87..388942c 100644 --- a/src/parser.y +++ b/src/parser.y @@ -85,9 +85,9 @@ metaSection: /* empty */ $$ = $4; addStat(&$$.stats, $2); } - | STRUCTURE_BEGIN optionalWhitespaces structureType optionalWhitespaces OPEN_PARENTHESES text CLOSE_PARENTHESES optionalWhitespaces metaSection + | STRUCTURE_BEGIN optionalWhitespaces structureType optionalWhitespaces OPEN_PARENTHESES text CLOSE_PARENTHESES optionalWhitespaces STRUCTURE_END metaSection { - $$ = $9; + $$ = $10; switch($3) { case RENDER_NODE: yyerror("render command not allowed in meta section; ignoring");