From 3f573dabd5955e6cec5de74ad31052f5486e6444 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Fri, 14 Sep 2007 12:53:26 +0000 Subject: [PATCH] Rain: corrected innerBlock to work sensibly with multiple declarations (particularly for the start of par blocks) --- frontends/ParseRain.hs | 8 +++++++- frontends/ParseRainTest.hs | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/frontends/ParseRain.hs b/frontends/ParseRain.hs index ecc8bf7..07d2aa7 100644 --- a/frontends/ParseRain.hs +++ b/frontends/ParseRain.hs @@ -266,7 +266,13 @@ innerBlock declsMustBeFirst = do m <- sLeftC --Returns either a single line (which means the immediate next line is a declaration) or a list of remaining lines linesToEnd :: InnerBlockLineState -> RainParser (Either A.Structured [A.Structured]) linesToEnd state - = (if state /= NoMoreDecls then do {(m,decl) <- declaration ; rest <- linesToEnd state ; return $ Left $ decl $ A.Several m (makeList rest)} else pzero) + = (if state /= NoMoreDecls then + do (m,decl) <- declaration + rest <- linesToEnd state + case rest of + Left s -> return $ Left $ decl s + Right ss -> return $ Left $ decl $ A.Several m ss + else pzero) <|> do {st <- statement ; rest <- linesToEnd nextState ; return $ Right $ (wrapProc st) : (makeList rest)} --Although return is technically a statement, we parse it here because it can only occur inside a block, --and we don't want to wrap it in an A.OnlyP: diff --git a/frontends/ParseRainTest.hs b/frontends/ParseRainTest.hs index 50a40cc..975c033 100644 --- a/frontends/ParseRainTest.hs +++ b/frontends/ParseRainTest.hs @@ -345,6 +345,13 @@ testPar = assertEqual "Par Decl Test 0" $ A.Par m A.PlainPar $ A.Spec m (A.Specification m (simpleName "x") $ A.Declaration m A.Int) $ A.Several m [A.OnlyP m $ A.Seq m $ A.Several m []] ) + + ,pass ("par {uint16:x; uint32:y; {} }",RP.statement, + assertEqual "Par Decl Test 1" $ A.Par m A.PlainPar $ + A.Spec m (A.Specification m (simpleName "x") $ A.Declaration m A.UInt16) $ + A.Spec m (A.Specification m (simpleName "y") $ A.Declaration m A.UInt32) $ + A.Several m [A.OnlyP m $ A.Seq m $ A.Several m []] ) + ,fail ("par { {} int: x; }",RP.statement) ]