commit 8e6adf955be84cf1acdde7c80d2fdac23aa3cfbf from: Omar Polo date: Thu Apr 13 21:34:26 2023 UTC template: fix processing of "{" at end of line add a regress for this case. commit - d023b3ba128914935c6e2bfb34997a0443fdf9fd commit + 8e6adf955be84cf1acdde7c80d2fdac23aa3cfbf blob - 39ebee0fb27bff738d486a8bc66fd9ee09e3c691 blob + e626a5c1982cf4b49415b877bfca979ec3c3ab01 --- template/parse.y +++ template/parse.y @@ -552,14 +552,15 @@ newblock: } else if (c == '{') { starting = 1; continue; - } + } else if (c == '\n') + break; *p++ = c; if ((size_t)(p - buf) >= sizeof(buf)) { yyerror("string too long"); return (findeol()); } - } while ((c = lgetc(0)) != EOF && c != '\n'); + } while ((c = lgetc(0)) != EOF); *p = '\0'; if (c == EOF) { yyerror("unterminated block"); @@ -586,14 +587,15 @@ newblock: } else if (c == '!') { ending = 1; continue; - } + } else if (c == '\n') + break; *p++ = c; if ((size_t)(p - buf) >= sizeof(buf)) { yyerror("line too long"); return (findeol()); } - } while ((c = lgetc(0)) != EOF && c != '\n'); + } while ((c = lgetc(0)) != EOF); *p = '\0'; if (c == EOF) { blob - 5b41a3b36ca0223dab174dafa40e73c572f9a203 blob + 09549b805b5e38a91c62ee9a3998256badd68e83 --- template/regress/Makefile +++ template/regress/Makefile @@ -5,7 +5,8 @@ REGRESS_TARGETS = 00-empty \ 04-flow \ 05-loop \ 06-escape \ - 07-printf + 07-printf \ + 08-dangling REGRESS_SETUP_ONCE = setup-comp REGRESS_CLEANUP = clean-comp @@ -57,4 +58,8 @@ clean-comp: ${CC} 07-printf.o runbase.o tmpl.o -o t && ./t > got diff -u ${.CURDIR}/07.expected got +08-dangling: 08-dangling.o runbase.o tmpl.o + ${CC} 08-dangling.o runbase.o tmpl.o -o t && ./t > got + diff -u ${.CURDIR}/08.expected got + .include blob - /dev/null blob + 1784d5d8836cf164c40a94347bdf3f2826dd04bc (mode 644) --- /dev/null +++ template/regress/08-dangling.tmpl @@ -0,0 +1,33 @@ +{! +#include + +#include "tmpl.h" + +int base(struct template *, const char *); + +!} + +{{ define base(struct template *tp, const char *title) }} +{! char *foo = NULL; !} + + + + {{ title }} + + {! /* TODO: frobnicate this line! */ !} +

{{ title }}

+ {{ " | " }} + {{ "other stuff" }} + + + +{{ finally }} +{! free(foo); !} +{{ end }} blob - /dev/null blob + 306fd0c40a46066d36177ff1c89d5254b95247e2 (mode 644) --- /dev/null +++ template/regress/08.expected @@ -0,0 +1,2 @@ + *hello*

*hello*

| other stuff +<hello>

<hello>

| other stuff