added extends functionality to demo

This commit is contained in:
overflowerror 2021-06-08 19:30:25 +02:00
parent 75800c531d
commit 296f0edecd
4 changed files with 25 additions and 12 deletions

View file

@ -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
@ -51,6 +51,10 @@ 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/*
rm -f obj/*

View file

@ -1,16 +1,7 @@
{$ char* title, char** names, size_t no $}
{# extends("layout.html.templ", title) #}
%%
<!DOCTYPE html>
<html>
<head>
<title>
{{ "%s", title }}
</title>
</head>
<body>
{% for(size_t i = 0; i < no; i++) %}
{# render("greeting.templ", names[i]) #}<br />
{% end %}
</body>
</html>

View file

@ -0,0 +1,14 @@
{$ char* title $}
%%
<!DOCTYPE html>
<html>
<head>
<title>
{{ "%s", title }}
</title>
</head>
<body>
{# child() #}
</body>
</html>

View file

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