commit 84efe063d23232222a3620238a5de72df40ced47 from: Omar Polo via: Thomas Adam date: Tue Apr 04 21:15:49 2023 UTC template: fix processing of "{" at end of line add a regress for this case. commit - 664d70035d306f09fe381da2dfaa725623c9e252 commit + 84efe063d23232222a3620238a5de72df40ced47 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 - fb6e4945dd4e2f6b31882eeeb94bf0a07a38120b blob + 1e6a9fd07ea3c0e471801ffd54afd0a5773dc68c --- template/parse.y +++ template/parse.y @@ -554,14 +554,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"); @@ -588,14 +589,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) {