diff --git a/frontends/ParseOccam.hs b/frontends/ParseOccam.hs index a300ee3..b2425b8 100644 --- a/frontends/ParseOccam.hs +++ b/frontends/ParseOccam.hs @@ -1951,13 +1951,20 @@ mainProcess --}}} --}}} --{{{ top-level forms --- | A source file consists of a process. --- This is only really true once we've tacked a process onto the bottom; a --- source file is really a series of specifications, but the later ones need to + +topLevelItem :: OccParser A.Structured +topLevelItem = handleSpecs (allocation <|> specification) topLevelItem + (\m s inner -> A.Spec m s inner) + <|> (mainProcess >>= (\(A.Main m) -> return $ A.Several m [])) + + +-- | A source file consists of a structured. +-- A source file is really a series of specifications, but the later ones need to -- have the earlier ones in scope, so we can't parse them separately. -sourceFile :: OccParser (A.Process, CompState) +-- Instead, we nest the specifications +sourceFile :: OccParser (A.Structured, CompState) sourceFile - = do p <- process + = do p <- topLevelItem s <- getState return (p, s) --}}} @@ -1972,7 +1979,7 @@ runTockParser toks prod cs Right r -> return r -- | Parse an occam program. -parseOccamProgram :: [Token] -> PassM A.Process +parseOccamProgram :: [Token] -> PassM A.Structured parseOccamProgram toks = do cs <- get (p, cs') <- runTockParser toks sourceFile cs diff --git a/frontends/ParseRain.hs b/frontends/ParseRain.hs index f35eeb7..e7a906e 100644 --- a/frontends/ParseRain.hs +++ b/frontends/ParseRain.hs @@ -416,14 +416,14 @@ topLevelDecl = do decls <- many (processDecl <|> functionDecl "process or fu eof return $ A.Several emptyMeta decls -rainSourceFile :: RainParser (A.Process, CompState) +rainSourceFile :: RainParser (A.Structured, CompState) rainSourceFile = do p <- topLevelDecl s <- getState - return (A.Seq emptyMeta p, s) + return (p, s) -- | Load and parse a Rain source file. -parseRainProgram :: String -> PassM A.Process +parseRainProgram :: String -> PassM A.Structured parseRainProgram filename = do source <- liftIO $ readFile filename lexOut <- liftIO $ L.runLexer filename source