Rain: corrected innerBlock to work sensibly with multiple declarations (particularly for the start of par blocks)

This commit is contained in:
Neil Brown 2007-09-14 12:53:26 +00:00
parent ff9b0d6611
commit 3f573dabd5
2 changed files with 14 additions and 1 deletions

View File

@ -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:

View File

@ -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)
]