]> ocean-lang.org Git - ocean/blobdiff - csrc/indent_test.mdc
oceani: simplify test in var_block_close.
[ocean] / csrc / indent_test.mdc
index fddb64b7520a15931b430075406c2853f056fef3..5fbd8eb414c18a2375ce184af3263d09c95838a0 100644 (file)
@@ -10,7 +10,7 @@ with complete bracketing and indenting.
        all :: itest
        itest.c itest.h : indent_test.mdc parsergen
                ./parsergen -o itest --LALR --tag indent indent_test.mdc
-       indent_test.mk: indent_test.mdc md2c
+       indent_test.mk itest.code: indent_test.mdc md2c
                ./md2c indent_test.mdc
        itest: itest.c | $(filter %.o,$(itestLDLIBS))
                $(CC) $(itestCFLAGS) $^ $(itestLDLIBS) -o $@
@@ -19,19 +19,15 @@ with complete bracketing and indenting.
                ./itest itest.code
        checkitest: itest itest.code
                @grep -v '^#' itest.out > .tmp.out
-               @./itest itest.code | diff -u - .tmp.out || echo itest FAILED
+               @./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
+               @./itest itest2.code| diff -u .tmp.out - || echo itest2 FAILED
        demos :: doitest
        tests :: checkitest
 
 # indent: header
 
- ./parsergen -o itest --LALR indent_test.cgm
- cc -o itest itest.c lib*.o -licuuc -lgmp
- ./itest itest.code
-
        struct expression {
                struct text op;
                struct expression *left, *right;
@@ -134,36 +130,33 @@ with complete bracketing and indenting.
 
 $TERM if { } : * + - / ; =
 
-Program -> Statementlist ${ print_statement($1, 0); }$
+Program -> OptNL Statementlist ${ print_statement($S, 0); }$
+
+OptNL ->
+       | OptNL NEWLINE
+Newlines -> NEWLINE
+       | Newlines NEWLINE
 
 $*statement
-       Newlines -> NEWLINE
-               | Newlines NEWLINE
-       Statementlist ->  Statements ${ $0 = $<S; }$
-               | Newlines Statements ${ $0 = $<S1; }$
-
-       Statements -> Statements Statement ${
-                               {
-                                       struct statement **s;
-                                       $0 = $<1;
-                                       s = &$0;
-                                       while (*s)
-                                               s = &(*s)->next;
-                                       *s = $<2;
-                               }
-                               }$
-                       | Statement ${ $0 = $<1; }$
-                       | ERROR ${ printf("statement ERROR\n"); $0 = NULL; }$
-
-       Open -> {
-               | Newlines {
-       Close -> }
-               | Newlines }
-       Block -> Open Statementlist Close ${ $0 = $<S; }$
-               | Open SimpleStatements } ${ $0 = $<S; }$
-               | : SimpleStatements ${ $0 = $<SS; }$
-               | : StatementBlock ${ $0 = $<SB; }$
-       StatementBlock -> Statementlist $$OUT ${ $0 = $<Sl; }$
+
+       Statementlist -> Statementlist Statement ${
+               {
+                       struct statement **s;
+                       $0 = $<1;
+                       s = &$0;
+                       while (*s)
+                               s = &(*s)->next;
+                       *s = $<2;
+               }
+               }$
+               | Statement ${ $0 = $<1; }$
+
+       Block -> { IN OptNL Statementlist OUT OptNL } ${ $0 = $<Stat; }$
+               | { SimpleStatements } ${ $0 = $<S; }$
+               | { SimpleStatements ; } ${ $0 = $<S; }$
+               | : IN OptNL Statementlist OUT ${ $0 = $<Sl; }$
+               | : SimpleStatements EOL ${ $0 = $<Si; }$
+               | : SimpleStatements ; ${ $0 = $<Si; }$
 
        SimpleStatements -> SimpleStatements ; SimpleStatement ${
                        {
@@ -176,7 +169,6 @@ $*statement
                        }
                        }$
                | SimpleStatement ${ $0 = $<1; }$
