From 59d69f71ab5f50613d6863db53f78bd94c27f7aa Mon Sep 17 00:00:00 2001 From: overflowerror Date: Fri, 4 Jun 2021 20:31:06 +0200 Subject: [PATCH] structure blocks are now read correctly --- src/parser.y | 16 ++++++++++++++++ src/tree.c | 23 +++++++++++++++++++++++ src/tree.h | 4 ++++ 3 files changed, 43 insertions(+) diff --git a/src/parser.y b/src/parser.y index 36be3bc..ca5b1b1 100644 --- a/src/parser.y +++ b/src/parser.y @@ -81,6 +81,11 @@ metaSection: /* empty */ $$ = $4; addStat(&$$.stats, $2); } + | STRUCTURE_BEGIN + { + yyerror("structure block in meta section not yet supported"); + YYERROR; + } ; parameters: /* empty */ @@ -135,8 +140,19 @@ mainSection: /* empty */ $$ = $1; addNode(&$$, newOutputNode($3)); } + | mainSection STRUCTURE_BEGIN texts structureType text STRUCTURE_END + { + if (!checkCharset($3, " \t\n")) { + yyerror("unknown structure block command"); + YYERROR; + } + + $$ = $1; + } ; +structureType: RENDER + statementHeader: STATEMENT_BEGIN blockStatement STATEMENT_END { $$ = $2; diff --git a/src/tree.c b/src/tree.c index bb55e23..5a5fdfe 100644 --- a/src/tree.c +++ b/src/tree.c @@ -1,5 +1,6 @@ #include #include +#include #include "common.h" #include "tree.h" @@ -161,3 +162,25 @@ struct template newTemplate() { .tree = newTree() }; } + +bool checkCharset(const char* string, const char* charset) { + size_t charsetLength = strlen(charset); + + while (*string != '\0') { + bool ok = false; + for (size_t i = 0; i < charsetLength; i++) { + if (*string == charset[i]) { + ok = true; + break; + } + } + + if (!ok) { + return false; + } + + string++; + } + + return true; +} diff --git a/src/tree.h b/src/tree.h index 2317a41..eab8323 100644 --- a/src/tree.h +++ b/src/tree.h @@ -1,6 +1,8 @@ #ifndef TREE_H_ #define TREE_H_ +#include + char* combineStr(char*, char*); #define TEXT_NODE (0) @@ -56,4 +58,6 @@ struct template { struct template newTemplate(); +bool checkCharset(const char*, const char*); + #endif