X-Git-Url: https://ocean-lang.org/code/?p=ocean;a=blobdiff_plain;f=csrc%2Findent_test.mdc;h=88e93914aa6f88a7b49638e230c3d99e372019eb;hp=540ecd22584868f832ac6b505b48b8088464ed0d;hb=ca00beb39b9d02578c1f0b556a2c2f70f28cf6e7;hpb=f8c00ecff941f5f86b4d54dd73cac3680684a11e diff --git a/csrc/indent_test.mdc b/csrc/indent_test.mdc index 540ecd2..88e9391 100644 --- a/csrc/indent_test.mdc +++ b/csrc/indent_test.mdc @@ -16,8 +16,16 @@ with complete bracketing and indenting. ./md2c indent_test.mdc itest: itest.c - demos:: 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 + @sed -e 'i\ + ' itest.code > itest2.code + @./itest itest2.code| diff -u - .tmp.out || echo itest2 FAILED + demos :: doitest + tests :: checkitest # indent: header @@ -129,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 ${ { @@ -149,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 $$OUT ${ $0 = $<1; }$ SimpleStatements -> SimpleStatements ; SimpleStatement ${ { @@ -176,40 +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; }$ - IfStatement -> if Expression Block OptNL ${ - $0 = calloc(1, sizeof(struct statement)); - $0->expr = $<2; - $0->thenpart = $<3; - }$ - | if Expression : SimpleStatements ${ - $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 ${ + $RIGHT else + + 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 ${ @@ -283,3 +284,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);