Parse_CspCASL.hs revision f909337bf7012aca169c0b56b89efbd4a310f8da
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder{- |
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaederModule : $Id$
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaederDescription : Parser for CspCASL specifications
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaederCopyright : (c) Uni Bremen 2007
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaederLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaederMaintainer : a.m.gimblett@swan.ac.uk
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaederStability : experimental
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaederPortability : portable
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaederParser for CSP-CASL specifications.
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder-}
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maedermodule CspCASL.Parse_CspCASL (
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder cspBasicSpec
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder) where
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maederimport Text.ParserCombinators.Parsec (choice, many1, try, (<|>),
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder option, sepBy)
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maederimport CASL.AS_Basic_CASL (VAR)
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maederimport Common.AnnoState (AParser, asKey, colonT, equalT, anSemi)
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maederimport Common.Id (genName)
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maederimport Common.Lexer (commaSep1, cParenT, oParenT)
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maederimport CspCASL.AS_CspCASL
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maederimport CspCASL.AS_CspCASL_Process
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maederimport CspCASL.Core_CspCASL
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maederimport CspCASL.CspCASL_Keywords
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maederimport CspCASL.Parse_CspCASL_Process
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaedercspBasicSpec :: AParser st CspBasicSpec
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaedercspBasicSpec = do
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder option [] $ do
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder choice [asKey channelS, asKey channelsS] -- "channel" or "channels"
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder cds <- chanDecl `sepBy` anSemi
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder --anSemi -- optional final semicolon. How?
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder return cds
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder items <- processItems
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder let (decls, eqs) = splitProcItems items
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder return (basicToCore (CspBasicSpec [] decls eqs))
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaederchanDecl :: AParser st CHANNEL
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaederchanDecl = do vs <- commaSep1 var
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder colonT
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder es <- event_set
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder return (Channel vs es)
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maedertype PROC_ITEM = Either PROC_DECL PROC_EQ
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaederprocessItems :: AParser st [PROC_ITEM]
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaederprocessItems = do asKey processS
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder procItems <|> fmap singleProcess csp_casl_process
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder-- Turn an unnamed singleton process into a declaration/equation.
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaedersingleProcess :: PROCESS -> [PROC_ITEM]
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaedersingleProcess p =
[Left (ProcDecl singletonProcessName [] FullAlphabet),
Right (ProcEq (ParmProcname singletonProcessName []) p)]
where singletonProcessName = genName "P"
splitProcItems :: [PROC_ITEM] -> ([PROC_DECL], [PROC_EQ])
splitProcItems i = ([x | Left x <- i], [x | Right x <- i])
procItems :: AParser st [PROC_ITEM]
procItems = many1 procItem
procItem :: AParser st PROC_ITEM
procItem = try (do pdcl <- procDecl
return (Left pdcl))
<|> (do peq <- procEq
return (Right peq))
procDecl :: AParser st PROC_DECL
procDecl = do
pn <- process_name
oParenT
parms <- commaSep1 event_set
cParenT
colonT
es <- event_set
return (ProcDecl pn parms es)
procEq :: AParser st PROC_EQ
procEq = do
pn <- try (do
pn <- parmProcname
equalT
return pn)
p <- csp_casl_process
return (ProcEq pn p)
parmProcname :: AParser st PARM_PROCNAME
parmProcname = do
pn <- process_name
pv <- procVars
return (ParmProcname pn pv)
procVars :: AParser st [VAR]
procVars = do try oParenT
vs <- commaSep1 var
cParenT
return vs
<|> return []