mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-01-19 11:31:26 +01:00
34606: fix up nested arithmetic substitution
Arithmetic within a parameter substitution is a special case that needs fixing with the introduction of the new Inparmath token. Add test.
This commit is contained in:
parent
bcc4ab792d
commit
6fa63a0ce2
3 changed files with 29 additions and 2 deletions
|
@ -1,5 +1,8 @@
|
|||
2015-02-22 Peter Stephenson <p.w.stephenson@ntlworld.com>
|
||||
|
||||
* 34606: Src/subst.c, Test/C01arith.ztst: fix up arithmetic
|
||||
nested in parameter substitution.
|
||||
|
||||
* 34604: Src/hist.c: Work around problem with changes in Meta
|
||||
affecting history file when read in.
|
||||
|
||||
|
|
20
Src/subst.c
20
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;
|
||||
/*
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue