summary refs log tree commit diff
path: root/Src/text.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2011-06-19 20:12:00 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2011-06-19 20:12:00 +0000
commit6062529d3fc7c7d29c63d0726d2449d4b56f33ac (patch)
tree8131c4e1678053413559fe71159201f891786a70 /Src/text.c
parent437d5d98f6d05588e23a6d9fda50184d0b6a80bb (diff)
downloadzsh-6062529d3fc7c7d29c63d0726d2449d4b56f33ac.tar.gz
zsh-6062529d3fc7c7d29c63d0726d2449d4b56f33ac.tar.xz
zsh-6062529d3fc7c7d29c63d0726d2449d4b56f33ac.zip
29492: add argument handling to anonymous functions
Diffstat (limited to 'Src/text.c')
-rw-r--r--Src/text.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/Src/text.c b/Src/text.c
index 669037a2d..f55553ed0 100644
--- a/Src/text.c
+++ b/Src/text.c
@@ -253,6 +253,7 @@ struct tstack {
 	struct {
 	    char *strs;
 	    Wordcode end;
+	    int nargs;
 	} _funcdef;
 	struct {
 	    Wordcode end;
@@ -456,19 +457,31 @@ gettext2(Estate state)
 	    if (!s) {
 		Wordcode p = state->pc;
 		Wordcode end = p + WC_FUNCDEF_SKIP(code);
+		int nargs = *state->pc++;
 
-		taddlist(state, *state->pc++);
+		taddlist(state, nargs);
+		if (nargs)
+		    taddstr(" ");
 		if (tjob) {
-		    taddstr(" () { ... }");
+		    taddstr("() { ... }");
 		    state->pc = end;
+		    if (!nargs) {
+			/*
+			 * Unnamed fucntion.
+			 * We're not going to pull any arguments off
+			 * later, so skip them now...
+			 */
+			state->pc += *end;
+		    }
 		    stack = 1;
 		} else {
-		    taddstr(" () {");
+		    taddstr("() {");
 		    tindent++;
 		    taddnl(1);
 		    n = tpush(code, 1);
 		    n->u._funcdef.strs = state->strs;
 		    n->u._funcdef.end = end;
+		    n->u._funcdef.nargs = nargs;
 		    state->strs += *state->pc;
 		    state->pc += 3;
 		}
@@ -478,6 +491,17 @@ gettext2(Estate state)
 		dec_tindent();
 		taddnl(0);
 		taddstr("}");
+		if (s->u._funcdef.nargs == 0) {
+		    /* Unnamed function with post-arguments */
+		    int nargs;
+		    s->u._funcdef.end += *state->pc++;
+		    nargs = *state->pc++;
+		    if (nargs) {
+			taddstr(" ");
+			taddlist(state, nargs);
+		    }
+		    state->pc = s->u._funcdef.end;
+		}
 		stack = 1;
 	    }
 	    break;