From 43c3ae4aa7de02a944cc576247a7e209fbee7f0c Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Mon, 20 Aug 2007 22:08:24 +0000 Subject: [PATCH] Rain: added the parsing of top-level declarations (and tuple definitions) --- RainParse.hs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/RainParse.hs b/RainParse.hs index 0351f7f..395d264 100644 --- a/RainParse.hs +++ b/RainParse.hs @@ -133,6 +133,7 @@ sRightC = try $ symbol "}" sEquality = try $ symbol "==" sSemiColon = try $ symbol ";" sColon = try $ symbol ":" +sComma = try $ symbol "," sQuote = try $ symbol "\"" --}}} @@ -273,8 +274,20 @@ statement <|> do { m <- md ; sSemiColon ; return $ A.Skip m} "statement" +formaliseTuple :: [(A.Name,A.Type)] -> [A.Formal] +formaliseTuple = map (\(n,t) -> A.Formal A.ValAbbrev t n) + +tupleDef :: RainParser [(A.Name,A.Type)] +tupleDef = do {sLeftR ; tm <- sepBy tupleDefMember sComma ; sRightR ; return tm} + where + tupleDefMember :: RainParser (A.Name,A.Type) + tupleDefMember = do {t <- dataType ; sColon ; n <- name ; return (n,t)} + topLevelDecl :: RainParser A.Structured -topLevelDecl = return $ A.Several emptyMeta [] --Dummy value, for now +topLevelDecl = do {m <- md; sProcess ; procName <- name ; params <- tupleDef ; bm <- md ; body <- block ; + return $ A.Spec m + (A.Specification m procName (A.Proc m A.PlainSpec (formaliseTuple params) body)) + (A.OnlyP m $ A.Main m)} rainSourceFile :: RainParser (A.Process, CompState) rainSourceFile