If this diff gets accepted, in ksh's man page, you'll probably have to change the following line as it's not entirely disambiguous how a function would behave if it had both 'function' and '()' where it was defined: "Functions defined with the function reserved word are treated differently in the following ways from functions defined with the () notation:" Notably, would someone learning ksh realise 'function funname()' isn't being defined with both notations at once? Examples might be: "Functions defined with the function reserved word are treated differently in the following ways from functions defined solely with the () notation:" "Functions defined with the function reserved word are treated differently in the following ways from functions defined without it:"
That said, I personally think to define a function with both 'function' and '()' is a genuine syntax error. On Sat, Dec 28, 2019 at 8:42 AM Jeremie Courreges-Anglas <[email protected]> wrote: > > > We have a few ports (~12) patched because of shell script constructs > like > > function usage() > { > > which are rejected by our ksh. Indeed ksh only supports either > > usage() > { > > or > > function usage > { > > Both bash and zsh also allow an optional "()". The diff below > implements the missing bits. > > Since the "reject = true;" mechanism bypasses yylex(), I have to > pass token() the same flags as with the musthave('{') call below. > > ok? > > > Index: ksh.1 > =================================================================== > RCS file: /d/cvs/src/bin/ksh/ksh.1,v > retrieving revision 1.208 > diff -u -p -r1.208 ksh.1 > --- ksh.1 26 Nov 2019 22:49:01 -0000 1.208 > +++ ksh.1 27 Dec 2019 12:27:37 -0000 > @@ -679,7 +679,7 @@ The exit status of a > statement is the last exit status of the > .Ar list > in the body of the loop; if the body is not executed, the exit status is > zero. > -.It Xo Ic function Ar name > +.It Xo Ic function Ar name Op () > .No { Ar list ; No } > .Xc > Defines the function > Index: syn.c > =================================================================== > RCS file: /d/cvs/src/bin/ksh/syn.c,v > retrieving revision 1.39 > diff -u -p -r1.39 syn.c > --- syn.c 24 Apr 2018 08:25:16 -0000 1.39 > +++ syn.c 27 Dec 2019 11:25:41 -0000 > @@ -555,6 +555,12 @@ function_body(char *name, > * an open-brace. > */ > if (ksh_func) { > + /* allow optional () after function name */ > + if (token(CONTIN|KEYWORD|ALIAS) == '(') > + musthave(')', 0); > + else > + reject = true; > + > musthave('{', CONTIN|KEYWORD|ALIAS); /* } */ > reject = true; > } > > > -- > jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE >
