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

Re: Bug / error in manpage.



(By the way, my work email is about to change, so if you're emailing me
directly, which isn't usually necessary for zsh discussions, use my
home email, p.w.stephenson@xxxxxxxxxxxx.  You should get a useful
bounce message when it does change, however.)

On Mon, 1 Oct 2012 18:08:36 +0000
Larry Schrof <larrys@xxxxxx> wrote:
> The man page for subscripting flags is incorrect. Here is the excerpt:
> 
>        The flags s, n and b take an argument; the delimiter is shown below  as
>        `:',  but  any  character,  or  the  matching  pairs  `(...)', `{...}',
>        `[...]', or `<...>', may be used.
> 
> The '< >' brackets do not work as separators:
> zsh% print $string[(ws<:>)2]
> zsh: parse error near `)'
> zsh%

I don't think there's any reason this shouldn't be made to work; there's
currently no check to make the square bracket context special for angle
brackets, except if you used braces in the parameter substitution.

The change also makes things like this work:

[[ '<bleagh>' = [<>]*[<>] ]]

I interpret that as a good thing.  Angle brackets only need to do
special things when used as redirection operators and (to a more limited
extent, since they're then part of a string) numeric glob ranges.

Index: Src/lex.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/lex.c,v
retrieving revision 1.70
diff -p -u -r1.70 lex.c
--- Src/lex.c	8 Dec 2011 19:42:07 -0000	1.70
+++ Src/lex.c	2 Oct 2012 11:45:19 -0000
@@ -1218,7 +1218,7 @@ gettokstr(int c, int sub)
 		c = Comma;
 	    break;
 	case LX2_OUTANG:
-	    if (in_brace_param || sub)
+	    if (in_brace_param || sub || brct)
 		break;
 	    e = hgetc();
 	    if (e != '(') {
@@ -1255,7 +1255,7 @@ gettokstr(int c, int sub)
 		break;
 	    }
 	    lexstop = 0;
-	    if (in_brace_param || sub)
+	    if (in_brace_param || sub || brct)
 		break;
 	    goto brk;
 	case LX2_EQUALS:
Index: Test/D06subscript.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/D06subscript.ztst,v
retrieving revision 1.13
diff -p -u -r1.13 D06subscript.ztst
--- Test/D06subscript.ztst	31 Jul 2008 13:53:28 -0000	1.13
+++ Test/D06subscript.ztst	2 Oct 2012 11:45:20 -0000
@@ -249,3 +249,23 @@
   string[0]=!
 1:Can't set only element zero of string
 ?(eval):1: string: assignment to invalid subscript range
+
+  string="Life,+like+a+dome+of+many-colour'd+glass"
+  for delims in "()" "{}" "[]" "<>"; do
+    eval 'print ${string[(ws'$delims[1]'+'$delims[2]')2]}'
+    eval 'print $string[(ws'$delims[1]'+'$delims[2]')3]'
+    eval 'print "$string[(ws'$delims[1]'+'$delims[2]')4]"'
+  done
+0:Check matched delimiters in subscripts
+>like
+>a
+>dome
+>like
+>a
+>dome
+>like
+>a
+>dome
+>like
+>a
+>dome

-- 
Peter Stephenson <pws@xxxxxxx>            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



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