LibName.hs revision 720eeee7c9d8442093c8d05bed743193eee906e0
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 SchulzAbstract syntax of HetCASL specification libraries
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst Schulz Follows Sect. II:2.2.5 of the CASL Reference Manual.
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst Schulz ( LibName (LibName)
de8eee2014437ec4020be15cd363257f87e79943Christian Maeder , LibId (IndirectLink)
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst Schulz , VersionNumber (VersionNumber)
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder , LinkPath (LinkPath)
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder , isQualNameFrom
c7f1a9b3811f1ed427c57559d9af26a75a309ff1Ewaryst Schulz , setFilePath
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder , getFilePath
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst Schulz , emptyLibName
91b3147021cbeebb0590f4a577acba73142785c5Christian Maeder , convertFileToLibStr
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaederomTs :: [Token]
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian MaederomTs = [genToken "OM"]
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaedermkQualName :: SIMPLE_ID -> LibName -> Id -> Id
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaedermkQualName nodeId ln i =
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder Id omTs [i, simpleIdToId nodeId, libNameToId ln] $ posOfId i
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 MaederisQualName :: Id -> Bool
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaederisQualName (Id ts cs _) = case cs of
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder _ : _ : _ -> ts == omTs
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian MaederunQualName :: Id -> Id
e24ccbc27ab90aa0bdb7064fd42e3bb0e0da6174Christian MaederunQualName j@(Id _ cs _) = case cs of
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder i : _ | isQualName j -> i
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
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maederdata LibName = LibName
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder { getLibId :: LibId
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder , _libVersion :: Maybe VersionNumber }
3fea26a73b8fa69b22dfd2653d8f7bdacb45b9c9Christian MaederemptyLibName :: String -> LibName
3fea26a73b8fa69b22dfd2653d8f7bdacb45b9c9Christian MaederemptyLibName s = LibName (IndirectLink s nullRange "") Nothing
6c244f12ab0dc7ba1baf1413266093886a570e13Christian Maederdata LibId = IndirectLink PATH Range FilePath
3fea26a73b8fa69b22dfd2653d8f7bdacb45b9c9Christian Maeder -- pos: start of PATH
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaederupdFilePathOfLibId :: FilePath -> LibId -> LibId
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaederupdFilePathOfLibId fp (IndirectLink p r _) = IndirectLink p r fp
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian MaedersetFilePath :: FilePath -> LibName -> LibName
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaedersetFilePath fp ln =
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder ln { getLibId = updFilePathOfLibId fp $ getLibId ln }
5b68f1141555736e0b7ddbe14218bcabcc44636fChristian MaedergetFilePath :: LibName -> FilePath
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaedergetFilePath ln =
5b68f1141555736e0b7ddbe14218bcabcc44636fChristian Maeder case getLibId ln of
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder IndirectLink _ _ fp -> fp
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maederdata VersionNumber = VersionNumber [String] Range
1fd936f22c745583ff70fd7ff6e3397f6bcf3fd9Marcel Zirbel -- pos: "version", start of first string
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maedertype PATH = String
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maederinstance GetRange LibId where
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder getRange (IndirectLink _ r _) = r
e24ccbc27ab90aa0bdb7064fd42e3bb0e0da6174Christian Maederinstance Show LibId where
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder show (IndirectLink s1 _ _) = s1
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maederinstance GetRange LibName where
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder getRange = getRange . getLibId
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maederinstance Show LibName where
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder show = show . hsep . prettyLibName
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian MaederprettyVersionNumber :: VersionNumber -> [Doc]
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaederprettyVersionNumber (VersionNumber v _) =
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder [keyword versionS, hcat $ punctuate dot $ map codeToken v]
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaederprettyLibName :: LibName -> [Doc]
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian MaederprettyLibName (LibName i mv) = pretty i : case mv of
e24ccbc27ab90aa0bdb7064fd42e3bb0e0da6174Christian Maeder Nothing -> []
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder Just v -> prettyVersionNumber v
3fea26a73b8fa69b22dfd2653d8f7bdacb45b9c9Christian Maederinstance Eq LibId where
3fea26a73b8fa69b22dfd2653d8f7bdacb45b9c9Christian Maeder IndirectLink s1 _ _ == IndirectLink s2 _ _ = s1 == s2
3fea26a73b8fa69b22dfd2653d8f7bdacb45b9c9Christian Maederinstance Ord LibId where
e24ccbc27ab90aa0bdb7064fd42e3bb0e0da6174Christian Maeder IndirectLink s1 _ _ <= IndirectLink s2 _ _ = s1 <= s2
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maederinstance Eq LibName where
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder ln1 == ln2 = compare ln1 ln2 == EQ
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maederinstance Ord LibName where
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder compare = comparing getLibId
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maederinstance Pretty LibName where
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder pretty = fsep . prettyLibName
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maederinstance Pretty LibId where
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder pretty = structId . show
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maederdata LinkPath a = LinkPath a [(LibName, Int)] deriving (Ord, Eq)
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maedertype SLinkPath = LinkPath String
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaederconvertFileToLibStr :: FilePath -> String
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaederconvertFileToLibStr = mkLibStr . takeBaseName
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaederstripLibChars :: String -> String
3be6a6e42bb49a1f99b0415fbc2e6330ab69e821Christian MaederstripLibChars = filter (\ c -> isAlphaNum c || elem c "'_/")
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian MaedermkLibStr :: String -> String
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian MaedermkLibStr = dropWhile (== '/') . stripLibChars