zsh-workers
 help / color / mirror / code / Atom feed
* \" in $(( )) vs $[ ]
@ 2011-09-15 10:17 Mikael Magnusson
  2011-09-15 12:12 ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Mikael Magnusson @ 2011-09-15 10:17 UTC (permalink / raw)
  To: zsh workers

% echo $(( ##\' ))
39
% echo $[ ##\" ]
34
% echo $(( ##\" ))
<cmdsubst:~>%

and tangentially, why does the above also work with only one #?
% a=b
% echo $[ #a ]
98
% echo $[ ##a ]
97
% echo $[ #\' ]
39
% echo $[ #\" ]
34

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: \" in $(( )) vs $[ ]
  2011-09-15 10:17 \" in $(( )) vs $[ ] Mikael Magnusson
@ 2011-09-15 12:12 ` Peter Stephenson
  2011-09-15 12:56   ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2011-09-15 12:12 UTC (permalink / raw)
  To: zsh workers

On Thu, 15 Sep 2011 12:17:44 +0200
Mikael Magnusson <mikachu@gmail.com> wrote:
> % echo $(( ##\" ))
> <cmdsubst:~>%

At this point we haven't resolved between $((...)...) and $((...)), but
I don't think double quote needs to be handled differently in the two
cases.

Index: Src/lex.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/lex.c,v
retrieving revision 1.67
diff -p -u -r1.67 lex.c
--- Src/lex.c	19 Jun 2011 16:26:11 -0000	1.67
+++ Src/lex.c	15 Sep 2011 12:09:27 -0000
@@ -1482,7 +1482,8 @@ dquote_parse(char endchar, int sub)
 		    (endchar == ']' && (c == '[' || c == ']' ||
 					c == '(' || c == ')' ||
 					c == '{' || c == '}' ||
-					(c == '"' && sub))))
+					(c == '"' && sub))) ||
+		    (endchar == ')' && c == '"'))
 		    add(Bnull);
 		else {
 		    /* lexstop is implicitly handled here */
Index: Test/D08cmdsubst.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/D08cmdsubst.ztst,v
retrieving revision 1.4
diff -p -u -r1.4 D08cmdsubst.ztst
--- Test/D08cmdsubst.ztst	11 Jul 2009 16:43:01 -0000	1.4
+++ Test/D08cmdsubst.ztst	15 Sep 2011 12:09:28 -0000
@@ -98,3 +98,11 @@
  echo `echo $?`
 0:Non-empty command substitution inherits status
 >1
+
+ echo $(( ##\" ))
+ echo $(echo \")
+ echo $((echo \"); echo OK)
+0:Handling of backslash double quote in parenthesised substitutions
+>34
+>"
+>" OK

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: \" in $(( )) vs $[ ]
  2011-09-15 12:12 ` Peter Stephenson
@ 2011-09-15 12:56   ` Peter Stephenson
  2011-09-15 13:59     ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2011-09-15 12:56 UTC (permalink / raw)
  To: zsh workers

Rethink... the following fits better with the existing logic.

I wonder if that parenthesised group I've patched shouldn't say
  endchar != '"'
?  That looks neater and seems to pass the tests.

Index: Src/lex.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/lex.c,v
retrieving revision 1.67
diff -p -u -r1.67 lex.c
--- Src/lex.c	19 Jun 2011 16:26:11 -0000	1.67
+++ Src/lex.c	15 Sep 2011 12:52:47 -0000
@@ -1567,7 +1567,8 @@ dquote_parse(char endchar, int sub)
 		err = (!brct-- && math);
 	    break;
 	case '"':
-	    if (intick || ((endchar == ']' || !endchar) && !bct))
+	    if (intick || ((endchar == ']' || endchar == ')' || !endchar) &&
+			   !bct))
 		break;
 	    if (bct) {
 		add(Dnull);
Index: Test/D08cmdsubst.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/D08cmdsubst.ztst,v
retrieving revision 1.4
diff -p -u -r1.4 D08cmdsubst.ztst
--- Test/D08cmdsubst.ztst	11 Jul 2009 16:43:01 -0000	1.4
+++ Test/D08cmdsubst.ztst	15 Sep 2011 12:52:48 -0000
@@ -98,3 +98,11 @@
  echo `echo $?`
 0:Non-empty command substitution inherits status
 >1
+
+ echo $(( ##\" ))
+ echo $(echo \")
+ echo $((echo \"); echo OK)
+0:Handling of backslash double quote in parenthesised substitutions
+>34
+>"
+>" OK

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: \" in $(( )) vs $[ ]
  2011-09-15 12:56   ` Peter Stephenson
@ 2011-09-15 13:59     ` Peter Stephenson
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Stephenson @ 2011-09-15 13:59 UTC (permalink / raw)
  To: zsh workers

On Thu, 15 Sep 2011 13:56:57 +0100
Peter Stephenson <Peter.Stephenson@csr.com> wrote:
> Rethink... the following fits better with the existing logic.
> 
> I wonder if that parenthesised group I've patched shouldn't say
>   endchar != '"'
> ?  That looks neater and seems to pass the tests.

The only difference appears to be that the change would additionally
catch the case of a double quote within one of the first two parts of an
arithmetic for, consistent with the last part (as that's terminated by a
closing parenthesis).  So I'll commit that.

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-09-15 13:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-15 10:17 \" in $(( )) vs $[ ] Mikael Magnusson
2011-09-15 12:12 ` Peter Stephenson
2011-09-15 12:56   ` Peter Stephenson
2011-09-15 13:59     ` 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).