]> ocean-lang.org Git - ocean/commitdiff
NEWLINE must only ever follow a 'linelike' symbol.
authorNeilBrown <neilb@suse.de>
Thu, 2 Oct 2014 10:47:40 +0000 (20:47 +1000)
committerNeilBrown <neilb@suse.de>
Thu, 2 Oct 2014 10:47:40 +0000 (20:47 +1000)
Signed-off-by: NeilBrown <neil@brown.name>
csrc/indent_test.cgm

index ac3ab55fe49d25b5ffa31778fe87d5c5fe6b444e..e7b176fd0ced16f162faaa05e010b96ccedf01e1 100644 (file)
@@ -116,11 +116,11 @@ Program -> Statementlist ${ print_statement($1, 0); }$
 
 OptNL -> NEWLINE
        |
-OptSemi -> NEWLINE
-       | ;
 
 $*statement
-       Statementlist -> Statements ${ $0 = $<1; }$
+       Statementlist -> SimpleStatements ${ $0 = $<1; }$
+               | Statements ${ $0 = $<1; }$
+
        Statements -> Statements Statement ${
                                {
                                        struct statement **s;
@@ -131,37 +131,57 @@ $*statement
                                        *s = $<2;
                                }
                                }$
-                       | Statements OptSemi ${ $0 = $<1; }$
                        | ${ $0 = NULL; }$
                        | ERROR ${ printf("statement ERROR\n"); $0 = NULL; }$
 
-       Block -> OptNL { Statementlist } OptNL ${ $0 = $<3; }$
+       Block -> OptNL { Statementlist OptNL } ${ $0 = $<3; }$
                | : Statementlist ${ $0 = $2; $2 = NULL; }$
 
-       Statement -> Factor = Expression OptSemi ${
+       SimpleStatements -> SimpleStatements ; SimpleStatement ${
+                       {
+                               struct statement **s;
+                               $0 = $<1;
+                               s = &$0;
+                               while (*s)
+                                       s = &(*s)->next;
+                               *s = $<3;
+                       }
+                       }$
+               | SimpleStatement ${ $0 = $<1; }$
+
+       SimpleStatement -> Factor = Expression ${
                        $0 = calloc(1, sizeof(struct statement));
                        $0->expr = calloc(1, sizeof(struct expression));
                        $0->expr->left = $<1;
                        $0->expr->op = $2.txt;
                        $0->expr->right = $<3;
                        }$
-               | if Expression Block OptNL ${
+       Statement -> SimpleStatements NEWLINE ${
+                       $0 = $<1;
+                       }$
+               | SimpleStatements ; NEWLINE ${
+                       $0 = $<1;
+                       }$
+               | NEWLINE ${ $0 = NULL; }$
+               | IfStatement ${ $0 = $<1; }$
+
+       IfStatement -> if Expression Block ${
                                $0 = calloc(1, sizeof(struct statement));
                                $0->expr = $<2;
                                $0->thenpart = $<3;
                                }$
-               | if Expression Statement ${
+               | if Expression SimpleStatement ${
                                $0 = calloc(1, sizeof(struct statement));
                                $0->expr = $<2;
                                $0->thenpart = $<3;
                                }$
-               | if Expression Block OptNL else Block ${
+               | if Expression Block Newlines else Block ${
                                $0 = calloc(1, sizeof(struct statement));
                                $0->expr = $<2;
                                $0->thenpart = $<3;
                                $0->elsepart = $<6;
                                }$
-               | if Expression Block OptNL else Statement ${
+               | if Expression Block Newlines else IfStatement ${
                                $0 = calloc(1, sizeof(struct statement));
                                $0->expr = $<2;
                                $0->thenpart = $<3;