SymbItems.hs revision d3f192025f2836285d9705a959542350e057f281
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder{- |
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
5d801400993c9671010d244646936d8fd435638cChristian Maeder
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance-}
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance
aa0ca44e856c87db27e61687cbb630f270976da1Felix Gabriel Mancemodule CspCASL.SymbItems where
5d801400993c9671010d244646936d8fd435638cChristian Maeder
5d801400993c9671010d244646936d8fd435638cChristian Maederimport CspCASL.AS_CspCASL_Process
5d801400993c9671010d244646936d8fd435638cChristian Maederimport CspCASL.CspCASL_Keywords
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Manceimport CspCASL.Print_CspCASL
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
097bc9f18b722812d480df0f5c634d09cbca8e21Felix Gabriel Manceimport CASL.AS_Basic_CASL
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Manceimport CASL.SymbolParser
852bd6145634dc2832b61c44678fe539bc1682d5Christian Maederimport CASL.ToDoc
090c663fcc1593c66f39a0972326799a672760d5Christian Maeder
f8c3d045dda224e92bf6bcb6288e1ee75ab54d1eChristian Maederimport Common.AnnoState
e40758c36e3e5312669558ad189b24b3eaf10c59Mihai Codescuimport Common.Doc hiding (braces)
e40758c36e3e5312669558ad189b24b3eaf10c59Mihai Codescuimport Common.DocUtils
feab1106bbee4f2ea2fd48bca7106dd041e4211dFelix Gabriel Manceimport Common.Id
18ff56829e5e99383ee6106584d55bcbd8ed45e7Felix Gabriel Manceimport Common.Keywords
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Manceimport Common.Lexer
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maederimport Common.Parsec
1a38107941725211e7c3f051f7a8f5e12199f03acmaederimport Common.Token
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mance
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Manceimport Text.ParserCombinators.Parsec
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
f8c3d045dda224e92bf6bcb6288e1ee75ab54d1eChristian Maederimport Control.Monad
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Manceimport qualified Data.Set as Set
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mancedata CspSymbItems = CspSymbItems CspSymbKind [CspSymb]
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance deriving (Show, Eq)
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mancedata CspSymbMapItems = CspSymbMapItems CspSymbKind [CspSymbMap]
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance deriving (Show, Eq)
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mancedata CspSymbKind = CaslKind SYMB_KIND | ProcessKind | ChannelKind
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance deriving (Show, Eq, Ord)
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mance
0ec1551231bc5dfdcb3f2bd68fec7457fade7bfdFelix Gabriel Mancedata CspSymb = CspSymb Id (Maybe CspType)
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance deriving (Show, Eq)
852bd6145634dc2832b61c44678fe539bc1682d5Christian Maeder
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)
6033265e7b4ae660eff78e944213286863304903Mihai Codescu
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mancedata CspSymbMap = CspSymbMap CspSymb (Maybe CspSymb)
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance deriving (Show, Eq)
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance
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 Maeder
68de80eb2800338cbd16512106fcadab79325d8bChristian Maederinstance Pretty CspSymbKind where
68de80eb2800338cbd16512106fcadab79325d8bChristian Maeder pretty k = pluralCspSympKind k [()]
fc7bd98aabe1bc26058660085e8c77d60a97bcecChristian Maeder
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
68de80eb2800338cbd16512106fcadab79325d8bChristian Maeder
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Manceinstance Pretty CspSymb where
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance pretty (CspSymb i ms) = pretty i <+> pretty ms
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
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
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
407f3d9049715c5d96f014a5a1776410e034db83Christian Maederinstance Pretty CspSymbItems where
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance pretty (CspSymbItems k l) = pluralCspSympKind k l <+> ppWithCommas l
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Manceinstance Pretty CspSymbMapItems where
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance pretty (CspSymbMapItems k l) = pluralCspSympKind k l <+> ppWithCommas l
544989bc1f6ed4bc0813334ffd934db0fb0010eaFelix Gabriel Mance
544989bc1f6ed4bc0813334ffd934db0fb0010eaFelix Gabriel ManceparseCspId :: AParser st Id
544989bc1f6ed4bc0813334ffd934db0fb0010eaFelix Gabriel ManceparseCspId = parseId csp_casl_keywords
544989bc1f6ed4bc0813334ffd934db0fb0010eaFelix Gabriel Mance
544989bc1f6ed4bc0813334ffd934db0fb0010eaFelix Gabriel MancecspSortId :: AParser st SORT
f8c3d045dda224e92bf6bcb6288e1ee75ab54d1eChristian MaedercspSortId = sortId csp_casl_keywords
6856a07e36551ed6fadd7c01e7152a3a28878a6fChristian Maeder
6856a07e36551ed6fadd7c01e7152a3a28878a6fChristian MaedercommType :: AParser st CommType
6856a07e36551ed6fadd7c01e7152a3a28878a6fChristian MaedercommType = do
6856a07e36551ed6fadd7c01e7152a3a28878a6fChristian Maeder s <- cspSortId
f8c3d045dda224e92bf6bcb6288e1ee75ab54d1eChristian Maeder do
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance colonT
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 Maeder
852bd6145634dc2832b61c44678fe539bc1682d5Christian MaederbracedList :: AParser st [CommType]
852bd6145634dc2832b61c44678fe539bc1682d5Christian MaederbracedList = braces $ commaSep1 commType
ea3f858eb531d981df3ed00beeadd99cf025adecChristian Maeder
ea3f858eb531d981df3ed00beeadd99cf025adecChristian MaedercommAlpha :: AParser st CommAlpha
ea3f858eb531d981df3ed00beeadd99cf025adecChristian MaedercommAlpha = fmap Set.fromList $ single commType <|> bracedList
75aaf82c430ad2a5cf159962b1c5c09255010fb4Felix Gabriel Mance
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mance-- | parsing a possibly qualified identifier
75aaf82c430ad2a5cf159962b1c5c09255010fb4Felix Gabriel MancecspSymb :: AParser st CspSymb
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel MancecspSymb =
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance do i <- parseCspId
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance do
1b1144abf7f95a4b23405b8d5604813cfe7b036aFelix Gabriel Mance _ <- colonST
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 <|> do
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mance ts <- between oParenT cParenT $ commaSep1 cspSortId
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mance colonT
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
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
1b90322eaf59ded3de24fc891bd67bbd73ec2bfaFelix Gabriel Mance-- | parse a kind keyword
1b90322eaf59ded3de24fc891bd67bbd73ec2bfaFelix Gabriel MancecspSymbKind :: AParser st CspSymbKind
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel MancecspSymbKind =
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
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance-- | parse a comma separated list of symbols
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel MancecspSymbs :: AParser st [CspSymb]
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel MancecspSymbs =
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance do s <- cspSymb
9cb6af1a7632f12b60f592ce5eb2ac51e6bd33bbFelix Gabriel Mance do
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance _ <- commaT `followedWith` parseCspId
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance is <- cspSymbs
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder return $ s : is
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance <|> return [s]
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance
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
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance-- | parse a comma separated list of symbols
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancecspSymbMaps :: AParser st [CspSymbMap]
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancecspSymbMaps =
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance do s <- cspSymbMap
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance do
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
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 <|> do
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance k <- cspSymbKind
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance fmap (CspSymbMapItems k) cspSymbMaps
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance