]> ocean-lang.org Git - ocean/blobdiff - csrc/indent_test.mdc
ident_test: declare precedence for 'else'
[ocean] / csrc / indent_test.mdc
index 792e152523055781b282ac2d261fcae324f0fc79..983d223dd6135f08b8e6fa3eb336a0ab7e2a3062 100644 (file)
@@ -6,7 +6,8 @@ with complete bracketing and indenting.
 # File: indent_test.mk
        myCFLAGS := -Wall -g -fplan9-extensions
        CFLAGS := $(filter-out $(myCFLAGS),$(CFLAGS)) $(myCFLAGS)
-       LDLIBS:= libparser.o libscanner.o libmdcode.o -licuuc
+       myLDLIBS:= libparser.o libscanner.o libmdcode.o -licuuc
+       LDLIBS := $(filter-out $(myLDLIBS),$(LDLIBS)) $(myLDLIBS)
 
        all :: itest
        itest.c itest.h : indent_test.mdc parsergen libparser.o libscanner.o libmdcode.o
@@ -15,8 +16,13 @@ with complete bracketing and indenting.
                ./md2c indent_test.mdc
        itest: itest.c
 
-       tests:: itest itest.code
+       doitest: itest itest.code
                ./itest itest.code
+       checkitest: itest itest.code
+               @grep -v '^#' itest.out > .tmp.out
+               @./itest itest.code | diff -u - .tmp.out || echo itest FAILED
+       demos :: doitest
+       tests :: checkitest
 
 # indent: header
 
@@ -122,7 +128,6 @@ with complete bracketing and indenting.
                exit(0);
        }
 
-
 # indent: grammar
 
 ~~~~~~
@@ -154,7 +159,7 @@ $*statement
                | NEWLINE }
        Block -> Open Statementlist Close ${ $0 = $<2; }$
                | Open SimpleStatements } ${ $0 = $<2; }$
-               | : Statementlist ${ $0 = $2; $2 = NULL; }$
+               | : Statementlist ${ $0 = $<2; }$
 
        SimpleStatements -> SimpleStatements ; SimpleStatement ${
                        {
@@ -182,12 +187,14 @@ $*statement
                | IfStatement ${ $0 = $<1; }$
                | Statement NEWLINE ${ $0 = $<1; }$
 
-       IfStatement -> if Expression Block OptNL ${
+       $RIGHT else
+
+       IfStatement -> if Expression Block OptNL $$else ${
                                $0 = calloc(1, sizeof(struct statement));
                                $0->expr = $<2;
                                $0->thenpart = $<3;
                                }$
-               | if Expression : SimpleStatements ${
+               | if Expression : SimpleStatements $$else ${
                                $0 = calloc(1, sizeof(struct statement));
                                $0->expr = $<2;
                                $0->thenpart = $<4;
@@ -224,7 +231,7 @@ $*expression
                                $0->left = $<1;
                                $0->right = $<3;
                        }$
-                   | Term ${ $0 = $1; $1 = NULL; }$
+                   | Term ${ $0 = $<1; }$
        Term -> Term * Factor ${
                                $0 = calloc(1, sizeof(struct expression));
                                $0->op = $2.txt;
@@ -237,7 +244,7 @@ $*expression
                                $0->left = $<1;
                                $0->right = $<3;
                        }$
-             | Factor ${ $0 = $1; $1 = NULL; }$
+             | Factor ${ $0 = $<1; }$
        Factor -> IDENTIFIER ${
                                $0 = calloc(1, sizeof(struct expression));
                                $0->op = $1.txt;
@@ -283,3 +290,36 @@ $*expression
                        c= d
        x = y
 
+# File: itest.out
+       (hello=yes);
+       (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);
+       (there2=x);
+       (there3=x);
+       (all=y);
+       if true:
+           (yes=x);
+       else:
+           (no=x);
+       if true:
+           (yes=no);
+           (no=yes);
+       if false:
+           (print=OK);
+       else:
+           (print=not_OK);
+       if a:
+           if b:
+               (c=d);
+       (x=y);