18861N/A{-# LANGUAGE DeriveDataTypeable #-}
18861N/ADescription : syntactic csp-casl symbols
18861N/ACopyright : (c) Christian Maeder, DFKI GmbH 2011
18861N/AMaintainer : Christian.Maeder@dfki.de
18861N/Adata CspSymbItems = CspSymbItems CspSymbKind [CspSymb]
18861N/A deriving (Show, Eq, Ord, Typeable, Data)
18861N/Adata CspSymbMapItems = CspSymbMapItems CspSymbKind [CspSymbMap]
18861N/A deriving (Show, Eq, Ord, Typeable, Data)
18861N/Adata CspSymbKind = CaslKind SYMB_KIND | ProcessKind | ChannelKind
18861N/A deriving (Show, Eq, Ord, Typeable, Data)
18861N/Adata CspSymb = CspSymb Id (Maybe CspType)
18861N/A deriving (Show, Eq, Ord, Typeable, Data)
18861N/A-- for channels with sorts we may re-use A_type that is ambiguous
18861N/Adata CspType = CaslType TYPE | ProcType ProcProfile
18861N/A deriving (Show, Eq, Ord, Typeable, Data)
18861N/Adata CspSymbMap = CspSymbMap CspSymb (Maybe CspSymb)
18861N/A deriving (Show, Eq, Ord, Typeable, Data)
18861N/ApluralCspSympKind :: CspSymbKind -> [a] -> Doc
18861N/ApluralCspSympKind k l = case k of
18861N/A _ -> keyword $ pluralS_symb_list c l
18861N/A ProcessKind -> keyword processS
18861N/A ChannelKind -> keyword $ channelS ++ appendS l
18861N/Ainstance Pretty CspSymbKind where
18861N/A pretty k = pluralCspSympKind k [()]
18861N/A CaslType c -> colon <> pretty c
18861N/A ProcType p -> printProcProfile p
18861N/A pretty (CspSymb i ms) = pretty i <+> pretty ms
18861N/Ainstance Pretty CspSymbMap where
18861N/A pretty (CspSymbMap s ms) = pretty s <+> case ms of
18861N/Ainstance Pretty CspSymbItems where
18861N/A pretty (CspSymbItems k l) = pluralCspSympKind k l <+> ppWithCommas l
18861N/Ainstance Pretty CspSymbMapItems where
18861N/A pretty (CspSymbMapItems k l) = pluralCspSympKind k l <+> ppWithCommas l
18861N/AcommAlpha :: AParser st CommAlpha
18861N/A-- | parsing a possibly qualified identifier
t <- fmap CaslType (opOrPredType cspKeywords) <|>
fmap (ProcType . ProcProfile []) commAlpha
return $ CspSymb i $ Just t
ts <- parenList cspSortId
return $ CspSymb i $ Just $ ProcType $ ProcProfile ts cs
<|> return (CspSymb i Nothing)
-- | parsing one symbol or a mapping of one to second symbol
cspSymbMap :: AParser st CspSymbMap
cspSymbMap = liftM2 CspSymbMap cspSymb $ optionMaybe
$ asKey mapsTo >> optional cspSymbKind >> cspSymb
-- | parse a kind keyword
cspSymbKind :: AParser st CspSymbKind
fmap (const ChannelKind) (pluralKeyword channelS)
<|> fmap (const ProcessKind) (asKey processS)
<|> fmap (CaslKind . fst) symbKind
-- | parse a comma separated list of symbols
cspSymbs :: AParser st [CspSymb]
_ <- commaT `followedWith` parseCspId
{- | Parse a possible kinded list of comma separated CspCASL symbols.
The argument is a list of keywords to avoid as identifiers. -}
cspSymbItems :: AParser st CspSymbItems
cspSymbItems = fmap (CspSymbItems $ CaslKind Implicit) cspSymbs <|> do
fmap (CspSymbItems k) cspSymbs
-- | parse a comma separated list of symbols
cspSymbMaps :: AParser st [CspSymbMap]
_ <- commaT `followedWith` parseCspId
-- | parse a possible kinded list of CspCASL symbol mappings
cspSymbMapItems :: AParser st CspSymbMapItems
cspSymbMapItems = fmap (CspSymbMapItems $ CaslKind Implicit) cspSymbMaps
fmap (CspSymbMapItems k) cspSymbMaps