From d48faef8cdff3c7c63c0a9164443e3d337aa1ec1 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 3 Aug 2011 18:45:17 +0000 Subject: 29633: more care with anonymous and other functions --- ChangeLog | 8 +++++++- Doc/Zsh/func.yo | 11 +++++++++-- Src/parse.c | 10 ++++++++-- Test/C04funcdef.ztst | 6 ++++++ 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3c0265440..c6209fca0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-08-03 Peter Stephenson + + * 29633: Doc/Zsh/func.yo, Src/parse.c, Test/C04funcdef.ztst: be + more careful that anonymous function syntax doesn't mess up + working syntax with other functions. + 2011-08-03 Peter Stephenson * 29635: Completion/Base/Widget/_complete_debug: Improve file @@ -15189,5 +15195,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5413 $ +* $Revision: 1.5414 $ ***************************************************** diff --git a/Doc/Zsh/func.yo b/Doc/Zsh/func.yo index 89b956cb4..7c391f80d 100644 --- a/Doc/Zsh/func.yo +++ b/Doc/Zsh/func.yo @@ -162,8 +162,15 @@ is not stored for future use. The function name is set to `tt((anon))'. Arguments to the function may be specified as words following the closing brace defining the function, hence if there are none no -arguments (other than tt($0)) are set. Note that this means -the argument list of any enclosing script or function is hidden. +arguments (other than tt($0)) are set. This is a difference from the +way other functions are parsed: normal function definitions may be +followed by certain keywords such as `tt(else)' or `tt(fi)', which will +be treated as arguments to anonymous functions, so that a newline or +semicolon is needed to force keyword interpretation. + +Note also that the argument list of any enclosing script or function is +hidden (as would be the case for any other function called at this +point). Redirections may be applied to the anonymous function in the same manner as to a current-shell structure enclosed in braces. The main use of anonymous diff --git a/Src/parse.c b/Src/parse.c index 5b8f0af48..e4d038b6e 100644 --- a/Src/parse.c +++ b/Src/parse.c @@ -1465,7 +1465,10 @@ par_funcdef(void) ecssub = oecssub; YYERRORV(oecused); } - incmdpos = 0; + if (num == 0) { + /* Anonymous function, possibly with arguments */ + incmdpos = 0; + } zshlex(); } else if (unset(SHORTLOOPS)) { lineno += oldlineno; @@ -1721,7 +1724,10 @@ par_simple(int *complex, int nr) ecssub = oecssub; YYERROR(oecused); } - incmdpos = 0; + if (argc == 0) { + /* Anonymous function, possibly with arguments */ + incmdpos = 0; + } zshlex(); } else { int ll, sl, c = 0; diff --git a/Test/C04funcdef.ztst b/Test/C04funcdef.ztst index 742d2d0a7..90f01e397 100644 --- a/Test/C04funcdef.ztst +++ b/Test/C04funcdef.ztst @@ -245,6 +245,12 @@ >empty >here + if true; then f() { echo foo1; } else f() { echo bar1; } fi; f + if false; then f() { echo foo2; } else f() { echo bar2; } fi; f +0:Compatibility with other shells when not anonymous functions +>foo1 +>bar2 + %clean rm -f file.in file.out -- cgit 1.4.1