From: NeilBrown Date: Wed, 10 Mar 2021 01:13:05 +0000 (+1100) Subject: Update indent_test grammer to align with new approach X-Git-Url: https://ocean-lang.org/code/?p=ocean;a=commitdiff_plain;h=1b9dd205f5d65b6d89b0e05d51690c8c6cf0f771 Update indent_test grammer to align with new approach Indents are now now handled very differently. Update itest grammar to match. Signed-off-by: NeilBrown --- diff --git a/csrc/indent_test.mdc b/csrc/indent_test.mdc index 463428b..5fbd8eb 100644 --- a/csrc/indent_test.mdc +++ b/csrc/indent_test.mdc @@ -130,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 = $ 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 = $ Statementlist ${ $0 = $ 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 = $ SimpleStatements ; SimpleStatement ${ { @@ -172,7 +169,6 @@ $*statement } }$ | SimpleStatement ${ $0 = $<1; }$ - | SimpleStatements ; ${ $0 = $<1; }$ SimpleStatement -> Factor = Expression ${ $0 = calloc(1, sizeof(struct statement)); @@ -181,29 +177,45 @@ $*statement $0->expr->op = $2.txt; $0->expr->right = $<3; }$ - SSline -> SimpleStatements NEWLINE ${ $0 = $<1; }$ - Statement -> SSline ${ $0 = $<1; }$ - | IfStatement ${ $0 = $<1; }$ - | Statement NEWLINE ${ $0 = $<1; }$ + Statement -> SimpleStatements Newlines ${ $0 = $next = $IS->next; + $IS->next = NULL; + $0->elsepart = $next = $IS->next; + $IS->next = NULL; + $0->elsepart = $ if Expression Block ${ $0 = calloc(1, sizeof(struct statement)); - $0->expr = $<2; - $0->thenpart = $<3; + $0->expr = $thenpart = $ 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 = $elsepart = $IS; + $0->next = $IS->next; + $IS->next = NULL; + }$ + | else IfHead Newlines IfSuffix ${ + $0 = $elsepart = $IS; + $0->next = $IS->next; + $IS->next = NULL; + }$ $*expression Expression -> Expression + Term ${