zsh-users
 help / color / mirror / code / Atom feed
* Anonymous function with redirection and arguments
@ 2017-05-08  2:47 ` Daniel Shahaf
  2017-05-08 16:07   ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Shahaf @ 2017-05-08  2:47 UTC (permalink / raw)
  To: zsh-users

$ zsh -f
% () { echo foo $1 } >1; cat 1; rm -f 1    
foo
% () { echo foo $1 } bar >1; cat 1; rm -f 1 
foo bar
% () { echo foo $1 } >1 bar; cat 1; rm -f 1
zsh: parse error near `bar'
% 

It shouldn't parse error, should it?

I suppose this has something to do with the sticky redirection
syntax.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Anonymous function with redirection and arguments
  2017-05-08  2:47 ` Anonymous function with redirection and arguments Daniel Shahaf
@ 2017-05-08 16:07   ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2017-05-08 16:07 UTC (permalink / raw)
  To: zsh-users

On Mon, 8 May 2017 02:47:41 +0000
Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> $ zsh -f
> % () { echo foo $1 } >1; cat 1; rm -f 1    
> foo
> % () { echo foo $1 } bar >1; cat 1; rm -f 1 
> foo bar
> % () { echo foo $1 } >1 bar; cat 1; rm -f 1
> zsh: parse error near `bar'
> % 
> 
> It shouldn't parse error, should it?

There's no obvious reason why they shouldn't be mixed.

pws

diff --git a/Src/parse.c b/Src/parse.c
index 83e87af..b0de9a8 100644
--- a/Src/parse.c
+++ b/Src/parse.c
@@ -2030,10 +2030,21 @@ par_simple(int *cmplx, int nr)
 		/* Unnamed function */
 		int parg = ecadd(0);
 		ecadd(0);
-		while (tok == STRING) {
-		    ecstr(tokstr);
-		    argc++;
-		    zshlex();
+		while (tok == STRING || IS_REDIROP(tok)) {
+		    if (tok == STRING)
+		    {
+			ecstr(tokstr);
+			argc++;
+			zshlex();
+		    } else {
+			*cmplx = c = 1;
+			nrediradd = par_redir(&r, NULL);
+			p += nrediradd;
+			if (ppost)
+			    ppost += nrediradd;
+			sr += nrediradd;
+			parg += nrediradd;
+		    }
 		}
 		if (argc > 0)
 		    *cmplx = 1;
diff --git a/Test/A04redirect.ztst b/Test/A04redirect.ztst
index a5de552..2671080 100644
--- a/Test/A04redirect.ztst
+++ b/Test/A04redirect.ztst
@@ -475,6 +475,18 @@
 >Nothing output yet
 >I just read any old rubbish
 
+  print you cannot be serious >input1
+  () {
+    local var
+    read var
+    print $1 $var $2
+  } <input1 Shirley >output1 dude
+  print Nothing output yet
+  cat output1
+0:anonymous function redirections mixed with argument
+>Nothing output yet
+>Shirley you cannot be serious dude
+
   redirfn() {
     local var
     read var


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-05-08 16:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20170508024902epcas3p1e81421caa823e3c28d8a333b935cd5c5@epcas3p1.samsung.com>
2017-05-08  2:47 ` Anonymous function with redirection and arguments Daniel Shahaf
2017-05-08 16:07   ` Peter Stephenson

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).