From 3e2f9d1e4cf6f1f5cb36abb62e7cc73c56172a10 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Tue, 7 Oct 2014 17:06:11 +1100 Subject: [PATCH] oceani: add proper 'then' handling. I hadn't thought about this properly before.. Signed-off-by: NeilBrown --- csrc/oceani.mdc | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/csrc/oceani.mdc b/csrc/oceani.mdc index 8f0ea0e..4e848e4 100644 --- a/csrc/oceani.mdc +++ b/csrc/oceani.mdc @@ -1637,11 +1637,12 @@ defined. ###### Grammar $*cond_statement - CondStatement -> ForPart OptNL WhilePart CondSuffix ${ - $0 = $<4; - $0->forpart = $<1; - $0->condpart = $3.condpart; $3.condpart = NULL; - $0->dopart = $3.dopart; $3.dopart = NULL; + CondStatement -> ForThen WhilePart CondSuffix ${ + $0 = $<3; + $0->forpart = $1.forpart; $1.forpart = NULL; + $0->thenpart = $1.thenpart; $1.thenpart = NULL; + $0->condpart = $2.condpart; $2.condpart = NULL; + $0->dopart = $2.dopart; $2.dopart = NULL; }$ | WhilePart CondSuffix ${ $0 = $<2; @@ -1657,6 +1658,7 @@ defined. $0->condpart = $1.condpart; $1.condpart = NULL; $0->thenpart = $1.thenpart; $1.thenpart = NULL; }$ + CondSuffix -> IfSuffix ${ $0 = $<1; }$ | Newlines case Expression Block CondSuffix ${ { struct casepart *cp = calloc(1, sizeof(*cp)); @@ -1702,11 +1704,30 @@ defined. $0 = $<2; }$ + ThenPart -> then SimpleStatements ${ + $0 = reorder_bilist($<2); + }$ + | then Block ${ + $0 = $<2; + }$ + + ThenPartNL -> ThenPart OptNL ${ + $0 = $<1; + }$ + WhileHead -> while Block ${ $0 = $<2; }$ $cond_statement + ForThen -> ForPart OptNL ThenPartNL ${ + $0.forpart = $<1; + $0.thenpart = $<3; + }$ + | ForPart OptNL ${ + $0.forpart = $<1; + }$ + WhilePart -> while Expression Block ${ $0.type = Xcond_statement; $0.condpart = $<2; @@ -1747,6 +1768,13 @@ defined. do_indent(indent, "for"); if (bracket) printf(" {\n"); else printf(":\n"); print_exec(cs->forpart, indent+1, bracket); + if (cs->thenpart) { + if (bracket) + do_indent(indent, "} then {\n"); + else + do_indent(indent, "then:\n"); + print_exec(cs->thenpart, indent+1, bracket); + } if (bracket) do_indent(indent, "}\n"); } if (cs->dopart) { @@ -1758,15 +1786,6 @@ defined. else do_indent(indent, "while:\n"); print_exec(cs->condpart, indent+1, bracket); - if (cs->thenpart) { - if (bracket) - do_indent(indent, "} then {\n"); - else - do_indent(indent, "then:\n"); - print_exec(cs->thenpart, indent+1, bracket); - if (bracket) - do_indent(indent, "}\n"); - } if (bracket) do_indent(indent, "} do {\n"); else -- 2.43.0