about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDaniel Shahaf <d.s@daniel.shahaf.name>2021-04-03 02:49:54 +0000
committerDaniel Shahaf <d.s@daniel.shahaf.name>2021-04-08 02:19:39 +0000
commit4ba9008ec7842770289645dc6a8829555915086b (patch)
tree4ffe5d56aa7cb1d598edeb1ca94237d1cfee5091
parent295fbc0998db7204a9eb68f46c8bedab171ff387 (diff)
downloadzsh-4ba9008ec7842770289645dc6a8829555915086b.tar.gz
zsh-4ba9008ec7842770289645dc6a8829555915086b.tar.xz
zsh-4ba9008ec7842770289645dc6a8829555915086b.zip
48379: Make the parameter expansion subscript flags parse error message, "error in flags", identify the location of the parse error.
-rw-r--r--ChangeLog4
-rw-r--r--Src/subst.c28
-rw-r--r--Test/D04parameter.ztst5
3 files changed, 34 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 429cd0376..461bfeacb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2021-04-08  Daniel Shahaf  <d.s@daniel.shahaf.name>
 
+	* 48379: Src/subst.c, Test/D04parameter.ztst: Make the parameter
+	expansion subscript flags parse error message, "error in flags",
+	identify the location of the parse error.
+
 	* 48321 (tweaked per thread): Completion/Unix/Type/_perl_modules:
 	Don't assume ${words[1]} to be either "perl" or "perldoc"
 
diff --git a/Src/subst.c b/Src/subst.c
index 8f5bd355e..96e0914eb 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -2259,9 +2259,31 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
 		    break;
 
 		default:
-		  flagerr:
-		    zerr("error in flags");
-		    return NULL;
+		flagerr:
+		    {
+			/* 
+			 * We're trying to output the string that failed to
+			 * parse and the offset of the parse error within that.
+			 *
+			 * The string is *str.  It hasn't been changed since
+			 * entry to this function, I think, except that the
+			 * first non-variable-declaration line in this function
+			 * (currently the 238th line in this function)
+			 * writes a NUL to the first place in *str, so we'll
+			 * compensate by outputting the dollar sign manually.
+			 */
+			char *str_copy_for_output = dupstring(*str + 1);
+
+			/* 
+			 * Convert to a 1-based offset, because the shell
+			 * language is 1-based by default.
+			 */
+			zlong offset = s - *str + 1;
+
+			untokenize(str_copy_for_output);
+			zerr("error in flags near position %z in '$%s'", offset, str_copy_for_output);
+			return NULL;
+		    }
 		}
 	    }
 	    s++;
diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst
index ac99ff0e3..05bb61bdc 100644
--- a/Test/D04parameter.ztst
+++ b/Test/D04parameter.ztst
@@ -2691,3 +2691,8 @@ F:behavior, see http://austingroupbugs.net/view.php?id=888
   eval 'echo $(\*)'
 0:Backslash character other than newline is normal after $(
 >What a star
+
+ : ${(zZ+x+):-}
+1:parameter expansion flags parsing error gives a clue
+?(eval):1: error in flags near position 7 in '${(zZ+x+):-}'
+