From: NeilBrown Date: Sat, 15 Jun 2019 23:47:58 +0000 (+1000) Subject: indent_test: adjust grammer to handle blank lines better. X-Git-Url: https://ocean-lang.org/code/?p=ocean;a=commitdiff_plain;h=71eaad4b0515c97316a320d38e54d9e9a8f25b50 indent_test: adjust grammer to handle blank lines better. 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 --- diff --git a/csrc/indent_test.mdc b/csrc/indent_test.mdc index 983d223..6ba2479 100644 --- a/csrc/indent_test.mdc +++ b/csrc/indent_test.mdc @@ -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 ${