zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: (z) splitting with double parenthesis
@ 2010-12-18 23:21 Peter Stephenson
  0 siblings, 0 replies; only message in thread
From: Peter Stephenson @ 2010-12-18 23:21 UTC (permalink / raw)
  To: Zsh hackers list

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@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-12-18 23:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-18 23:21 PATCH: (z) splitting with double parenthesis Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).