structure blocks are now read correctly

This commit is contained in:
overflowerror 2021-06-04 20:31:06 +02:00
parent 274cec4d5e
commit 59d69f71ab
3 changed files with 43 additions and 0 deletions

View file

@ -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;

View file

@ -1,5 +1,6 @@
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#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;
}

View file

@ -1,6 +1,8 @@
#ifndef TREE_H_
#define TREE_H_
#include <stdbool.h>
char* combineStr(char*, char*);
#define TEXT_NODE (0)
@ -56,4 +58,6 @@ struct template {
struct template newTemplate();
bool checkCharset(const char*, const char*);
#endif