mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-11 13:01:28 +02:00
45583/0009: Add end-of-options guard support to 'function -T'.
This commit is contained in:
parent
386d9ac8ff
commit
aed0cb4408
4 changed files with 53 additions and 11 deletions
|
@ -1,5 +1,8 @@
|
||||||
2020-03-22 Daniel Shahaf <d.s@daniel.shahaf.name>
|
2020-03-22 Daniel Shahaf <d.s@daniel.shahaf.name>
|
||||||
|
|
||||||
|
* 45583/0009: README, Src/parse.c, Test/E02xtrace.ztst: Add
|
||||||
|
end-of-options guard support to 'function -T'.
|
||||||
|
|
||||||
* 45583/0008: Doc/Zsh/grammar.yo, README, Src/exec.c,
|
* 45583/0008: Doc/Zsh/grammar.yo, README, Src/exec.c,
|
||||||
Src/parse.c, Test/E02xtrace.ztst: Add the 'function -T' syntax.
|
Src/parse.c, Test/E02xtrace.ztst: Add the 'function -T' syntax.
|
||||||
|
|
||||||
|
|
23
README
23
README
|
@ -43,12 +43,23 @@ name of an external command. Now it may also be a shell function. Normal
|
||||||
command word precedece rules apply, so if you have a function and a command
|
command word precedece rules apply, so if you have a function and a command
|
||||||
with the same name, the function will be used.
|
with the same name, the function will be used.
|
||||||
|
|
||||||
The syntax "function -T { ... }" used to define a function named "-T".
|
The "function" reserved word, used to define functions, gained a new -T option.
|
||||||
It now defines an anonymous function with single-level tracing enabled ---
|
That affects syntaxes such as:
|
||||||
same as "function f { ... }; functions -T f; f", but without naming the
|
|
||||||
function. The syntax "function -T foo { ... }" is similarly affected: it
|
1. "function -T { ... }". It used to define a function named "-T". It
|
||||||
now defines a function "foo" with tracing enabled; previously it defined
|
now defines and executes an anonymous function with single-level tracing
|
||||||
two functions, named "-T" and "foo" (see the MULTI_FUNC_DEF option).
|
enabled --- same as "function f { ... }; functions -T f; f", but without
|
||||||
|
naming the function.
|
||||||
|
|
||||||
|
2. "function -T foo { ... }". It used to define two functions, named "-T"
|
||||||
|
and "foo" (see the MULTI_FUNC_DEF option). It now defines a function
|
||||||
|
"foo" with tracing enabled.
|
||||||
|
|
||||||
|
3. "function -- { ... }". It used to define a function named "--". It
|
||||||
|
now defines and executes an anonymous function. The "--" is taken to be
|
||||||
|
an end-of-options guard (same as "ls --").
|
||||||
|
|
||||||
|
The sh-compatible function definition syntax, "f() { ... }", is unchanged.
|
||||||
|
|
||||||
Incompatibilities since 5.7.1
|
Incompatibilities since 5.7.1
|
||||||
-----------------------------
|
-----------------------------
|
||||||
|
|
16
Src/parse.c
16
Src/parse.c
|
@ -1680,10 +1680,18 @@ par_funcdef(int *cmplx)
|
||||||
p = ecadd(0);
|
p = ecadd(0);
|
||||||
ecadd(0); /* p + 1 */
|
ecadd(0); /* p + 1 */
|
||||||
|
|
||||||
if (tok == STRING && tokstr[0] == Dash &&
|
/* Consume an initial (-T), (--), or (-T --).
|
||||||
tokstr[1] == 'T' && !tokstr[2]) {
|
* Anything else is a literal function name.
|
||||||
++do_tracing;
|
*/
|
||||||
zshlex();
|
if (tok == STRING && tokstr[0] == Dash) {
|
||||||
|
if (tokstr[1] == 'T' && !tokstr[2]) {
|
||||||
|
++do_tracing;
|
||||||
|
zshlex();
|
||||||
|
}
|
||||||
|
if (tok == STRING && tokstr[0] == Dash &&
|
||||||
|
tokstr[1] == Dash && !tokstr[2]) {
|
||||||
|
zshlex();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (tok == STRING) {
|
while (tok == STRING) {
|
||||||
|
|
|
@ -199,9 +199,29 @@
|
||||||
?+f:0> echo traced named function
|
?+f:0> echo traced named function
|
||||||
>traced named function
|
>traced named function
|
||||||
|
|
||||||
function -T -T { echo trace function literally named "-T" }
|
function -T -- -T { echo trace function literally named "-T" }
|
||||||
-T
|
-T
|
||||||
|
function -T -- { echo trace anonymous function }
|
||||||
|
functions -- -- # no output
|
||||||
0:define traced function: parse test
|
0:define traced function: parse test
|
||||||
?+-T:0> echo trace function literally named -T
|
?+-T:0> echo trace function literally named -T
|
||||||
>trace function literally named -T
|
>trace function literally named -T
|
||||||
|
?+(anon):0> echo trace anonymous function
|
||||||
|
>trace anonymous function
|
||||||
|
|
||||||
|
function -- g { echo g }
|
||||||
|
g
|
||||||
|
function -- { echo anonymous }
|
||||||
|
functions -- -- # no output
|
||||||
|
0:function end-of-"options" syntax, #1
|
||||||
|
>g
|
||||||
|
>anonymous
|
||||||
|
|
||||||
|
function -- -T { echo runs }
|
||||||
|
functions -- -- # no output
|
||||||
|
echo the definition didn\'t execute it
|
||||||
|
-T
|
||||||
|
0:function end-of-"options" syntax, #2
|
||||||
|
>the definition didn't execute it
|
||||||
|
>runs
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue