diff options
author | Omar Polo <op@omarpolo.com> | 2021-07-09 12:49:15 +0000 |
---|---|---|
committer | Omar Polo <op@omarpolo.com> | 2021-07-09 12:49:15 +0000 |
commit | 67f494057aa3a0a32cc4d948cff2f27ef9de2340 (patch) | |
tree | 649129374062c2209f38593ac2db94f94660ac69 /parse.y | |
parent | c39be742cf8348232f6a527b19c42f764e80aae0 (diff) |
@-macros, rollback changes to strings and optional semicolons
* expand $-macros as string, only the new @-macros get expanded as-is
* rollback changes to characters allowed in bare strings
* optional semicolons in optnl, useful for readable @-macros
Diffstat (limited to 'parse.y')
-rw-r--r-- | parse.y | 29 |
1 files changed, 27 insertions, 2 deletions
@@ -354,6 +354,7 @@ fastcgi : TSPAWN string { ; optnl : '\n' optnl /* zero or more newlines */ + | ';' optnl /* semicolons too */ | /*empty*/ ; @@ -562,6 +563,30 @@ top: while (1) { if ((c = lgetc(0)) == EOF) return 0; + if (p + 1 >= buf + sizeof(buf) -1) { + yyerror("string too long"); + return findeol(); + } + if (isalnum(c) || c == '_') { + *p++ = c; + continue; + } + *p = '\0'; + lungetc(c); + break; + } + val = symget(buf); + if (val == NULL) { + yyerror("macro `%s' not defined", buf); + return findeol(); + } + yylval.v.string = xstrdup(val); + return STRING; + } + if (c == '@' && !expanding) { + while (1) { + if ((c = lgetc(0)) == EOF) + return 0; if (p + 1 >= buf + sizeof(buf) - 1) { yyerror("string too long"); @@ -670,9 +695,9 @@ nodigits: (isalnum(x) || (ispunct(x) && x != '(' && x != ')' && \ x != '{' && x != '}' && \ x != '!' && x != '=' && x != '#' && \ - x != ',')) + x != ',' && x != ';')) - if (isalnum(c) || c == ':' || c == '_' || c == '/' || c == '.') { + if (isalnum(c) || c == ':' || c == '_') { do { *p++ = c; if ((size_t)(p-buf) >= sizeof(buf)) { |