]> ocean-lang.org Git - ocean/commitdiff
indent_test: adjust grammer to handle blank lines better.
authorNeilBrown <neil@brown.name>
Sat, 15 Jun 2019 23:47:58 +0000 (09:47 +1000)
committerNeilBrown <neil@brown.name>
Sat, 15 Jun 2019 23:47:58 +0000 (09:47 +1000)
This uses the new $$NEWLINE are other techniques to ensure
blank lines are handled well.
We also test that adding blank lines everywhere doesn't break
anything.

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

index 983d223dd6135f08b8e6fa3eb336a0ab7e2a3062..6ba2479e58ecbd449811c6a355295cb4b7b629a8 100644 (file)
@@ -21,6 +21,9 @@ with complete bracketing and indenting.
        checkitest: itest itest.code
                @grep -v '^#' itest.out > .tmp.out
                @./itest itest.code | diff -u - .tmp.out || echo itest FAILED
+               @sed -e 'i\
+               ' itest.code > itest2.code
+               @./itest itest2.code| diff -u - .tmp.out || echo itest2 FAILED
        demos :: doitest
        tests :: checkitest
 
@@ -134,11 +137,9 @@ with complete bracketing and indenting.
 
 Program -> Statementlist ${ print_statement($1, 0); }$
 
-OptNL -> NEWLINE
-       |
-
 $*statement
        Statementlist ->  Statements ${ $0 = $<1; }$
+               | NEWLINE Statementlist ${ $0 = $<2; }$
 
        Statements -> Statements Statement ${
                                {
@@ -154,12 +155,14 @@ $*statement
                        | ERROR ${ printf("statement ERROR\n"); $0 = NULL; }$
 
        Open -> {
-               | NEWLINE {
+               | NEWLINE Open
        Close -> }
-               | NEWLINE }
+               | NEWLINE Close
        Block -> Open Statementlist Close ${ $0 = $<2; }$
                | Open SimpleStatements } ${ $0 = $<2; }$
-               | : Statementlist ${ $0 = $<2; }$
+               | : SimpleStatements $$NEWLINE ${ $0 = $<2; }$
+               | : StatementBlock ${ $0 = $<2; }$
+       StatementBlock -> Statementlist $$NEWLINE ${ $0 = $<1; }$
 
        SimpleStatements -> SimpleStatements ; SimpleStatement ${
                        {
@@ -181,42 +184,33 @@ $*statement
                        $0->expr->op = $2.txt;
                        $0->expr->right = $<3;
                        }$
-       Statement -> SimpleStatements NEWLINE ${
-                       $0 = $<1;
-                       }$
+       SSline -> SimpleStatements NEWLINE ${ $0 = $<1; }$
+               | SSline NEWLINE ${ $0 = $<1; }$
+       Statement -> SSline ${ $0 = $<1; }$
                | IfStatement ${ $0 = $<1; }$
-               | Statement NEWLINE ${ $0 = $<1; }$
 
        $RIGHT else
 
-       IfStatement -> if Expression Block OptNL $$else ${
-                               $0 = calloc(1, sizeof(struct statement));
-                               $0->expr = $<2;
-                               $0->thenpart = $<3;
-                               }$
-               | if Expression : SimpleStatements $$else ${
-                               $0 = calloc(1, sizeof(struct statement));
-                               $0->expr = $<2;
-                               $0->thenpart = $<4;
-                               }$
-               | if Expression Block OptNL else Block ${
-                               $0 = calloc(1, sizeof(struct statement));
-                               $0->expr = $<2;
-                               $0->thenpart = $<3;
-                               $0->elsepart = $<6;
-                               }$
-               | if Expression Block OptNL else : SimpleStatements ${
-                               $0 = calloc(1, sizeof(struct statement));
-                               $0->expr = $<2;
-                               $0->thenpart = $<3;
-                               $0->elsepart = $<7;
-                               }$
-               | if Expression Block OptNL else IfStatement ${
+       IfHead -> if Expression Block ${
                                $0 = calloc(1, sizeof(struct statement));
                                $0->expr = $<2;
                                $0->thenpart = $<3;
-                               $0->elsepart = $<6;
                                }$
+               | IfHead NEWLINE ${ $0 = $<1; }$
+       IfTail -> else Block ${ $0 = $<2; }$
+               | IfTail NEWLINE ${ $0 = $<1; }$
+
+       IfStatement -> IfHead $$else ${ $0 = $<1; }$
+               | IfHead IfTail ${
+                       $0 = $<1;
+                       $0->elsepart = $<2;
+                       }$
+               | IfHead else IfStatement ${
+                       $0 = $<1;
+                       $0->elsepart = $<3;
+                       }$
+               | IfStatement NEWLINE ${ $0 = $<1; }$
+
 
 $*expression
        Expression -> Expression + Term ${