zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <Peter.Stephenson@csr.com>
To: "zsh-users@zsh.org" <zsh-users@zsh.org>
Subject: Re: Bug / error in manpage.
Date: Tue, 2 Oct 2012 12:57:18 +0100	[thread overview]
Message-ID: <20121002125718.3ba26743@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <CC8F2A37.9567%larrys@fb.com>

(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@ntlworld.com.  You should get a useful
bounce message when it does change, however.)

On Mon, 1 Oct 2012 18:08:36 +0000
Larry Schrof <larrys@fb.com> 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@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


  reply	other threads:[~2012-10-02 12:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-01 18:08 Larry Schrof
2012-10-02 11:57 ` Peter Stephenson [this message]
2012-10-02 14:06 ` Bart Schaefer
2012-10-02 17:40   ` Larry Schrof
2012-10-02 18:35   ` Peter Stephenson
2012-10-02 18:39     ` Larry Schrof
2012-10-02 20:00       ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121002125718.3ba26743@pwslap01u.europe.root.pri \
    --to=peter.stephenson@csr.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).