Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: lexer bug



See:

  beta% (( ${#a[(R)[^[]]} ))
  zsh: command not found: 0
  beta%

Due to the unbalanced brackets this is parsed as `( ( ... ) )'.

The patch turns off counting opening/closing parens and brackets in
math expressions when we are inside a parameter expression. Can anyone 
think of a case where this is dangerous/wrong?

Bye
 Sven

diff -u oldsrc/lex.c Src/lex.c
--- oldsrc/lex.c	Wed Nov  3 11:47:53 1999
+++ Src/lex.c	Thu Nov  4 14:22:07 1999
@@ -1299,16 +1299,20 @@
 		intick = 1, ALLOWHIST
 	    break;
 	case '(':
-	    pct++;
+	    if (!math || !bct)
+		pct++;
 	    break;
 	case ')':
-	    err = (!pct-- && math);
+	    if (!math || !bct)
+		err = (!pct-- && math);
 	    break;
 	case '[':
-	    brct++;
+	    if (!math || !bct)
+		brct++;
 	    break;
 	case ']':
-	    err = (!brct-- && math);
+	    if (!math || !bct)
+		err = (!brct-- && math);
 	    break;
 	case '"':
 	    if (intick || (!endchar && !bct))

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author