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