Commit Diff
Diff:
c39be742cf8348232f6a527b19c42f764e80aae0
67f494057aa3a0a32cc4d948cff2f27ef9de2340
Commit:
67f494057aa3a0a32cc4d948cff2f27ef9de2340
Tree:
649129374062c2209f38593ac2db94f94660ac69
Author:
Omar Polo <op@omarpolo.com>
Date:
Fri Jul 9 12:49:15 2021 UTC
Message:
@-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
commit - c39be742cf8348232f6a527b19c42f764e80aae0
commit + 67f494057aa3a0a32cc4d948cff2f27ef9de2340
blob - 8f450de756554371b618add63490d625cf99dc3a
blob + a43eeac2b8642da0a404a35fd0ca88e6fe1f8f78
--- parse.y
+++ parse.y
@@ -354,6 +354,7 @@ optnl : '\n' optnl /* zero or more newlines */
;
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)) {
Omar Polo