commit 3e8b34ba260ecb0048222375132a6998b2a8d2cc from: Omar Polo date: Sat Jan 07 09:23:36 2023 UTC template: add `while' construct commit - 52afe35820b3ceb4c85d7e72024e976a143cfd78 commit + 3e8b34ba260ecb0048222375132a6998b2a8d2cc blob - 1bebb961c5e733837754ec787917a8b8d6bdc572 blob + d61bd1fae0e2bab34ea4d6fe34e3f2301879546a --- template/parse.y +++ template/parse.y @@ -87,7 +87,7 @@ typedef struct { %} %token DEFINE ELSE END ERROR FINALLY FOR IF INCLUDE PRINTF -%token RENDER TQFOREACH UNSAFE URLESCAPE +%token RENDER TQFOREACH UNSAFE URLESCAPE WHILE %token STRING %type string %type stringy @@ -273,6 +273,12 @@ loop : '{' FOR stringy '}' { } body end { fputs("}\n", fp); } + | '{' WHILE stringy '}' { + fprintf(fp, "while (%s) {\n", $3); + free($3); + } body end { + fputs("}\n", fp); + } ; end : '{' END '}' @@ -353,6 +359,7 @@ lookup(char *s) { "tailq-foreach", TQFOREACH }, { "unsafe", UNSAFE }, { "urlescape", URLESCAPE }, + { "while", WHILE }, }; const struct keywords *p; blob - 31b32697b9affdd4231edc3b70f8abaf0bb8300c blob + 5b286fbc62df91dfd76bf8f751fd3591c532b925 --- template/template.7 +++ template/template.7 @@ -102,6 +102,8 @@ only zero or one time and always for last. Looping construct similar to the C loop. .It Cm {{ Ic tailq-foreach Ar var head fieldname Cm }} Ar .. Cm {{ Ic end Cm }} Looping construct similar to the queue.h macro TAILQ_FOREACH. +.It Cm {{ Ic while Ar ... Cm }} Ar ... Cm {{ Ic end Cm }} +Looping construct similar to the C while loop. .It Cm {{ Ar expression Cm | Ic unsafe Cm }} Output .Ar expression