1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-02 10:01:11 +02:00

35153: nested math substitution

This commit is contained in:
Peter Stephenson 2015-05-15 10:19:53 +01:00
parent 59a874f94e
commit 0da0a0b9c7
3 changed files with 21 additions and 2 deletions

View file

@ -1,5 +1,7 @@
2015-05-15 Peter Stephenson <p.stephenson@samsung.com>
* 35153: Src/subst.c, Test/C01arith.ztst: nested math substitution.
* 35151: Src/subst.c: improved check for both b and q flags.
* 35131: Src/pattern.c: "[]" in a pattern is treated as an empty

View file

@ -259,10 +259,19 @@ stringsubst(LinkList list, LinkNode node, int pf_flags, int asssub)
#endif
str--;
} else if (c == Inparmath) {
/* Math substitution of the form $((...)) */
/*
* Math substitution of the form $((...)).
* These can be nested, for goodness sake...
*/
int mathpar = 1;
str[-1] = '\0';
while (*str != Outparmath && *str)
while (mathpar && *str) {
str++;
if (*str == Outparmath)
mathpar--;
else if (*str == Inparmath)
mathpar++;
}
if (*str != Outparmath) {
zerr("failed to find end of math substitution");
return NULL;

View file

@ -387,3 +387,11 @@
print $((`:`))
0:Null string in arithmetic evaluation after command substitution
>0
print $(( 1 + $(( 2 + 3 )) ))
print $(($((3+4))))
print $((1*$((2*$((3))*4))*5))
0:Nested math substitutions. Yes, I know, very useful.
>6
>7
>120