Changed the occam and Rain parsers to return a Structured rather than a Process (which will simplify the generated ASTs)

This commit is contained in:
Neil Brown 2007-10-17 13:21:17 +00:00
parent a25824b601
commit 1c858e112c
2 changed files with 16 additions and 9 deletions

View File

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

View File

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