summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--parse.y17
2 files changed, 18 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 5ba1cf3..f759e29 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -903,3 +903,11 @@ Changes since rc-1.5b2
2015-05-13
Release: rc-1.7.4.
+
+[... needs completing]
+
+2018-03-05
+
+ Bug: the grammar disallowed local assignments and redirections in the true
+ branch of `if` when there was an `else` clause (thanks Dražen Borković and
+ Bert Münnich; github #31).
diff --git a/parse.y b/parse.y
index 33d723a..b3f1255 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
@@ -117,13 +120,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); }