On Sat, Dec 28, 2019 at 02:40:27PM +0100, Jeremie Courreges-Anglas 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.
Thanks, I wanted this as well for some time.
> Since the "reject = true;" mechanism bypasses yylex(), I have to
> pass token() the same flags as with the musthave('{') call below.
>
> ok?
Defining, listing and undefining works. As per the differences between
`function name' and `name()', your new `function name()' behaves like
the former. This should be clarified in the manual.
The Functions paragraph starts with repeating the currently two possible
forms, either remove the duplicate work there or adjust accordingly. It
also goes into detail about the differences, e.g. `$0' being different;
strictly speaking this must be clarified as well, since the new form
`funtion name()' now satisfies both criteria: "Functions defined with
the function reserved word" and "functions defined with the () notation".
> 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 ()
There must be no space between `name' and `['.
> .No { Ar list ; No }
> .Xc
> Defines the function