rc

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

commit ceb59bb2a644f4ebc1645fe15f1063029579fa7c
parent 3f4dfc08e2ca5dc37260dee2bc7d1fb6c5f9ff96
Author: Toby Goodwin <toby@nqmail.org>
Date:   Sun, 19 Aug 2018 22:46:08 +0100

do not permit "if not" after "if ... else"

Diffstat:
Mtree.c | 12++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/tree.c b/tree.c @@ -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;