rc

[fork] interactive rc shell
Log | Files | Refs | README | LICENSE

commit 280d57b40b71c16b242dab52286592efdf2e3356
parent 67a87ad0104d88e8b1711a3831d616598edb30c2
Author: Bert Münnich <ber.t@posteo.de>
Date:   Fri,  2 Mar 2018 21:04:06 +0100

Unify bodies of if and if-else statements

Fixes issue #31 of rakitzis/rc.

Diffstat:
Mparse.y | 17++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/parse.y b/parse.y @@ -17,7 +17,8 @@ Node *parsetree; /* not using yylval because bison declares it as an auto */ %token OROR PIPE REDIR SREDIR SUB SUBSHELL SWITCH TWIDDLE WHILE WORD HUH %left '^' '=' -%left WHILE ')' ELSE +%right ELSE TWIDDLE +%left WHILE ')' %left ANDAND OROR '\n' %left BANG SUBSHELL %left PIPE @@ -43,7 +44,7 @@ Node *parsetree; /* not using yylval because bison declares it as an auto */ %type <keyword> keyword %type <node> assign body brace case cbody cmd cmdsa cmdsan comword epilog first line nlwords paren redir sword simple iftail word words - arg args + arg args else %start rc @@ -96,8 +97,10 @@ cbody : cmd { $$ = mk(nCbody, $1, NULL); } | case cbody { $$ = mk(nCbody, $1, $2); } | cmdsan cbody { $$ = mk(nCbody, $1, $2); } -iftail : cmd %prec ELSE - | brace ELSE optnl cmd { $$ = mk(nElse,$1,$4); } +iftail : cmd else { $$ = $2 != NULL ? mk(nElse, $1, $2) : $1; } + +else : /* empty */ %prec ELSE { $$ = NULL; } + | ELSE optnl cmd { $$ = $3; } cmd : /* empty */ %prec WHILE { $$ = NULL; } | simple @@ -116,13 +119,13 @@ cmd : /* empty */ %prec WHILE { $$ = NULL; } | BANG optcaret cmd { $$ = mk(nBang,$3); } | SUBSHELL optcaret cmd { $$ = mk(nSubshell,$3); } | FN words brace { $$ = mk(nNewfn,$2,$3); } - | FN words { $$ = mk(nRmfn,$2); } + | FN words %prec ELSE { $$ = mk(nRmfn,$2); } optcaret : /* empty */ %prec '^' | '^' -simple : first - | first args { $$ = ($2 != NULL ? mk(nArgs,$1,$2) : $1); } +simple : first %prec ELSE + | first args %prec ELSE { $$ = ($2 != NULL ? mk(nArgs,$1,$2) : $1); } args : arg | args arg { $$ = ($2 != NULL ? mk(nArgs,$1,$2) : $1); }