Parse_CspCASL.hs revision 12b2ae689353ecbaad720a9af9f9be01c1a3fe2d
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann{- |
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannModule : $Header$
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannDescription : Parser for CspCASL specifications
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannCopyright : (c) Uni Bremen 2007
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannLicense : GPLv2 or higher, see LICENSE.txt
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannMaintainer : a.m.gimblett@swan.ac.uk
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannStability : experimental
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannPortability : portable
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannParser for CSP-CASL specifications.
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann-}
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannmodule CspCASL.Parse_CspCASL (singleProcess) where
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannimport Text.ParserCombinators.Parsec
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannimport Common.AS_Annotation (Annoted (..), emptyAnno)
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannimport Common.AnnoState
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannimport Common.Id
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannimport Common.Lexer
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannimport CspCASL.AS_CspCASL
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannimport CspCASL.AS_CspCASL_Process
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannimport CspCASL.CspCASL_Keywords
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannimport CspCASL.Parse_CspCASL_Process
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmanninstance AParsable CspBasicExt where
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann aparser = cspBasicExt
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmanncspBasicExt :: AParser st CspBasicExt
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmanncspBasicExt =
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann itemList csp_casl_keywords channelS (const chanDecl) (\ l _ -> Channels l)
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann <|> do
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann p <- asKey processS
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann auxItemList csp_casl_keywords [p] procItem (\ l _ -> ProcItems l)
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannchanDecl :: AParser st CHANNEL_DECL
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannchanDecl = do
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann vs <- commaSep1 channel_name
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann colonT
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann es <- csp_casl_sort
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann return (ChannelDecl vs es)
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann{- Turn an unnamed singleton process into a declaration/equation. THIS WHOLE
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannfunctions seems odd. Why would we want a fixed process "P" which communicates
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmannover sort "singletonProcessSort". BUG? -}
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannsingleProcess :: PROCESS -> [Annoted PROC_ITEM]
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannsingleProcess p =
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann map emptyAnno [Proc_Decl singletonProcessName [] singletonProcessAlpha,
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann Proc_Eq (ParmProcname (PROCESS_NAME singletonProcessName) []) p]
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann where singletonProcessName = mkSimpleId "P"
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann singletonProcessAlpha =
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann ProcAlphabet [mkSimpleId "singletonProcessSort"]
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann nullRange
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannprocItem :: AParser st PROC_ITEM
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannprocItem = try procDecl <|> procEq
2450a4210dee64b064499a3a1154129bdfc74981Daniel Hausmann
2450a4210dee64b064499a3a1154129bdfc74981Daniel HausmannprocDecl :: AParser st PROC_ITEM
procDecl = do
(pn, parms, comms) <- procNameWithParamsAndComms
return (Proc_Decl pn parms comms)
procEq :: AParser st PROC_ITEM
procEq = do
pn <- parmProcname
equalT
p <- csp_casl_process
return (Proc_Eq pn p)
parmProcname :: AParser st PARM_PROCNAME
parmProcname = do
pn <- process_name
pv <- option [] $ do
try oParenT
vs <- commaSep1 var
cParenT
return vs
return (ParmProcname pn pv)