Description : Parser for CspCASL processes
License : GPLv2 or higher
Maintainer : a.m.gimblett@swan.ac.uk
Parser for CSP-CASL processes.
csp_casl_process :: AParser st PROCESS
csp_casl_process = cond_proc <|> par_proc
cond_proc :: AParser st PROCESS
cond_proc = do ift <- asKey ifS
return (ConditionalProcess f p q (compRange ift q))
par_proc :: AParser st PROCESS
par_proc = choice_proc >>= par_proc'
par_proc' :: PROCESS -> AParser st PROCESS
par_proc' (Interleaving lp rp (compRange lp rp))
<|> do asKey synchronousS
par_proc' (SynchronousParallel lp rp (compRange lp rp))
<|> do asKey genpar_openS
es <- event_set <?> "communication type"
par_proc' (GeneralisedParallel lp es rp (compRange lp rp))
par_proc' (AlphabetisedParallel lp les res rp (compRange lp rp))
choice_proc :: AParser st PROCESS
choice_proc = seq_proc >>= choice_proc'
choice_proc' :: PROCESS -> AParser st PROCESS
do asKey external_choiceS
choice_proc' (ExternalChoice lp rp (compRange lp rp))
<|> do asKey internal_choiceS
choice_proc' (InternalChoice lp rp (compRange lp rp))
seq_proc :: AParser st PROCESS
seq_proc = pref_proc >>= seq_proc'
seq_proc' :: PROCESS -> AParser st PROCESS
seq_proc' lp = do asKey sequentialS
seq_proc' (Sequential lp rp (compRange lp rp))
pref_proc :: AParser st PROCESS
pref_proc = do e <- try (event << asKey prefix_procS)
return (PrefixProcess e p (compRange e p))
hid_ren_proc :: AParser st PROCESS
hid_ren_proc = prim_proc >>= hid_ren_proc'
hid_ren_proc' :: PROCESS -> AParser st PROCESS
hid_ren_proc' (Hiding lp es (compRange lp es))
<|> do asKey ren_proc_openS
ck <- asKey ren_proc_closeS
hid_ren_proc' (RenamingProcess lp rn (compRange lp ck))
prim_proc :: AParser st PROCESS
return (Run es (compRange rk cp))
<|> do ck <- asKey chaosS
return (Chaos es (compRange ck cp))
return (Div (getRange dk))
return (Stop (getRange sk))
return (Skip (getRange sk))
<|> do n <- try process_name
return (NamedProcess n args (compRange n args))
process_name :: AParser st PROCESS_NAME
process_name = varId csp_casl_keywords
channel_name :: AParser st CHANNEL_NAME
channel_name = varId csp_casl_keywords
comm_type :: AParser st COMM_TYPE
comm_type = varId csp_casl_keywords
-- List of arguments to a named process
procArgs :: AParser st [(TERM ())]
-- Sort IDs, excluding CspCasl keywords
csp_casl_sort :: AParser st SORT
csp_casl_sort = sortId csp_casl_keywords
event_set :: AParser st EVENT_SET
event_set = do cts <- comm_type `sepBy` commaT
return (EventSet cts (getRange cts))
-- internal / external prefix choice.
event :: AParser st EVENT
event = try chan_recv <|> try chan_nondet_send <|> try chan_send
<|> try externalPrefixChoice <|> try internalPrefixChoice
chan_send :: AParser st EVENT
chan_send = do cn <- channel_name
return (ChanSend cn t (getRange cn))
chan_nondet_send :: AParser st EVENT
chan_nondet_send = do cn <- channel_name
return (ChanNonDetSend cn v s (compRange cn s))
chan_recv :: AParser st EVENT
chan_recv = do cn <- channel_name
return (ChanRecv cn v s (compRange cn s))
internalPrefixChoice :: AParser st EVENT
internalPrefixChoice = do ipk <- asKey internal_choiceS
return (InternalPrefixChoice v s (compRange ipk s))
externalPrefixChoice :: AParser st EVENT
externalPrefixChoice = do epk <- asKey external_choiceS
return (ExternalPrefixChoice v s (compRange epk s))
term_event :: AParser st EVENT
return (TermEvent t (getRange t))
-- Formulas are CASL formulas. We make our own wrapper around them
formula :: AParser st (FORMULA ())
-- Primitive renaming is done using an operator name or a predicate
-- name. They're both Ids. Separation between operator or predicate
-- (or some other non-applicable Id) must be a static analysis
renaming :: AParser st RENAMING
renaming = fmap Renaming $ parseId csp_casl_keywords `sepBy` commaT
var = varId csp_casl_keywords
compRange :: (GetRange a, GetRange b) => a -> b -> Range
compRange x y = getRange x `appRange` getRange y