diff --git a/RainParse.hs b/RainParse.hs index 3b266ea..d0c4c14 100644 --- a/RainParse.hs +++ b/RainParse.hs @@ -303,11 +303,19 @@ declaration :: RainParser (Meta,A.Structured -> A.Structured) declaration = try $ do {t <- dataType; sColon ; n <- name ; sSemiColon ; return (findMeta t, A.Spec (findMeta t) $ A.Specification (findMeta t) n $ A.Declaration (findMeta t) t) } -topLevelDecl :: RainParser A.Structured -topLevelDecl = do {m <- sProcess ; procName <- name ; params <- tupleDef ; body <- block ; +terminator :: A.Structured +terminator = (A.OnlyP emptyMeta $ A.Main emptyMeta) + +processDecl :: RainParser A.Structured +processDecl = do {m <- sProcess ; procName <- name ; params <- tupleDef ; body <- block ; return $ A.Spec m (A.Specification m procName (A.Proc m A.PlainSpec (formaliseTuple params) body)) - (A.OnlyP m $ A.Main m)} + terminator} + +topLevelDecl :: RainParser A.Structured +topLevelDecl = do decls <- many processDecl + eof + return $ A.Several emptyMeta decls rainSourceFile :: RainParser (A.Process, CompState) rainSourceFile diff --git a/RainParseTest.hs b/RainParseTest.hs index 15898cd..a957021 100644 --- a/RainParseTest.hs +++ b/RainParseTest.hs @@ -342,18 +342,30 @@ testTopLevelDecl :: [ParseTest A.Structured] testTopLevelDecl = [ pass ("process noargs() {}", RP.topLevelDecl, - assertPatternMatch "testTopLevelDecl 0" $ tag3 A.Spec DontCare + assertPatternMatch "testTopLevelDecl 0" $ tag2 A.Several DontCare [tag3 A.Spec DontCare (tag3 A.Specification DontCare (simpleNamePattern "noargs") $ tag4 A.Proc DontCare A.PlainSpec ([] :: [A.Formal]) (tag2 A.Seq DontCare $ tag2 A.Several DontCare ([] :: [A.Structured])) ) - (tag2 A.OnlyP DontCare $ tag1 A.Main DontCare) + (tag2 A.OnlyP DontCare $ tag1 A.Main DontCare)] ) , pass ("process onearg(int: x) {x = 0;}", RP.topLevelDecl, - assertPatternMatch "testTopLevelDecl 1" $ tag3 A.Spec DontCare + assertPatternMatch "testTopLevelDecl 1" $ tag2 A.Several DontCare [tag3 A.Spec DontCare (tag3 A.Specification DontCare (simpleNamePattern "onearg") $ tag4 A.Proc DontCare A.PlainSpec [tag3 A.Formal A.ValAbbrev A.Int (simpleNamePattern "x")] (tag2 A.Seq DontCare $ tag2 A.Several DontCare [tag2 A.OnlyP DontCare $ makeAssignPattern (variablePattern "x") (intLiteralPattern 0)]) ) - (tag2 A.OnlyP DontCare $ tag1 A.Main DontCare) + (tag2 A.OnlyP DontCare $ tag1 A.Main DontCare)] ) + ,pass ("process noargs0() {} process noargs1 () {}", RP.topLevelDecl, + assertPatternMatch "testTopLevelDecl 2" $ tag2 A.Several DontCare [ + tag3 A.Spec DontCare + (tag3 A.Specification DontCare (simpleNamePattern "noargs0") $ tag4 A.Proc DontCare A.PlainSpec ([] :: [A.Formal]) + (tag2 A.Seq DontCare $ tag2 A.Several DontCare ([] :: [A.Structured])) + ) (tag2 A.OnlyP DontCare $ tag1 A.Main DontCare) + ,tag3 A.Spec DontCare + (tag3 A.Specification DontCare (simpleNamePattern "noargs1") $ tag4 A.Proc DontCare A.PlainSpec ([] :: [A.Formal]) + (tag2 A.Seq DontCare $ tag2 A.Several DontCare ([] :: [A.Structured])) + ) (tag2 A.OnlyP DontCare $ tag1 A.Main DontCare) + ] + ) , fail ("process", RP.topLevelDecl) , fail ("process () {}", RP.topLevelDecl) , fail ("process foo", RP.topLevelDecl)