-               | SimpleStatements ; ${ $0 = $<1; }$
 
        SimpleStatement -> Factor = Expression ${
                        $0 = calloc(1, sizeof(struct statement));
@@ -185,29 +177,45 @@ $*statement
                        $0->expr->op = $2.txt;
                        $0->expr->right = $<3;
                        }$
-       SSline -> SimpleStatements NEWLINE ${ $0 = $<1; }$
-       Statement -> SSline ${ $0 = $<1; }$
-               | IfStatement $$NEWLINE ${ $0 = $<1; }$
-               | Statement NEWLINE ${ $0 = $<1; }$
+       Statement -> SimpleStatements Newlines ${ $0 = $<SS; }$
+               | SimpleStatements ; Newlines ${ $0 = $<SS; }$
+               | IfHead Newlines ${ $0 = $<If; }$
+               | IfHead Newlines IfSuffix ${
+                       $0 = $<IH;
+                       $0->next = $IS->next;
+                       $IS->next = NULL;
+                       $0->elsepart = $<IS;
+               }$
+               | IfHead IfSuffix ${
+                       $0 = $<IH;
+                       $0->next = $IS->next;
+                       $IS->next = NULL;
+                       $0->elsepart = $<IS;
+               }$
+               | ERROR Newlines ${ printf("statement ERROR\n"); $0 = NULL; }$
 
        $RIGHT else
 
        IfHead -> if Expression Block ${
                                $0 = calloc(1, sizeof(struct statement));
-                               $0->expr = $<2;
-                               $0->thenpart = $<3;
+                               $0->expr = $<Ex;
+                               $0->thenpart = $<Bl;
                                }$
-               | IfHead NEWLINE ${ $0 = $<1; }$
 
-       IfStatement -> IfHead $$else ${ $0 = $<1; }$
-               | IfHead else Block ${
-                       $0 = $<1;
-                       $0->elsepart = $<3;
-                       }$
-               | IfHead else IfStatement ${
-                       $0 = $<1;
-                       $0->elsepart = $<3;
-                       }$
+       IfSuffix -> else Block Newlines ${ $0 = $<Bl; }$
+               | else IfHead Newlines ${ $0 = $<IH; }$
+               | else IfHead IfSuffix ${
+                       $0 = $<IH;
+                       $0->elsepart = $IS;
+                       $0->next = $IS->next;
+                       $IS->next = NULL;
+               }$
+               | else IfHead Newlines IfSuffix ${
+                       $0 = $<IH;
+                       $0->elsepart = $IS;
+                       $0->next = $IS->next;
+                       $IS->next = NULL;
+               }$
 
 $*expression
        Expression -> Expression + Term ${
@@ -264,6 +272,21 @@ $*expression
         else if cond2:
                there1 =x
                there1a=x
+       if cond + cond2 :
+               hello = x;
+               hello2 = x;
+
+               sum = val +
+                val;
+
+               if condX:
+                foo = x *
+                    x +
+                    y
+                    / two;
+       else if cond2:
+               there1 =x
+               there1a=x
        there2=x
        there3=x;
        all = y;
@@ -280,6 +303,8 @@ $*expression
        if a:
                if b:
                        c= d
+               else:
+                       f=g
        x = y
 
 # File: itest.out
@@ -287,6 +312,16 @@ $*expression
        (mister=no);
        (there=x);
        (all=y);
+       if (cond+cond2):
+           (hello=x);
+           (hello2=x);
+           (sum=(val+val));
+           if condX:
+               (foo=((x*x)+(y/two)));
+       else:
+           if cond2:
+               (there1=x);
+               (there1a=x);
        if (cond+cond2):
            (hello=x);
            (hello2=x);
@@ -318,4 +353,6 @@ $*expression
        if a:
            if b:
                (c=d);
+           else:
+               (f=g);
        (x=y);