SymbItems.hs revision 499b6cb3ab95a336a324545123e18f387ee4d2a3
306763c67bb99228487345b32ab8c5c6cd41f23cChristian MaederModule : $Header$
306763c67bb99228487345b32ab8c5c6cd41f23cChristian MaederDescription : syntactic csp-casl symbols
306763c67bb99228487345b32ab8c5c6cd41f23cChristian MaederCopyright : (c) Christian Maeder, DFKI GmbH 2011
306763c67bb99228487345b32ab8c5c6cd41f23cChristian MaederLicense : GPLv2 or higher, see LICENSE.txt
e9249d3ecd51a2b6a966a58669953e58d703adc6Till MossakowskiMaintainer : Christian.Maeder@dfki.de
306763c67bb99228487345b32ab8c5c6cd41f23cChristian MaederStability : provisional
306763c67bb99228487345b32ab8c5c6cd41f23cChristian MaederPortability : portable
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowskiimport Common.Doc hiding (braces)
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowskiimport qualified Data.Set as Set
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowskidata CspSymbItems = CspSymbItems CspSymbKind [CspSymb]
59fa9b1349ae1e001d996da732c4ac805c2938e2Christian Maeder deriving (Show, Eq)
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowskidata CspSymbMapItems = CspSymbMapItems CspSymbKind [CspSymbMap]
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski deriving (Show, Eq)
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowskidata CspSymbKind = CaslKind SYMB_KIND | ProcessKind | ChannelKind
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski deriving (Show, Eq, Ord)
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowskidata CspSymb = CspSymb Id (Maybe CspType)
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski deriving (Show, Eq)
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski-- for channels with sorts we may re-use A_type that is ambiguous
d85e3f253f6af237c4b70bbfacb1bfecb5cfa678Christian Maederdata CspType = CaslType TYPE | ProcType ProcProfile
d85e3f253f6af237c4b70bbfacb1bfecb5cfa678Christian Maeder deriving (Show, Eq)
4184cb191a9081cb2a9cf3ef5f060f56f0ca5922Till Mossakowskidata CspSymbMap = CspSymbMap CspSymb (Maybe CspSymb)
8731f7b93b26083dc34a2c0937cd6493b42f2c2cTill Mossakowski deriving (Show, Eq)
8731f7b93b26083dc34a2c0937cd6493b42f2c2cTill MossakowskipluralCspSympKind :: CspSymbKind -> [a] -> Doc
e9249d3ecd51a2b6a966a58669953e58d703adc6Till MossakowskipluralCspSympKind k l = case k of
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski CaslKind c -> case c of
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski Implicit -> empty
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski _ -> keyword $ pluralS_symb_list c l
38f350357e92da312d2c344352180b3dc5c1fc8aTill Mossakowski ProcessKind -> keyword processS
5d6e7ea3bd14fc987436cff0f542393ea9ba34bbTill Mossakowski ChannelKind -> keyword $ channelS ++ appendS l
9a36df4f63e0214bc0b4aef9b388c8d4e48632bbTill Mossakowskiinstance Pretty CspSymbKind where
9a36df4f63e0214bc0b4aef9b388c8d4e48632bbTill Mossakowski pretty k = pluralCspSympKind k [()]
5d6e7ea3bd14fc987436cff0f542393ea9ba34bbTill Mossakowskiinstance Pretty CspType where
5d6e7ea3bd14fc987436cff0f542393ea9ba34bbTill Mossakowski pretty t = case t of
5d6e7ea3bd14fc987436cff0f542393ea9ba34bbTill Mossakowski CaslType c -> colon <> pretty c
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski ProcType p -> printProcProfile p
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowskiinstance Pretty CspSymb where
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski pretty (CspSymb i ms) = pretty i <+> pretty ms
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowskiinstance Pretty CspSymbMap where
425b287f28abf82702d46c176a38b668fb017ce4Felix Reckers pretty (CspSymbMap s ms) = pretty s <+> case ms of
d85e3f253f6af237c4b70bbfacb1bfecb5cfa678Christian Maeder Nothing -> empty
425b287f28abf82702d46c176a38b668fb017ce4Felix Reckers Just t -> mapsto <+> pretty t
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowskiinstance Pretty CspSymbItems where
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski pretty (CspSymbItems k l) = pluralCspSympKind k l <+> ppWithCommas l
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowskiinstance Pretty CspSymbMapItems where
8db2d2c5a8df6dd6d7302bc59577150b87237940Till Mossakowski pretty (CspSymbMapItems k l) = pluralCspSympKind k l <+> ppWithCommas l
8db2d2c5a8df6dd6d7302bc59577150b87237940Till MossakowskiparseCspId :: AParser st Id
59fa9b1349ae1e001d996da732c4ac805c2938e2Christian MaederparseCspId = parseId csp_casl_keywords
e9249d3ecd51a2b6a966a58669953e58d703adc6Till MossakowskicspSortId :: AParser st SORT
e9249d3ecd51a2b6a966a58669953e58d703adc6Till MossakowskicspSortId = sortId csp_casl_keywords
e9249d3ecd51a2b6a966a58669953e58d703adc6Till MossakowskicommType :: AParser st CommType
230a51f3c282a3222d1cf40c2040fee19259964eTill Mossakowski s <- cspSortId
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski r <- cspSortId
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski if isSimpleId s
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski then return $ CommTypeChan $ TypedChanName (idToSimpleId s) r
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski else unexpected $ "sort " ++ show s
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski <|> return (CommTypeSort s)
e9249d3ecd51a2b6a966a58669953e58d703adc6Till MossakowskibracedList :: AParser st [CommType]
e9249d3ecd51a2b6a966a58669953e58d703adc6Till MossakowskibracedList = braces $ commaSep1 commType
e9249d3ecd51a2b6a966a58669953e58d703adc6Till MossakowskicommAlpha :: AParser st CommAlpha
e9249d3ecd51a2b6a966a58669953e58d703adc6Till MossakowskicommAlpha = fmap Set.fromList $ single commType <|> bracedList
5e21bb46b24f477dafad6fdeff51aed7aaad0a47Till Mossakowski-- | parsing a possibly qualified identifier
5e21bb46b24f477dafad6fdeff51aed7aaad0a47Till MossakowskicspSymb :: AParser st CspSymb
8731f7b93b26083dc34a2c0937cd6493b42f2c2cTill Mossakowski do i <- parseCspId
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski t <- fmap CaslType (opOrPredType csp_casl_keywords) <|>
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski fmap (ProcType . ProcProfile []) commAlpha
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski return $ CspSymb i $ Just t
d85e3f253f6af237c4b70bbfacb1bfecb5cfa678Christian Maeder ts <- between oParenT cParenT $ commaSep1 cspSortId
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski cs <- commAlpha
8db2d2c5a8df6dd6d7302bc59577150b87237940Till Mossakowski return $ CspSymb i $ Just $ ProcType $ ProcProfile ts cs
d85e3f253f6af237c4b70bbfacb1bfecb5cfa678Christian Maeder <|> return (CspSymb i Nothing)
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski-- | parsing one symbol or a mapping of one to second symbol
e9249d3ecd51a2b6a966a58669953e58d703adc6Till MossakowskicspSymbMap :: AParser st CspSymbMap
e9249d3ecd51a2b6a966a58669953e58d703adc6Till MossakowskicspSymbMap = liftM2 CspSymbMap cspSymb $ optionMaybe
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski $ asKey mapsTo >> optional cspSymbKind >> cspSymb
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski-- | parse a kind keyword
e9249d3ecd51a2b6a966a58669953e58d703adc6Till MossakowskicspSymbKind :: AParser st CspSymbKind
d85e3f253f6af237c4b70bbfacb1bfecb5cfa678Christian Maeder fmap (const ChannelKind) (pluralKeyword channelS)
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski <|> fmap (const ProcessKind) (asKey processS)
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski <|> fmap (CaslKind . fst) symbKind
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski-- | parse a comma separated list of symbols
e9249d3ecd51a2b6a966a58669953e58d703adc6Till MossakowskicspSymbs :: AParser st [CspSymb]
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski do s <- cspSymb
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski _ <- commaT `followedWith` parseCspId
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski is <- cspSymbs
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski return $ s : is
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski <|> return [s]
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski{- | Parse a possible kinded list of comma separated CspCASL symbols.
d85e3f253f6af237c4b70bbfacb1bfecb5cfa678Christian Maeder The argument is a list of keywords to avoid as identifiers. -}
d85e3f253f6af237c4b70bbfacb1bfecb5cfa678Christian MaedercspSymbItems :: AParser st CspSymbItems
e9249d3ecd51a2b6a966a58669953e58d703adc6Till MossakowskicspSymbItems = fmap (CspSymbItems $ CaslKind Implicit) cspSymbs <|> do
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski k <- cspSymbKind
d85e3f253f6af237c4b70bbfacb1bfecb5cfa678Christian Maeder fmap (CspSymbItems k) cspSymbs
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski-- | parse a comma separated list of symbols
e9249d3ecd51a2b6a966a58669953e58d703adc6Till MossakowskicspSymbMaps :: AParser st [CspSymbMap]
f7819aa9d183836144a98c70d4fa7d65e31cb513Till Mossakowski do s <- cspSymbMap
f7819aa9d183836144a98c70d4fa7d65e31cb513Till Mossakowski _ <- commaT `followedWith` parseCspId
f7819aa9d183836144a98c70d4fa7d65e31cb513Till Mossakowski is <- cspSymbMaps
8731f7b93b26083dc34a2c0937cd6493b42f2c2cTill Mossakowski return $ s : is
8731f7b93b26083dc34a2c0937cd6493b42f2c2cTill Mossakowski <|> return [s]
8731f7b93b26083dc34a2c0937cd6493b42f2c2cTill Mossakowski-- | parse a possible kinded list of CspCASL symbol mappings
e9249d3ecd51a2b6a966a58669953e58d703adc6Till MossakowskicspSymbMapItems :: AParser st CspSymbMapItems
e9249d3ecd51a2b6a966a58669953e58d703adc6Till MossakowskicspSymbMapItems = fmap (CspSymbMapItems $ CaslKind Implicit) cspSymbMaps
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski k <- cspSymbKind
d85e3f253f6af237c4b70bbfacb1bfecb5cfa678Christian Maeder fmap (CspSymbMapItems k) cspSymbMaps