commit - c8e1e0443e5715c08703da02a0673f29c1d74bf2
commit + 9c75d045d714e428f2a33b50fb59d589139e3529
blob - b2f21c0a91042ef4a2e55b52475a4ba54ebbacb7
blob + 38f801e710c7cd79e1ad80f0252443b807fa3a0f
--- template/parse.y
+++ template/parse.y
%}
-%token DEFINE ELSE END ERROR FINALLY IF INCLUDE PRINTF
+%token DEFINE ELSE END ERROR FINALLY FOR IF INCLUDE PRINTF
%token RENDER TQFOREACH UNSAFE URLESCAPE
%token <v.string> STRING
%type <v.string> string
}
;
-loop : '{' TQFOREACH STRING STRING STRING '}' {
+loop : '{' FOR stringy '}' {
+ printf("for (%s) {\n", $3);
+ free($3);
+ } body end {
+ puts("}");
+ }
+ | '{' TQFOREACH STRING STRING STRING '}' {
printf("TAILQ_FOREACH(%s, %s, %s) {\n",
$3, $4, $5);
free($3);
{ "else", ELSE },
{ "end", END },
{ "finally", FINALLY },
+ { "for", FOR },
{ "if", IF },
{ "include", INCLUDE },
{ "printf", PRINTF },
blob - 0a1daeb5d04c95c9bfaa13fa6bd319e71f0c231e
blob + dd96702b6b6d728f77177f953de0319b5fc8c5a8
--- template/regress/05-loop.tmpl
+++ template/regress/05-loop.tmpl
{{ end }}
{{ define list(struct template *tp, struct tailhead *head) }}
- {! struct entry *np; !}
+{!
+ struct entry *np;
+ int i;
+!}
{{ if !TAILQ_EMPTY(head) }}
<p>items:</p>
<ul>
{{ else }}
<p>no items</p>
{{ end }}
+
+ <p>
+ {{ for i = 0; i < 3; ++i }}
+ hello{{ " " }}
+ {{ end }}
+ world!
+ </p>
{{ end }}
blob - 1c17d8e4f2fb97529887c0f02f9ee8e6d8d77c08
blob + d4c20d67eeee5e6e0217d8abd4c19f2d440ba6d9
--- template/regress/05.expected
+++ template/regress/05.expected
-<!doctype html><html><body><p>items:</p><ul><li>1</li><li>2</li></ul></body></html>
-<!doctype html><html><body><p>no items</p></body></html>
+<!doctype html><html><body><p>items:</p><ul><li>1</li><li>2</li></ul><p>hello hello hello world!</p></body></html>
+<!doctype html><html><body><p>no items</p><p>hello hello hello world!</p></body></html>