zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh workers <zsh-workers@zsh.org>
Subject: Re: code that used to work that doesn't anymore
Date: Sun, 22 Feb 2015 21:28:58 +0000	[thread overview]
Message-ID: <20150222212858.2ce59c6d@ntlworld.com> (raw)
In-Reply-To: <CAHYJk3QKsGYhjM8a6-sMqVimzkyuxHbz61MfHLAEhcY4EZW1uw@mail.gmail.com>

On Sun, 22 Feb 2015 22:07:24 +0100
Mikael Magnusson <mikachu@gmail.com> wrote:
> No idea if this was meant to be valid syntax, but used to run:
> % zselect -t ${$(( $1 * 100 ))%.[0-9]#}
> zsh: bad substitution

It appears that's supported, but there was no test for it so it didn't
get picked up as a change.

diff --git a/Src/subst.c b/Src/subst.c
index 176a004..f52bcdf 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -2217,12 +2217,28 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags)
      */
     idbeg = s;
     if ((subexp = (inbrace && s[-1] && isstring(*s) &&
-		   (s[1] == Inbrace || s[1] == Inpar)))) {
+		   (s[1] == Inbrace || s[1] == Inpar || s[1] == Inparmath)))) {
 	int sav;
 	int quoted = *s == Qstring;
+	int outtok;
 
 	val = s++;
-	skipparens(*s, *s == Inpar ? Outpar : Outbrace, &s);
+	switch (*s) {
+	case Inbrace:
+	    outtok = Outbrace;
+	    break;
+	case Inpar:
+	    outtok = Outpar;
+	    break;
+	case Inparmath:
+	    outtok = Outparmath;
+	    break;
+	default:
+	    /* "Can't Happen" (TM) */
+	    DPUTS(1, "Nested substitution: This Can't Happen (TM)");
+	    return NULL;
+	}
+	skipparens(*s, outtok, &s);
 	sav = *s;
 	*s = 0;
 	/*
diff --git a/Test/C01arith.ztst b/Test/C01arith.ztst
index 67d78ee..d3176dd 100644
--- a/Test/C01arith.ztst
+++ b/Test/C01arith.ztst
@@ -300,6 +300,7 @@
   print $(( 0b2 ))
 1:Binary numbers don't tend to have 2's in
 ?(eval):1: bad math expression: operator expected at `2 '
+# ` for emacs shell mode
 
   integer varassi
   print $(( varassi = 5.5 / 2.0 ))
@@ -376,3 +377,10 @@
   esac))
 0:Would-be math expansion with extra parenthesis making it a cmd subst
 >Worked OK
+
+  (setopt extendedglob
+  set -- 32.463
+  print ${$(( $1 * 100 ))%%.[0-9]#})
+0:Arithmetic substitution nested in parameter substitution
+>3246
+ 

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


      reply	other threads:[~2015-02-22 21:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-22 21:07 Mikael Magnusson
2015-02-22 21:28 ` Peter Stephenson [this message]

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=20150222212858.2ce59c6d@ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@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).