1a38107941725211e7c3f051f7a8f5e12199f03acmaeder{-# LANGUAGE DeriveDataTypeable #-}
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederDescription : syntactic csp-casl symbols
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederCopyright : (c) Christian Maeder, DFKI GmbH 2011
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederLicense : GPLv2 or higher, see LICENSE.txt
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederMaintainer : Christian.Maeder@dfki.de
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederStability : provisional
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederPortability : portable
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederimport Common.Doc hiding (braces)
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederimport qualified Data.Set as Set
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederdata CspSymbItems = CspSymbItems CspSymbKind [CspSymb]
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder deriving (Show, Eq, Ord, Typeable, Data)
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederdata CspSymbMapItems = CspSymbMapItems CspSymbKind [CspSymbMap]
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder deriving (Show, Eq, Ord, Typeable, Data)
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederdata CspSymbKind = CaslKind SYMB_KIND | ProcessKind | ChannelKind
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder deriving (Show, Eq, Ord, Typeable, Data)
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederdata CspSymb = CspSymb Id (Maybe CspType)
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder deriving (Show, Eq, Ord, Typeable, Data)
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder-- for channels with sorts we may re-use A_type that is ambiguous
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederdata CspType = CaslType TYPE | ProcType ProcProfile
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder deriving (Show, Eq, Ord, Typeable, Data)
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederdata CspSymbMap = CspSymbMap CspSymb (Maybe CspSymb)
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder deriving (Show, Eq, Ord, Typeable, Data)
ab0274ab68a174d3e92235b4c4ca865c03901583Christian MaederpluralCspSympKind :: CspSymbKind -> [a] -> Doc
ab0274ab68a174d3e92235b4c4ca865c03901583Christian MaederpluralCspSympKind k l = case k of
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder CaslKind c -> case c of
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder Implicit -> empty
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder _ -> keyword $ pluralS_symb_list c l
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder ProcessKind -> keyword processS
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder ChannelKind -> keyword $ channelS ++ appendS l
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maederinstance Pretty CspSymbKind where
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder pretty k = pluralCspSympKind k [()]
9f93b2a8b552789cd939d599504d39732672dc84Christian Maederinstance Pretty CspType where
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder pretty t = case t of
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder CaslType c -> colon <> pretty c
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder ProcType p -> printProcProfile p
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederinstance Pretty CspSymb where
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder pretty (CspSymb i ms) = pretty i <+> pretty ms
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederinstance Pretty CspSymbMap where
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder pretty (CspSymbMap s ms) = pretty s <+> case ms of
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder Nothing -> empty
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder Just t -> mapsto <+> pretty t
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederinstance Pretty CspSymbItems where
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder pretty (CspSymbItems k l) = pluralCspSympKind k l <+> ppWithCommas l
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederinstance Pretty CspSymbMapItems where
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder pretty (CspSymbMapItems k l) = pluralCspSympKind k l <+> ppWithCommas l
d3f192025f2836285d9705a959542350e057f281Christian MaedercommAlpha :: AParser st CommAlpha
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercommAlpha = fmap Set.fromList $ single commType <|> bracedList
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder-- | parsing a possibly qualified identifier
d3f192025f2836285d9705a959542350e057f281Christian MaedercspSymb :: AParser st CspSymb
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder do i <- parseCspId
38504dc968167ba2e82dd568edeae8d6af4dc145Christian Maeder t <- fmap CaslType (opOrPredType cspKeywords) <|>
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder fmap (ProcType . ProcProfile []) commAlpha
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder return $ CspSymb i $ Just t
66ea26416f702f5e00759ffc767f0f785cc86058Christian Maeder ts <- parenList cspSortId
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder cs <- commAlpha
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder return $ CspSymb i $ Just $ ProcType $ ProcProfile ts cs
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder <|> return (CspSymb i Nothing)
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder-- | parsing one symbol or a mapping of one to second symbol
d3f192025f2836285d9705a959542350e057f281Christian MaedercspSymbMap :: AParser st CspSymbMap
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercspSymbMap = liftM2 CspSymbMap cspSymb $ optionMaybe
499b6cb3ab95a336a324545123e18f387ee4d2a3Christian Maeder $ asKey mapsTo >> optional cspSymbKind >> cspSymb
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder-- | parse a kind keyword
d3f192025f2836285d9705a959542350e057f281Christian MaedercspSymbKind :: AParser st CspSymbKind
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder fmap (const ChannelKind) (pluralKeyword channelS)
d3f192025f2836285d9705a959542350e057f281Christian Maeder <|> fmap (const ProcessKind) (asKey processS)
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder <|> fmap (CaslKind . fst) symbKind
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder-- | parse a comma separated list of symbols
d3f192025f2836285d9705a959542350e057f281Christian MaedercspSymbs :: AParser st [CspSymb]
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder do s <- cspSymb
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder _ <- commaT `followedWith` parseCspId
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder is <- cspSymbs
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder return $ s : is
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder <|> return [s]
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder{- | Parse a possible kinded list of comma separated CspCASL symbols.
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder The argument is a list of keywords to avoid as identifiers. -}
d3f192025f2836285d9705a959542350e057f281Christian MaedercspSymbItems :: AParser st CspSymbItems
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercspSymbItems = fmap (CspSymbItems $ CaslKind Implicit) cspSymbs <|> do
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder k <- cspSymbKind
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder fmap (CspSymbItems k) cspSymbs
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder-- | parse a comma separated list of symbols
d3f192025f2836285d9705a959542350e057f281Christian MaedercspSymbMaps :: AParser st [CspSymbMap]
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder do s <- cspSymbMap
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder _ <- commaT `followedWith` parseCspId
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder is <- cspSymbMaps
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder return $ s : is
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder <|> return [s]
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder-- | parse a possible kinded list of CspCASL symbol mappings
d3f192025f2836285d9705a959542350e057f281Christian MaedercspSymbMapItems :: AParser st CspSymbMapItems
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercspSymbMapItems = fmap (CspSymbMapItems $ CaslKind Implicit) cspSymbMaps
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder k <- cspSymbKind
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder fmap (CspSymbMapItems k) cspSymbMaps