diff options
| author | Toby Goodwin <toby@nqmail.org> | 2018-08-19 22:46:08 +0100 |
|---|---|---|
| committer | Toby Goodwin <toby@nqmail.org> | 2018-08-19 22:46:08 +0100 |
| commit | ceb59bb2a644f4ebc1645fe15f1063029579fa7c (patch) | |
| tree | 111d8d551e3f64637c4360485cf04d4e808203e5 | |
| parent | 3f4dfc08e2ca5dc37260dee2bc7d1fb6c5f9ff96 (diff) | |
do not permit "if not" after "if ... else"
| -rw-r--r-- | tree.c | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -2,11 +2,14 @@ #include "rc.h" +#include "develop.h" + /* convert if followed by ifnot to else */ static Node *desugar_ifnot(Node *n) { if (n->type == nBody && n->u[1].p && n->u[1].p->type == nIfnot) { /* (body (if c x) (if-not y)) => (body (if c (else x y))) */ - if (n->u[0].p->type == nIf) { + if (n->u[0].p->type == nIf && + n->u[0].p->u[1].p->type != nElse) { Node *yes = n->u[0].p; Node *no = n->u[1].p; Node *els = nalloc(offsetof(Node, u[2])); @@ -22,7 +25,8 @@ static Node *desugar_ifnot(Node *n) { n->u[1].p->u[0].p->type == nIfnot) { /* (body (if c x) (body (if-not y) z)) => (body (if c (else x y)) z) */ - if (n->u[0].p->type == nIf) { + if (n->u[0].p->type == nIf && + n->u[0].p->u[1].p->type != nElse) { Node *yes = n->u[0].p; Node *no = n->u[1].p->u[0].p; Node *els = nalloc(offsetof(Node, u[2])); @@ -99,6 +103,10 @@ extern Node *mk(enum nodetype t,...) { } n->type = t; + if (0 && RC_DEVELOP) { + tree_dump(n); + fprint(2, "---\n"); + } n = desugar_ifnot(n); va_end(ap); return n; |