From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eigenstate.org ([206.124.132.107]) by ewsd; Wed Dec 11 17:42:03 EST 2019 Received: from eigenstate.org (localhost [127.0.0.1]) by eigenstate.org (OpenSMTPD) with ESMTP id 0f048bfd for <9front@9front.org>; Wed, 11 Dec 2019 14:42:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=eigenstate.org; h= message-id:to:subject:date:from:mime-version:content-type :content-transfer-encoding; s=mail; bh=W/xPisXYiMXT9rLw2U0Qx0SXx 9w=; b=AW/RyS5B/NZvyn3GetMawTiSz0TAxnMUbpHYpklca9fh02GGxZuqgLdkE Vno3/4YdW0ze40E4ToBsmNbTfudmvOsGIpExXmCftvjSx/qmS/BWsuLWan7gGvZE mj0/DfNdg23ky88YkD7j6Wozc/bEFID/NWMTo1ijgQh7qAzHgM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=eigenstate.org; h=message-id :to:subject:date:from:mime-version:content-type :content-transfer-encoding; q=dns; s=mail; b=BRx/ikfwcLeUjADI0aZ /HYoSLUkuVcnAqSqBeyEH5mXN7kNS5/Dq8czZlksmOzSLP81NcbUp1Q+fXQJOX7f 5qTYUMt+Pe4ywzUA7VmKBcOUn8n7RCh5MJ+AKGpmisdqtfUNpUx4KnLgFD669LWw 34U6BKWivgXcTNpRf7wxAGao= Received: from stockyard.guest.pikopiko.org (mail.gunshopcomputers.com [209.180.212.191]) by eigenstate.org (OpenSMTPD) with ESMTPSA id 51fa1305 (TLSv1.2:ECDHE-RSA-AES256-SHA:256:NO) for <9front@9front.org>; Wed, 11 Dec 2019 14:42:02 -0800 (PST) Message-ID: To: 9front@9front.org Subject: [PATCH]: Playing with rc: subshell functions. Date: Wed, 11 Dec 2019 14:42:02 -0800 From: ori@eigenstate.org MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: core dependency general-purpose layer I don't know if I want this committed, but I figured I'd toss it out if people care. This patch adds support for running function bodies in subshells, so fn foo @{...} is sugar for for fn foo {@{ ... }} This costs us something, though -- to fix a syntax ambiguity, I removed the ability to name functions after keywords. So before: fn if @ { echo wut } would work, and you could do: term% 'if' wut term% '@' wut Now, it'd be a syntax error: rc: #d/0: token if: syntax error diff -r f1523de908ce sys/src/cmd/rc/syn.y --- a/sys/src/cmd/rc/syn.y Tue Dec 10 23:13:25 2019 -0800 +++ b/sys/src/cmd/rc/syn.y Wed Dec 11 14:41:32 2019 -0800 @@ -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 @@ | 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 @@ 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);}