From: Ori Bernstein Date: Thu, 8 Jul 2021 21:35:34 +0000 (+0000) Subject: rc: add subshell-function syntax X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=2f8a59f4b5bfe028c022855acc19666d69eed909;p=plan9front.git rc: add subshell-function syntax fn foo @{bar} is now equivalent to fn foo {@{bar}}. As a side effect, this disallows creating functions named after keywords without first quoting them. --- diff --git a/sys/src/cmd/rc/syn.y b/sys/src/cmd/rc/syn.y index 051c9e88e..542dcba78 100644 --- a/sys/src/cmd/rc/syn.y +++ b/sys/src/cmd/rc/syn.y @@ -17,7 +17,7 @@ struct tree *tree; }; %type line paren brace body cmdsa cmdsan assign epilog redir -%type cmd simple first word comword keyword words +%type cmd simple first word comword keyword words comwords %type NOT FOR IN WHILE IF TWIDDLE BANG SUBSHELL SWITCH FN %type WORD REDIR DUP PIPE %% @@ -68,8 +68,10 @@ cmd: {$$=0;} | assign cmd %prec BANG {$$=mung3($1, $1->child[0], $1->child[1], $2);} | BANG cmd {$$=mung1($1, $2);} | SUBSHELL cmd {$$=mung1($1, $2);} -| FN words brace {$$=tree2(FN, $2, $3);} -| FN words {$$=tree1(FN, $2);} +| FN comwords brace {$$=tree2(FN, $2, $3);} +| FN comwords SUBSHELL brace + {$$=tree2(FN, $2, mung1($3, $4));} +| FN comwords {$$=tree1(FN, $2);} simple: first | simple word {$$=tree2(ARGLIST, $1, $2);} | simple redir {$$=tree2(ARGLIST, $1, $2);} @@ -90,3 +92,5 @@ comword: '$' word {$$=tree1('$', $2);} keyword: FOR|IN|WHILE|IF|NOT|TWIDDLE|BANG|SUBSHELL|SWITCH|FN words: {$$=(struct tree*)0;} | words word {$$=tree2(WORDS, $1, $2);} +comwords: {$$=(struct tree*)0;} +| comwords comword {$$=tree2(WORDS, $1, $2);}