diff --git a/Makefile b/Makefile index 510bdac..4897eae 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,7 @@ gen/lex.yy.c: src/scanner.l gen/y.tab.h gen $(LEX) $< mv lex.yy.c gen/ -demo: demofiles/demo.c gen/demo.tab.c gen/greeting.tab.c $(A_LIB) +demo: demofiles/demo.c gen/demo.tab.c gen/greeting.tab.c gen/layout.tab.c $(A_LIB) $(CC) $(CFLAGS) -o $@ $^ gen/demo.tab.c: demofiles/demo.html.templ $(BIN) gen @@ -50,6 +50,10 @@ gen/demo.tab.c: demofiles/demo.html.templ $(BIN) gen gen/greeting.tab.c: demofiles/greeting.templ $(BIN) gen # change dir to set template name cd demofiles && ../$(BIN) greeting.templ > ../$@ + +gen/layout.tab.c: demofiles/layout.html.templ $(BIN) gen + # change dir to set template name + cd demofiles && ../$(BIN) layout.html.templ > ../$@ clean: rm -f gen/* diff --git a/demofiles/demo.html.templ b/demofiles/demo.html.templ index 17c9528..1f2df35 100644 --- a/demofiles/demo.html.templ +++ b/demofiles/demo.html.templ @@ -1,16 +1,7 @@ {$ char* title, char** names, size_t no $} +{# extends("layout.html.templ", title) #} %% - - - - - {{ "%s", title }} - - - {% for(size_t i = 0; i < no; i++) %} {# render("greeting.templ", names[i]) #}
{% end %} - - diff --git a/demofiles/layout.html.templ b/demofiles/layout.html.templ new file mode 100644 index 0000000..e1181d8 --- /dev/null +++ b/demofiles/layout.html.templ @@ -0,0 +1,14 @@ +{$ char* title $} + +%% + + + + + {{ "%s", title }} + + + + {# child() #} + + diff --git a/src/parser.y b/src/parser.y index 388942c..c51578e 100644 --- a/src/parser.y +++ b/src/parser.y @@ -161,11 +161,15 @@ mainSection: /* empty */ $$ = $1; addNode(&$$, newOutputNode($3)); } - | mainSection STRUCTURE_BEGIN optionalWhitespaces structureType optionalWhitespaces OPEN_PARENTHESES text CLOSE_PARENTHESES optionalWhitespaces STRUCTURE_END + | mainSection STRUCTURE_BEGIN optionalWhitespaces structureType optionalWhitespaces OPEN_PARENTHESES texts CLOSE_PARENTHESES optionalWhitespaces STRUCTURE_END { $$ = $1; switch($4) { case RENDER_NODE: + if (strlen($7) == 0) { + yyerror("render command needs at least one argument (template name)"); + YYERROR; + } addNode(&$$, newRenderNode($7)); break; case CHILD_NODE: