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

PATCH: (z) splitting with double parenthesis



Happens when a introductory double parenthesis turns out to want to be a
subshell substitution rather than a math substitution.

% foo='((0.25542 * 60) - 15)*60'
% print -l ${(z)foo} 
0.25542 * 60
(
0.25542
*
60
)
-
15
)
*60

This only
applies to command position since otherwise parentheses don't cause a
new word... hmm, I think (Z) could do with an option to say don't treat
the first word as a command word, but that can wait.  You can work
around it with 

  foo=": $foo"
  split=(${${(z)foo}[2,-1]})

Index: Src/lex.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/lex.c,v
retrieving revision 1.62
diff -p -u -r1.62 lex.c
--- Src/lex.c	14 Dec 2010 10:40:42 -0000	1.62
+++ Src/lex.c	18 Dec 2010 23:13:43 -0000
@@ -885,6 +885,11 @@ gettok(void)
 		    return DINPAR;
 
 		case 0:
+		    /*
+		     * Not math, so we don't return the contents
+		     * as a string in this case.
+		     */
+		    tokstr = NULL;
 		    return INPAR;
 
 		default:
Index: Test/D04parameter.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/D04parameter.ztst,v
retrieving revision 1.51
diff -p -u -r1.51 D04parameter.ztst
--- Test/D04parameter.ztst	15 Dec 2010 04:05:50 -0000	1.51
+++ Test/D04parameter.ztst	18 Dec 2010 23:13:43 -0000
@@ -393,6 +393,7 @@
     'foo=(1 2 3)'
     '(( 3 + 1 == 8 / 2 ))'
     'for (( i = 1 ; i < 10 ; i++ ))'
+    '((0.25542 * 60) - 15)*60'
   )
   for string in $strings; do
     array=(${(z)string})
@@ -416,6 +417,19 @@
 >4:i < 10 ;:
 >5:i++ :
 >6:)):
+# This one needs resolving between a math expression and
+# a command, which causes interesting effects internally.
+>1:(:
+>2:(:
+>3:0.25542:
+>4:*:
+>5:60:
+>6:):
+>7:-:
+>8:15:
+>9:):
+>10:*60:
+
 
   line=$'A line with # someone\'s comment\nanother line # (1 more\nanother one'
   print "*** Normal ***"

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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