SymbItems.hs revision d3f192025f2836285d9705a959542350e057f281
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceModule : $Header$
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceDescription : syntactic csp-casl symbols
81ec673ac5ab1493568d9ef7798b752ab8ee0e61Felix Gabriel ManceCopyright : (c) Christian Maeder, DFKI GmbH 2011
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceLicense : GPLv2 or higher, see LICENSE.txt
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceMaintainer : Christian.Maeder@dfki.de
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceStability : provisional
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel MancePortability : portable
e40758c36e3e5312669558ad189b24b3eaf10c59Mihai Codescuimport Common.Doc hiding (braces)
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Manceimport qualified Data.Set as Set
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mancedata CspSymbItems = CspSymbItems CspSymbKind [CspSymb]
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance deriving (Show, Eq)
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mancedata CspSymbMapItems = CspSymbMapItems CspSymbKind [CspSymbMap]
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance deriving (Show, Eq)
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mancedata CspSymbKind = CaslKind SYMB_KIND | ProcessKind | ChannelKind
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance deriving (Show, Eq, Ord)
0ec1551231bc5dfdcb3f2bd68fec7457fade7bfdFelix Gabriel Mancedata CspSymb = CspSymb Id (Maybe CspType)
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance deriving (Show, Eq)
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder-- for channels with sorts we may re-use A_type that is ambiguous
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mancedata CspType = CaslType TYPE | ProcType ProcProfile
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance deriving (Show, Eq)
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mancedata CspSymbMap = CspSymbMap CspSymb (Maybe CspSymb)
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance deriving (Show, Eq)
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel MancepluralCspSympKind :: CspSymbKind -> [a] -> Doc
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel MancepluralCspSympKind k l = case k of
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance CaslKind c -> case c of
68de80eb2800338cbd16512106fcadab79325d8bChristian Maeder Implicit -> empty
68de80eb2800338cbd16512106fcadab79325d8bChristian Maeder _ -> keyword $ pluralS_symb_list c l
68de80eb2800338cbd16512106fcadab79325d8bChristian Maeder ProcessKind -> keyword processS
68de80eb2800338cbd16512106fcadab79325d8bChristian Maeder ChannelKind -> keyword $ channelS ++ appendS l
68de80eb2800338cbd16512106fcadab79325d8bChristian Maederinstance Pretty CspSymbKind where
68de80eb2800338cbd16512106fcadab79325d8bChristian Maeder pretty k = pluralCspSympKind k [()]
fc7bd98aabe1bc26058660085e8c77d60a97bcecChristian Maederinstance Pretty CspType where
68de80eb2800338cbd16512106fcadab79325d8bChristian Maeder pretty t = case t of
fc7bd98aabe1bc26058660085e8c77d60a97bcecChristian Maeder CaslType c -> colon <> pretty c
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance ProcType p -> printProcProfile p
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Manceinstance Pretty CspSymb where
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance pretty (CspSymb i ms) = pretty i <+> pretty ms
852bd6145634dc2832b61c44678fe539bc1682d5Christian Maederinstance Pretty CspSymbMap where
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance pretty (CspSymbMap s ms) = pretty s <+> case ms of
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance Nothing -> empty
c4ca03cce9571a309b1c173e9d5d27fdb8843abdChristian Maeder Just t -> mapsto <+> pretty t
407f3d9049715c5d96f014a5a1776410e034db83Christian Maederinstance Pretty CspSymbItems where
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance pretty (CspSymbItems k l) = pluralCspSympKind k l <+> ppWithCommas l
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Manceinstance Pretty CspSymbMapItems where
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance pretty (CspSymbMapItems k l) = pluralCspSympKind k l <+> ppWithCommas l
544989bc1f6ed4bc0813334ffd934db0fb0010eaFelix Gabriel ManceparseCspId :: AParser st Id
544989bc1f6ed4bc0813334ffd934db0fb0010eaFelix Gabriel ManceparseCspId = parseId csp_casl_keywords
544989bc1f6ed4bc0813334ffd934db0fb0010eaFelix Gabriel MancecspSortId :: AParser st SORT
f8c3d045dda224e92bf6bcb6288e1ee75ab54d1eChristian MaedercspSortId = sortId csp_casl_keywords
6856a07e36551ed6fadd7c01e7152a3a28878a6fChristian MaedercommType :: AParser st CommType
6856a07e36551ed6fadd7c01e7152a3a28878a6fChristian Maeder s <- cspSortId
f8c3d045dda224e92bf6bcb6288e1ee75ab54d1eChristian Maeder r <- cspSortId
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance if isSimpleId s
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance then return $ CommTypeChan $ TypedChanName (idToSimpleId s) r
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance else unexpected $ "sort " ++ show s
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance <|> return (CommTypeSort s)
852bd6145634dc2832b61c44678fe539bc1682d5Christian MaederbracedList :: AParser st [CommType]
852bd6145634dc2832b61c44678fe539bc1682d5Christian MaederbracedList = braces $ commaSep1 commType
ea3f858eb531d981df3ed00beeadd99cf025adecChristian MaedercommAlpha :: AParser st CommAlpha
ea3f858eb531d981df3ed00beeadd99cf025adecChristian MaedercommAlpha = fmap Set.fromList $ single commType <|> bracedList
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mance-- | parsing a possibly qualified identifier
75aaf82c430ad2a5cf159962b1c5c09255010fb4Felix Gabriel MancecspSymb :: AParser st CspSymb
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance do i <- parseCspId
19e01e1a7e319063434bd86c8ecbc5f241ef9993Felix Gabriel Mance t <- fmap CaslType (opOrPredType csp_casl_keywords) <|>
1b1144abf7f95a4b23405b8d5604813cfe7b036aFelix Gabriel Mance fmap (ProcType . ProcProfile []) commAlpha
5a3ae0a9224276de25e709ef8788c1b9716cd206Christian Maeder return $ CspSymb i $ Just t
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mance ts <- between oParenT cParenT $ commaSep1 cspSortId
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance cs <- commAlpha
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance return $ CspSymb i $ Just $ ProcType $ ProcProfile ts cs
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance <|> return (CspSymb i Nothing)
1b90322eaf59ded3de24fc891bd67bbd73ec2bfaFelix Gabriel Mance-- | parsing one symbol or a mapping of one to second symbol
1b90322eaf59ded3de24fc891bd67bbd73ec2bfaFelix Gabriel MancecspSymbMap :: AParser st CspSymbMap
1b90322eaf59ded3de24fc891bd67bbd73ec2bfaFelix Gabriel MancecspSymbMap = liftM2 CspSymbMap cspSymb $ optionMaybe
1b90322eaf59ded3de24fc891bd67bbd73ec2bfaFelix Gabriel Mance $ asKey mapsTo >> cspSymb
1b90322eaf59ded3de24fc891bd67bbd73ec2bfaFelix Gabriel Mance-- | parse a kind keyword
1b90322eaf59ded3de24fc891bd67bbd73ec2bfaFelix Gabriel MancecspSymbKind :: AParser st CspSymbKind
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance fmap (const ChannelKind) (pluralKeyword channelS)
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance <|> fmap (const ProcessKind) (asKey processS)
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance <|> fmap (CaslKind . fst) symbKind
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance-- | parse a comma separated list of symbols
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel MancecspSymbs :: AParser st [CspSymb]
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance do s <- cspSymb
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance _ <- commaT `followedWith` parseCspId
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance is <- cspSymbs
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder return $ s : is
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance <|> return [s]
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance{- | Parse a possible kinded list of comma separated CspCASL symbols.
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance The argument is a list of keywords to avoid as identifiers. -}
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancecspSymbItems :: AParser st CspSymbItems
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancecspSymbItems = fmap (CspSymbItems $ CaslKind Implicit) cspSymbs <|> do
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance k <- cspSymbKind
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder fmap (CspSymbItems k) cspSymbs
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance-- | parse a comma separated list of symbols
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancecspSymbMaps :: AParser st [CspSymbMap]
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance do s <- cspSymbMap
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance _ <- commaT `followedWith` parseCspId
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder optional cspSymbMap
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance is <- cspSymbMaps
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance return $ s : is
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance <|> return [s]
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance-- | parse a possible kinded list of CspCASL symbol mappings
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel MancecspSymbMapItems :: AParser st CspSymbMapItems
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancecspSymbMapItems = fmap (CspSymbMapItems $ CaslKind Implicit) cspSymbMaps
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance k <- cspSymbKind
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance fmap (CspSymbMapItems k) cspSymbMaps