From 6a546ea265d0ee30152298463e9e7b7c2f53b3b0 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sun, 7 Nov 2021 10:00:29 +1100 Subject: [PATCH] oceani: fix up the while/do scope The scope created for while/do does NOT extend into the case/else part. This is because it is a repeating scope and needs to close and re-open. We *could* include case/else in the final instance of that scope, but I'm not at all sure that I want to. Maybe later. So close the scope properly and fix up the test code which depends on the scope being extended. Signed-off-by: NeilBrown --- csrc/oceani-tests.mdc | 3 ++- csrc/oceani.mdc | 16 +++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/csrc/oceani-tests.mdc b/csrc/oceani-tests.mdc index 973331f..2433cce 100644 --- a/csrc/oceani-tests.mdc +++ b/csrc/oceani-tests.mdc @@ -365,13 +365,14 @@ Here I break it into two parts, keeping the array code separate. else hi = mid if hi - lo < 1: + lo = mid use GiveUp use True do pass case Found: print "Yay, I found", target case GiveUp: - print "Closest I found was", mid + print "Closest I found was", lo ###### output: sayhello,55,33,hello,True Hello World, what lovely oceans you have! diff --git a/csrc/oceani.mdc b/csrc/oceani.mdc index 364ee29..2a40ff2 100644 --- a/csrc/oceani.mdc +++ b/csrc/oceani.mdc @@ -3873,12 +3873,14 @@ defined. $0->condpart = $next = $0->casepart; $0->casepart = $condpart = $next = $0->casepart; $0->casepart = $ IfSuffix ${ $0 = $<1; - // This is where we close scope of the whole - // "for" or "while" statement - var_block_close(c, CloseSequential); }$ | Newlines CasePart CondSuffix ${ $0 = $ for OpenBlock ${ $0 = $ while UseBlock OptNL do Block ${ $0.condpart = $ if UseBlock OptNL then OpenBlock ClosePara ${ @@ -3964,7 +3965,7 @@ defined. }$ $*exec - // This scope is closed in CondSuffix + // This scope is closed in CondStatement SwitchPart -> switch OpenScope Expression ${ $0 = $