Some minor cleanups to ParseOccam.

This commit is contained in:
Adam Sampson 2008-03-15 14:10:51 +00:00
parent 54668d3ba2
commit 79a5799b8f

View File

@ -90,7 +90,9 @@ plainToken t = genToken test
test (_, t') = if t == t' then Just () else Nothing test (_, t') = if t == t' then Just () else Nothing
--}}} --}}}
--{{{ symbols --{{{ symbols
sAmp, sAssign, sBang, sColon, sColons, sComma, sEq, sLeft, sLeftR, sQuest, sRight, sRightR, sSemi :: OccParser () sAmp, sAssign, sBang, sColon, sColons, sComma, sEq, sLeft, sLeftR, sQuest,
sRight, sRightR, sSemi
:: OccParser ()
sAmp = reserved "&" sAmp = reserved "&"
sAssign = reserved ":=" sAssign = reserved ":="
@ -107,12 +109,13 @@ sRightR = reserved ")"
sSemi = reserved ";" sSemi = reserved ";"
--}}} --}}}
--{{{ keywords --{{{ keywords
sAFTER, sALT, sAND, sANY, sAT, sBITAND, sBITNOT, sBITOR, sBOOL, sBYTE, sBYTESIN, sCASE, sCHAN, sDATA, sAFTER, sALT, sAND, sANY, sAT, sBITAND, sBITNOT, sBITOR, sBOOL, sBYTE,
sELSE, sFALSE, sFOR, sFROM, sFUNCTION, sIF, sINLINE, sIN, sINT, sINT16, sINT32, sINT64, sIS, sBYTESIN, sCASE, sCHAN, sDATA, sELSE, sFALSE, sFOR, sFROM, sFUNCTION, sIF,
sMINUS, sMOSTNEG, sMOSTPOS, sNOT, sOF, sOFFSETOF, sOR, sPACKED, sPAR, sPLACE, sPLACED, sPLUS, sINLINE, sIN, sINT, sINT16, sINT32, sINT64, sIS, sMINUS, sMOSTNEG, sMOSTPOS,
sPORT, sPRI, sPROC, sPROCESSOR, sPROTOCOL, sREAL32, sREAL64, sRECORD, sREM, sRESHAPES, sRESULT, sNOT, sOF, sOFFSETOF, sOR, sPACKED, sPAR, sPLACE, sPLACED, sPLUS, sPORT,
sRETYPES, sROUND, sSEQ, sSIZE, sSKIP, sSTOP, sTIMER, sTIMES, sTRUE, sTRUNC, sTYPE, sVAL, sVALOF, sPRI, sPROC, sPROCESSOR, sPROTOCOL, sREAL32, sREAL64, sRECORD, sREM,
sWHILE, sWORKSPACE, sVECSPACE sRESHAPES, sRESULT, sRETYPES, sROUND, sSEQ, sSIZE, sSKIP, sSTOP, sTIMER,
sTIMES, sTRUE, sTRUNC, sTYPE, sVAL, sVALOF, sWHILE, sWORKSPACE, sVECSPACE
:: OccParser () :: OccParser ()
sAFTER = reserved "AFTER" sAFTER = reserved "AFTER"
@ -467,7 +470,6 @@ scopeOut n@(A.Name m nt s)
otherwise -> dieInternal (Just m, "scopeOut trying to scope out the wrong name") otherwise -> dieInternal (Just m, "scopeOut trying to scope out the wrong name")
put $ st { csLocalNames = lns' } put $ st { csLocalNames = lns' }
-- FIXME: Do these with generics? (going carefully to avoid nested code blocks)
scopeInRep :: A.Replicator -> OccParser A.Replicator scopeInRep :: A.Replicator -> OccParser A.Replicator
scopeInRep (A.For m n b c) scopeInRep (A.For m n b c)
= do n' <- scopeIn n (A.Declaration m A.Int) A.ValAbbrev = do n' <- scopeIn n (A.Declaration m A.Int) A.ValAbbrev
@ -1976,22 +1978,23 @@ intrinsicProc
--}}} --}}}
--{{{ top-level forms --{{{ top-level forms
-- | An item at the top level is either a specification, or the end of the
-- file.
topLevelItem :: OccParser A.AST topLevelItem :: OccParser A.AST
topLevelItem = handleSpecs (allocation <|> specification) topLevelItem topLevelItem
(\m s inner -> A.Spec m s inner) = handleSpecs (allocation <|> specification) topLevelItem
<|> do m <- md (\m s inner -> A.Spec m s inner)
eof <|> do m <- md
-- Stash the current locals so that we can either restore them eof
-- when we get back to the file we included this one from, or -- Stash the current locals so that we can either restore them
-- pull the TLP name from them at the end. -- when we get back to the file we included this one from, or
modify $ (\ps -> ps { csMainLocals = csLocalNames ps }) -- pull the TLP name from them at the end.
return $ A.Several m [] modify $ (\ps -> ps { csMainLocals = csLocalNames ps })
return $ A.Several m []
-- | A source file is a series of nested specifications.
-- | A source file consists of a structured. -- The later specifications must be in scope for the earlier ones.
-- A source file is really a series of specifications, but the later ones need to -- We represent this as an 'AST' -- a @Structured ()@.
-- have the earlier ones in scope, so we can't parse them separately.
-- Instead, we nest the specifications
sourceFile :: OccParser (A.AST, [WarningReport], CompState) sourceFile :: OccParser (A.AST, [WarningReport], CompState)
sourceFile sourceFile
= do p <- topLevelItem = do p <- topLevelItem