From: ori@eigenstate.org
To: 9front@9front.org
Subject: [PATCH]: Playing with rc: subshell functions.
Date: Wed, 11 Dec 2019 14:42:02 -0800 [thread overview]
Message-ID: <AF2AB5765FB5B7BE0E60AF400917A1A0@eigenstate.org> (raw)
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<tree> line paren brace body cmdsa cmdsan assign epilog redir
-%type<tree> cmd simple first word comword keyword words
+%type<tree> cmd simple first word comword keyword words comwords
%type<tree> NOT FOR IN WHILE IF TWIDDLE BANG SUBSHELL SWITCH FN
%type<tree> 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);}
reply other threads:[~2019-12-11 22:42 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AF2AB5765FB5B7BE0E60AF400917A1A0@eigenstate.org \
--to=ori@eigenstate.org \
--cc=9front@9front.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).