]> ocean-lang.org Git - ocean/commitdiff
oceani: add proper 'then' handling.
authorNeilBrown <neil@brown.name>
Tue, 7 Oct 2014 06:06:11 +0000 (17:06 +1100)
committerNeilBrown <neil@brown.name>
Tue, 7 Oct 2014 06:08:05 +0000 (17:08 +1100)
I hadn't thought about this properly before..

Signed-off-by: NeilBrown <neil@brown.name>
csrc/oceani.mdc

index 8f0ea0e322ec2885158938f8a5846c337a3036a5..4e848e4912f5f8176b83a41e456c2a1111903f3c 100644 (file)
@@ -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