LibName.hs revision e2e5830e2562de2f9a7daa31704fca25285180f0
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maeder{- |
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian MaederModule : $Header$
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian MaederDescription : library names for HetCASL and development graphs
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian MaederCopyright : (c) Christian Maeder, DFKI GmbH 2008
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian MaederLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian MaederMaintainer : Christian.Maeder@dfki.de
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian MaederStability : provisional
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian MaederPortability : portable
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maeder
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian MaederAbstract syntax of HetCASL specification libraries
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maeder Follows Sect. II:2.2.5 of the CASL Reference Manual.
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maeder-}
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maeder
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maedermodule Common.LibName where
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maeder
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maederimport Common.Doc
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maederimport Common.DocUtils
92dc581bf568c9e225aa9d0570ab0a4b6ebdab69Christian Maederimport Common.Id
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maederimport Common.Keywords
92dc581bf568c9e225aa9d0570ab0a4b6ebdab69Christian Maederimport Common.Utils
92dc581bf568c9e225aa9d0570ab0a4b6ebdab69Christian Maeder
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maederimport Data.List
92dc581bf568c9e225aa9d0570ab0a4b6ebdab69Christian Maederimport System.Time
92dc581bf568c9e225aa9d0570ab0a4b6ebdab69Christian Maeder
0789323dfca89bae8f710da5bba20220b9af2feaChristian MaederomTs :: [Token]
0789323dfca89bae8f710da5bba20220b9af2feaChristian MaederomTs = [genToken "OM"]
0789323dfca89bae8f710da5bba20220b9af2feaChristian Maeder
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian MaedermkQualName :: SIMPLE_ID -> LibId -> Id -> Id
92dc581bf568c9e225aa9d0570ab0a4b6ebdab69Christian MaedermkQualName nodeId libId i =
0789323dfca89bae8f710da5bba20220b9af2feaChristian Maeder Id omTs [i, simpleIdToId nodeId, libIdToId libId] $ posOfId i
0789323dfca89bae8f710da5bba20220b9af2feaChristian Maeder
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian MaederisQualNameFrom :: SIMPLE_ID -> LibId -> Id -> Bool
248ab4f138caa9a594cd3fe0815e7fd4150701efChristian MaederisQualNameFrom nodeId libId i@(Id _ cs _) = case cs of
5dc46f6d0fdd8747d730f9e79a93978145ed43bbChristian Maeder _ : n : l : _ | isQualName i ->
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder n == simpleIdToId nodeId && libIdToId libId == l
5dc46f6d0fdd8747d730f9e79a93978145ed43bbChristian Maeder _ -> True
248ab4f138caa9a594cd3fe0815e7fd4150701efChristian Maeder
0789323dfca89bae8f710da5bba20220b9af2feaChristian MaederisQualName :: Id -> Bool
0789323dfca89bae8f710da5bba20220b9af2feaChristian MaederisQualName (Id ts cs _) = case cs of
0789323dfca89bae8f710da5bba20220b9af2feaChristian Maeder _ : _ : _ -> ts == omTs
0789323dfca89bae8f710da5bba20220b9af2feaChristian Maeder _ -> False
92dc581bf568c9e225aa9d0570ab0a4b6ebdab69Christian Maeder
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian MaederlibIdOfQualName :: Id -> Id
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian MaederlibIdOfQualName j@(Id _ cs _) = case cs of
6df66a8a7be47ca0d9a4d15b89d3380c8e1f4aedEwaryst Schulz [_, _, i] | isQualName j -> i
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder _ -> error "libIdOfQualName: Check by isQualName before calling getLibId!"
6df66a8a7be47ca0d9a4d15b89d3380c8e1f4aedEwaryst Schulz
6df66a8a7be47ca0d9a4d15b89d3380c8e1f4aedEwaryst SchulzgetNodeId :: Id -> Id
6df66a8a7be47ca0d9a4d15b89d3380c8e1f4aedEwaryst SchulzgetNodeId j@(Id _ cs _) = case cs of
6df66a8a7be47ca0d9a4d15b89d3380c8e1f4aedEwaryst Schulz [_, i, _] | isQualName j -> i
6df66a8a7be47ca0d9a4d15b89d3380c8e1f4aedEwaryst Schulz _ -> error "Check by isQualName before calling getNodeId!"
6df66a8a7be47ca0d9a4d15b89d3380c8e1f4aedEwaryst Schulz
6df66a8a7be47ca0d9a4d15b89d3380c8e1f4aedEwaryst Schulz
5dc46f6d0fdd8747d730f9e79a93978145ed43bbChristian MaederunQualName :: Id -> Id
5dc46f6d0fdd8747d730f9e79a93978145ed43bbChristian MaederunQualName j@(Id _ cs _) = case cs of
5dc46f6d0fdd8747d730f9e79a93978145ed43bbChristian Maeder i : _ | isQualName j -> i
5dc46f6d0fdd8747d730f9e79a93978145ed43bbChristian Maeder _ -> j
5dc46f6d0fdd8747d730f9e79a93978145ed43bbChristian Maeder
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian MaederlibIdToId :: LibId -> Id
92dc581bf568c9e225aa9d0570ab0a4b6ebdab69Christian MaederlibIdToId li = let
92dc581bf568c9e225aa9d0570ab0a4b6ebdab69Christian Maeder path = splitOn '/' $ show li
92dc581bf568c9e225aa9d0570ab0a4b6ebdab69Christian Maeder toTok s = Token s $ getRange li
92dc581bf568c9e225aa9d0570ab0a4b6ebdab69Christian Maeder in mkId $ map toTok $ intersperse "/" path
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maeder
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maederdata LibName = LibName
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder { getLibId :: LibId
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder , libVersion :: Maybe VersionNumber }
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maeder
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian MaederemptyLibName :: String -> LibName
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian MaederemptyLibName s = LibName (IndirectLink s nullRange "" noTime) Nothing
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder
b410420153cc9ac37fb4ebb86699cba7fa19bc35Christian Maederdata LibId =
b410420153cc9ac37fb4ebb86699cba7fa19bc35Christian Maeder DirectLink URL Range
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maeder -- pos: start of URL
b410420153cc9ac37fb4ebb86699cba7fa19bc35Christian Maeder | IndirectLink PATH Range FilePath ClockTime
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maeder -- pos: start of PATH
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maeder
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian MaedernoTime :: ClockTime
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian MaedernoTime = TOD 0 0
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maeder
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder-- | Returns the LibId of a LibName
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian MaedergetModTime :: LibId -> ClockTime
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian MaedergetModTime li = case li of
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder DirectLink _ _ -> noTime
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder IndirectLink _ _ _ m -> m
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maeder
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian MaederupdFilePathOfLibId :: FilePath -> ClockTime -> LibId -> LibId
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian MaederupdFilePathOfLibId fp mt li = case li of
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder DirectLink _ _ -> li
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder IndirectLink p r _ _ -> IndirectLink p r fp mt
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maeder
429df04296fa571432f62cbfad6855e1420e0fd6Christian MaedersetFilePath :: FilePath -> ClockTime -> LibName -> LibName
429df04296fa571432f62cbfad6855e1420e0fd6Christian MaedersetFilePath fp mt ln =
429df04296fa571432f62cbfad6855e1420e0fd6Christian Maeder ln { getLibId = updFilePathOfLibId fp mt $ getLibId ln }
429df04296fa571432f62cbfad6855e1420e0fd6Christian Maeder
b410420153cc9ac37fb4ebb86699cba7fa19bc35Christian Maederdata VersionNumber = VersionNumber [String] Range
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maeder -- pos: "version", start of first string
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maeder
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maedertype URL = String
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maedertype PATH = String
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maeder
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maederinstance GetRange LibId where
92dc581bf568c9e225aa9d0570ab0a4b6ebdab69Christian Maeder getRange li = case li of
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder DirectLink _ r -> r
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder IndirectLink _ r _ _ -> r
92dc581bf568c9e225aa9d0570ab0a4b6ebdab69Christian Maeder
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maederinstance Show LibId where
92dc581bf568c9e225aa9d0570ab0a4b6ebdab69Christian Maeder show li = case li of
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder DirectLink s _ -> s
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder IndirectLink s1 _ _ _ -> s1
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maeder
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maederinstance GetRange LibName where
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder getRange = getRange . getLibId
14d7908303969441ba30c2748de45f20345c6b31Christian Maeder
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maederinstance Show LibName where
54a535fb81b928ac8f99a11bdcfa8998533204a5Christian Maeder show = show . hsep . prettyLibName
b410420153cc9ac37fb4ebb86699cba7fa19bc35Christian Maeder
b410420153cc9ac37fb4ebb86699cba7fa19bc35Christian MaederprettyVersionNumber :: VersionNumber -> [Doc]
b410420153cc9ac37fb4ebb86699cba7fa19bc35Christian MaederprettyVersionNumber (VersionNumber v _) =
b410420153cc9ac37fb4ebb86699cba7fa19bc35Christian Maeder [keyword versionS, hcat $ punctuate dot $ map codeToken v]
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maeder
54a535fb81b928ac8f99a11bdcfa8998533204a5Christian MaederprettyLibName :: LibName -> [Doc]
54a535fb81b928ac8f99a11bdcfa8998533204a5Christian MaederprettyLibName (LibName i mv) = pretty i : case mv of
54a535fb81b928ac8f99a11bdcfa8998533204a5Christian Maeder Nothing -> []
54a535fb81b928ac8f99a11bdcfa8998533204a5Christian Maeder Just v -> prettyVersionNumber v
54a535fb81b928ac8f99a11bdcfa8998533204a5Christian Maeder
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maederinstance Eq LibId where
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder DirectLink s1 _ == DirectLink s2 _ = s1 == s2
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder IndirectLink s1 _ _ _ == IndirectLink s2 _ _ _ = s1 == s2
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maeder _ == _ = False
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maeder
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maederinstance Ord LibId where
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder DirectLink s1 _ <= DirectLink s2 _ = s1 <= s2
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder IndirectLink s1 _ _ _ <= IndirectLink s2 _ _ _ = s1 <= s2
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder DirectLink _ _ <= _ = True
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder IndirectLink _ _ _ _ <= _ = False
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maeder
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maederinstance Eq LibName where
248ab4f138caa9a594cd3fe0815e7fd4150701efChristian Maeder ln1 == ln2 = compare ln1 ln2 == EQ
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maeder
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maederinstance Ord LibName where
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder compare ln1 ln2 = compare (getLibId ln1) $ getLibId ln2
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maeder
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maederinstance Pretty LibName where
54a535fb81b928ac8f99a11bdcfa8998533204a5Christian Maeder pretty = fsep . prettyLibName
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maeder
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maederinstance Pretty LibId where
54a535fb81b928ac8f99a11bdcfa8998533204a5Christian Maeder pretty = structId . show
54a535fb81b928ac8f99a11bdcfa8998533204a5Christian Maeder
e2e5830e2562de2f9a7daa31704fca25285180f0Ewaryst Schulztype LinkPath a = (a, [(LibId, Int)])
e2e5830e2562de2f9a7daa31704fca25285180f0Ewaryst Schulz
e2e5830e2562de2f9a7daa31704fca25285180f0Ewaryst SchulzshowLinkPath :: LinkPath a -> String
e2e5830e2562de2f9a7daa31704fca25285180f0Ewaryst SchulzshowLinkPath (x, ((_, n):l)) = showLinkPath (x, l) ++ "/" ++ show n
e2e5830e2562de2f9a7daa31704fca25285180f0Ewaryst SchulzshowLinkPath _ = ""
e2e5830e2562de2f9a7daa31704fca25285180f0Ewaryst Schulz
e2e5830e2562de2f9a7daa31704fca25285180f0Ewaryst Schulz{-
e2e5830e2562de2f9a7daa31704fca25285180f0Ewaryst Schulzinstance Show a => Show (LinkPath a) where
e2e5830e2562de2f9a7daa31704fca25285180f0Ewaryst Schulz show (LinkPath x ((li, n):l)) = show (LinkPath x l) ++ "/" ++ show n
e2e5830e2562de2f9a7daa31704fca25285180f0Ewaryst Schulz show _ = ""
e2e5830e2562de2f9a7daa31704fca25285180f0Ewaryst Schulz
e2e5830e2562de2f9a7daa31704fca25285180f0Ewaryst Schulzinstance Functor LinkPath where
e2e5830e2562de2f9a7daa31704fca25285180f0Ewaryst Schulz fmap f (LinkPath x l) = LinkPath (f x) l
e2e5830e2562de2f9a7daa31704fca25285180f0Ewaryst Schulz-}