summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert Münnich <ber.t@posteo.de>2018-03-02 21:04:06 +0100
committerBert Münnich <ber.t@posteo.de>2018-03-02 21:15:46 +0100
commit280d57b40b71c16b242dab52286592efdf2e3356 (patch)
tree60225a8580720fb426eed0de7614367f3a6e80fe
parent67a87ad0104d88e8b1711a3831d616598edb30c2 (diff)
Unify bodies of if and if-else statements
Fixes issue #31 of rakitzis/rc.
-rw-r--r--parse.y17
1 files changed, 10 insertions, 7 deletions
diff --git a/parse.y b/parse.y
index 276961a..55f7e80 100644
--- 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); }