LibName.hs revision 720eeee7c9d8442093c8d05bed743193eee906e0
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst Schulz{- |
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens ElknerModule : $Header$
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst SchulzDescription : library names for HetCASL and development graphs
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst SchulzCopyright : (c) Christian Maeder, DFKI GmbH 2008
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu ProdescuLicense : GPLv2 or higher, see LICENSE.txt
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst SchulzMaintainer : Christian.Maeder@dfki.de
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst SchulzStability : provisional
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst SchulzPortability : portable
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst Schulz
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst SchulzAbstract syntax of HetCASL specification libraries
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst Schulz Follows Sect. II:2.2.5 of the CASL Reference Manual.
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst Schulz-}
4cbba4634ba267c438f75fa7a5009f6249d3dda1Christian Maeder
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst Schulzmodule Common.LibName
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst Schulz ( LibName (LibName)
de8eee2014437ec4020be15cd363257f87e79943Christian Maeder , LibId (IndirectLink)
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst Schulz , VersionNumber (VersionNumber)
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder , LinkPath (LinkPath)
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst Schulz , SLinkPath
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder , isQualNameFrom
c7f1a9b3811f1ed427c57559d9af26a75a309ff1Ewaryst Schulz , isQualName
e24ccbc27ab90aa0bdb7064fd42e3bb0e0da6174Christian Maeder , mkQualName
1f7d5e06c0b9d99d257bdee9e8fb7bc000ec1d78Ewaryst Schulz , unQualName
c7f1a9b3811f1ed427c57559d9af26a75a309ff1Ewaryst Schulz , setFilePath
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder , getFilePath
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst Schulz , emptyLibName
91b3147021cbeebb0590f4a577acba73142785c5Christian Maeder , convertFileToLibStr
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder , getLibId
ad3327fb03d73436ee6f61c7ad2e51186137f46bChristian Maeder , mkLibStr
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst Schulz ) where
c7f1a9b3811f1ed427c57559d9af26a75a309ff1Ewaryst Schulz
c7f1a9b3811f1ed427c57559d9af26a75a309ff1Ewaryst Schulzimport Common.Doc
c7f1a9b3811f1ed427c57559d9af26a75a309ff1Ewaryst Schulzimport Common.DocUtils
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst Schulzimport Common.Id
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst Schulzimport Common.Keywords
c7f1a9b3811f1ed427c57559d9af26a75a309ff1Ewaryst Schulzimport Common.Utils
c7f1a9b3811f1ed427c57559d9af26a75a309ff1Ewaryst Schulz
e24ccbc27ab90aa0bdb7064fd42e3bb0e0da6174Christian Maederimport Data.Char
01ddc4cad68fa84b4e9dd41089ad876329bae5b0Christian Maederimport Data.List
e24ccbc27ab90aa0bdb7064fd42e3bb0e0da6174Christian Maederimport Data.Ord
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maederimport System.FilePath
01ddc4cad68fa84b4e9dd41089ad876329bae5b0Christian Maeder
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaederomTs :: [Token]
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian MaederomTs = [genToken "OM"]
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaedermkQualName :: SIMPLE_ID -> LibName -> Id -> Id
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaedermkQualName nodeId ln i =
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder Id omTs [i, simpleIdToId nodeId, libNameToId ln] $ posOfId i
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaederisQualNameFrom :: SIMPLE_ID -> LibName -> Id -> Bool
de8eee2014437ec4020be15cd363257f87e79943Christian MaederisQualNameFrom nodeId ln i@(Id _ cs _) = case cs of
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder _ : n : l : _ | isQualName i ->
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder n == simpleIdToId nodeId && libNameToId ln == l
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder _ -> True
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaederisQualName :: Id -> Bool
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaederisQualName (Id ts cs _) = case cs of
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder _ : _ : _ -> ts == omTs
e24ccbc27ab90aa0bdb7064fd42e3bb0e0da6174Christian Maeder _ -> False
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian MaederunQualName :: Id -> Id
e24ccbc27ab90aa0bdb7064fd42e3bb0e0da6174Christian MaederunQualName j@(Id _ cs _) = case cs of
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder i : _ | isQualName j -> i
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder _ -> j
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian MaederlibNameToId :: LibName -> Id
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian MaederlibNameToId ln = let
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder path = splitOn '/' . show $ getLibId ln
3fea26a73b8fa69b22dfd2653d8f7bdacb45b9c9Christian Maeder toTok s = Token s $ getRange ln
6c244f12ab0dc7ba1baf1413266093886a570e13Christian Maeder in mkId $ map toTok $ intersperse "/" path
8a3ab31caff2bc2ad9355680186a7dd4da5f73b5Christian Maeder
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maederdata LibName = LibName
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder { getLibId :: LibId
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder , _libVersion :: Maybe VersionNumber }
3fea26a73b8fa69b22dfd2653d8f7bdacb45b9c9Christian Maeder
3fea26a73b8fa69b22dfd2653d8f7bdacb45b9c9Christian MaederemptyLibName :: String -> LibName
3fea26a73b8fa69b22dfd2653d8f7bdacb45b9c9Christian MaederemptyLibName s = LibName (IndirectLink s nullRange "") Nothing
e24ccbc27ab90aa0bdb7064fd42e3bb0e0da6174Christian Maeder
6c244f12ab0dc7ba1baf1413266093886a570e13Christian Maederdata LibId = IndirectLink PATH Range FilePath
3fea26a73b8fa69b22dfd2653d8f7bdacb45b9c9Christian Maeder -- pos: start of PATH
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaederupdFilePathOfLibId :: FilePath -> LibId -> LibId
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaederupdFilePathOfLibId fp (IndirectLink p r _) = IndirectLink p r fp
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian MaedersetFilePath :: FilePath -> LibName -> LibName
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaedersetFilePath fp ln =
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder ln { getLibId = updFilePathOfLibId fp $ getLibId ln }
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder
5b68f1141555736e0b7ddbe14218bcabcc44636fChristian MaedergetFilePath :: LibName -> FilePath
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaedergetFilePath ln =
5b68f1141555736e0b7ddbe14218bcabcc44636fChristian Maeder case getLibId ln of
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder IndirectLink _ _ fp -> fp
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maederdata VersionNumber = VersionNumber [String] Range
1fd936f22c745583ff70fd7ff6e3397f6bcf3fd9Marcel Zirbel -- pos: "version", start of first string
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maedertype PATH = String
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maederinstance GetRange LibId where
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder getRange (IndirectLink _ r _) = r
dc62afbf79603699b39b2387f48298634f642e67cmaeder
e24ccbc27ab90aa0bdb7064fd42e3bb0e0da6174Christian Maederinstance Show LibId where
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder show (IndirectLink s1 _ _) = s1
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maederinstance GetRange LibName where
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder getRange = getRange . getLibId
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maederinstance Show LibName where
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder show = show . hsep . prettyLibName
5664bc775d5d61bbd5f71cf05f5c6dd5c63340ffChristian Maeder
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian MaederprettyVersionNumber :: VersionNumber -> [Doc]
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaederprettyVersionNumber (VersionNumber v _) =
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder [keyword versionS, hcat $ punctuate dot $ map codeToken v]
537ae4f09f55d4834e05c54781ba2c8512280324Christian Maeder
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaederprettyLibName :: LibName -> [Doc]
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian MaederprettyLibName (LibName i mv) = pretty i : case mv of
e24ccbc27ab90aa0bdb7064fd42e3bb0e0da6174Christian Maeder Nothing -> []
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder Just v -> prettyVersionNumber v
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder
3fea26a73b8fa69b22dfd2653d8f7bdacb45b9c9Christian Maederinstance Eq LibId where
3fea26a73b8fa69b22dfd2653d8f7bdacb45b9c9Christian Maeder IndirectLink s1 _ _ == IndirectLink s2 _ _ = s1 == s2
e24ccbc27ab90aa0bdb7064fd42e3bb0e0da6174Christian Maeder
3fea26a73b8fa69b22dfd2653d8f7bdacb45b9c9Christian Maederinstance Ord LibId where
e24ccbc27ab90aa0bdb7064fd42e3bb0e0da6174Christian Maeder IndirectLink s1 _ _ <= IndirectLink s2 _ _ = s1 <= s2
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maederinstance Eq LibName where
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder ln1 == ln2 = compare ln1 ln2 == EQ
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maederinstance Ord LibName where
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder compare = comparing getLibId
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maederinstance Pretty LibName where
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder pretty = fsep . prettyLibName
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maederinstance Pretty LibId where
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder pretty = structId . show
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maederdata LinkPath a = LinkPath a [(LibName, Int)] deriving (Ord, Eq)
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maedertype SLinkPath = LinkPath String
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaederconvertFileToLibStr :: FilePath -> String
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaederconvertFileToLibStr = mkLibStr . takeBaseName
3be6a6e42bb49a1f99b0415fbc2e6330ab69e821Christian Maeder
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaederstripLibChars :: String -> String
3be6a6e42bb49a1f99b0415fbc2e6330ab69e821Christian MaederstripLibChars = filter (\ c -> isAlphaNum c || elem c "'_/")
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian MaedermkLibStr :: String -> String
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian MaedermkLibStr = dropWhile (== '/') . stripLibChars
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder