From: NeilBrown Date: Fri, 3 Oct 2014 03:29:14 +0000 (+1000) Subject: indent test: various fixed to match new design. X-Git-Tag: workingparser~6 X-Git-Url: https://ocean-lang.org/code/?p=ocean;a=commitdiff_plain;h=50d88f0943635d7467dc8bdb951bade69920c8da indent test: various fixed to match new design. Signed-off-by: NeilBrown --- diff --git a/csrc/indent_test.cgm b/csrc/indent_test.cgm index d5c3156..974c167 100644 --- a/csrc/indent_test.cgm +++ b/csrc/indent_test.cgm @@ -117,12 +117,8 @@ Program -> Statementlist ${ print_statement($1, 0); }$ OptNL -> NEWLINE | -Newlines -> NEWLINE - | NEWLINE Newlines - $*statement - Statementlist -> SimpleStatements ${ $0 = $<1; }$ - | Statements ${ $0 = $<1; }$ + Statementlist -> Statements ${ $0 = $<1; }$ Statements -> Statements Statement ${ { @@ -134,10 +130,15 @@ $*statement *s = $<2; } }$ - | ${ $0 = NULL; }$ + | Statement ${ $0 = $<1; }$ | ERROR ${ printf("statement ERROR\n"); $0 = NULL; }$ - Block -> OptNL { Statementlist OptNL } ${ $0 = $<3; }$ + Open -> { + | NEWLINE { + Close -> } + | NEWLINE } + Block -> Open Statementlist Close ${ $0 = $<2; }$ + | Open SimpleStatements } ${ $0 = $<2; }$ | : Statementlist ${ $0 = $2; $2 = NULL; }$ SimpleStatements -> SimpleStatements ; SimpleStatement ${ @@ -151,6 +152,7 @@ $*statement } }$ | SimpleStatement ${ $0 = $<1; }$ + | SimpleStatements ; ${ $0 = $<1; }$ SimpleStatement -> Factor = Expression ${ $0 = calloc(1, sizeof(struct statement)); @@ -159,31 +161,35 @@ $*statement $0->expr->op = $2.txt; $0->expr->right = $<3; }$ - Statement -> SimpleStatements Newlines ${ - $0 = $<1; - }$ - | SimpleStatements ; Newlines ${ + Statement -> SimpleStatements NEWLINE ${ $0 = $<1; }$ | IfStatement ${ $0 = $<1; }$ + | Statement NEWLINE ${ $0 = $<1; }$ - IfStatement -> if Expression Block ${ + IfStatement -> if Expression Block OptNL ${ $0 = calloc(1, sizeof(struct statement)); $0->expr = $<2; $0->thenpart = $<3; }$ - | if Expression SimpleStatement ${ + | if Expression : SimpleStatements ${ $0 = calloc(1, sizeof(struct statement)); $0->expr = $<2; - $0->thenpart = $<3; + $0->thenpart = $<4; }$ - | if Expression Block Newlines else Block ${ + | if Expression Block OptNL else Block ${ $0 = calloc(1, sizeof(struct statement)); $0->expr = $<2; $0->thenpart = $<3; $0->elsepart = $<6; }$ - | if Expression Block Newlines else IfStatement ${ + | 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 ${ $0 = calloc(1, sizeof(struct statement)); $0->expr = $<2; $0->thenpart = $<3; diff --git a/csrc/itest.code b/csrc/itest.code index 9ce8305..86b71a4 100644 --- a/csrc/itest.code +++ b/csrc/itest.code @@ -16,11 +16,23 @@ x + y / two; - else if cond2: + else if cond2: there1 =x there1a=x there2=x there3=x; all = y; - if true {yes=x;} else no=x; + 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