commit 97267ffd9f5f20bf2047f4e4e76f1d155dffaa59 from: Omar Polo date: Mon Apr 03 10:24:27 2023 UTC template: fix processing of "{" at end of line add a regress for this case. commit - 2734319d6bf828cb8fdc44a9030605f7bb4c32d1 commit + 97267ffd9f5f20bf2047f4e4e76f1d155dffaa59 blob - f781b7ac44f61c8065695ac89ec64680ac84268c blob + 1dabd1cc6698d8d3b6dd99bdd5581a4eb7188d36 --- regress/template/Makefile +++ regress/template/Makefile @@ -5,7 +5,8 @@ REGRESS_TARGETS = 00-empty \ 04-flow \ 05-loop \ 06-escape \ - 07-printf + 07-printf \ + 08-dangling REGRESS_CLEANUP = clean-comp NO_OBJ = Yes @@ -52,4 +53,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 +++ regress/template/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 +++ regress/template/08.expected @@ -0,0 +1,2 @@ + *hello*

*hello*

| other stuff +<hello>

<hello>

| other stuff 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) {