{-# LANGUAGE DeriveDataTypeable #-}
{- |
Module      :  ./Common/LibName.hs
Description :  library names for DOL and development graphs
Copyright   :  (c) Christian Maeder, DFKI GmbH 2008
License     :  GPLv2 or higher, see LICENSE.txt
Maintainer  :  Christian.Maeder@dfki.de
Stability   :  provisional
Portability :  portable

Abstract syntax of HetCASL/DOL specification library names.
   Follows Sect. II:2.2.5 of the CASL Reference Manual
   and 9.7 of the OMG standard DOL.
-}

module Common.LibName
  ( LibName (LibName, getLibId, locIRI, mimeType, libVersion)
  , VersionNumber (VersionNumber)
  , isQualNameFrom
  , isQualName
  , mkQualName
  , unQualName
  , setFilePath
  , libToFileName
  , libToString
  , getFilePath
  , iriLibName
  , filePathToLibId
  , emptyLibName
  , convertFileToLibStr
  , mkLibStr
  , setMimeType
  , mkLibName
  , libNameToId
  ) where

import Common.Doc
import Common.DocUtils
import Common.Id
import Common.IRI
import Common.Keywords
import Common.Percent
import Common.Utils

import Data.Char
import Data.Data
import Data.List
import Data.Maybe
import Data.Ord

import System.FilePath

omTs :: [Token]
omTs :: [Token]
omTs = [String -> Token
genToken "OM"]

mkQualName :: SIMPLE_ID -> LibName -> Id -> Id
mkQualName :: Token -> LibName -> Id -> Id
mkQualName nodeId :: Token
nodeId ln :: LibName
ln i :: Id
i =
  [Token] -> [Id] -> Range -> Id
Id [Token]
omTs [Id
i, Token -> Id
simpleIdToId Token
nodeId, LibName -> Id
libNameToId LibName
ln] (Range -> Id) -> Range -> Id
forall a b. (a -> b) -> a -> b
$ Id -> Range
posOfId Id
i

isQualNameFrom :: SIMPLE_ID -> LibName -> Id -> Bool
isQualNameFrom :: Token -> LibName -> Id -> Bool
isQualNameFrom nodeId :: Token
nodeId ln :: LibName
ln i :: Id
i@(Id _ cs :: [Id]
cs _) = case [Id]
cs of
  _ : n :: Id
n : l :: Id
l : _ | Id -> Bool
isQualName Id
i ->
    Id
n Id -> Id -> Bool
forall a. Eq a => a -> a -> Bool
== Token -> Id
simpleIdToId Token
nodeId Bool -> Bool -> Bool
&& LibName -> Id
libNameToId LibName
ln Id -> Id -> Bool
forall a. Eq a => a -> a -> Bool
== Id
l
  _ -> Bool
True

isQualName :: Id -> Bool
isQualName :: Id -> Bool
isQualName (Id ts :: [Token]
ts cs :: [Id]
cs _) = case [Id]
cs of
  _ : _ : _ -> [Token]
ts [Token] -> [Token] -> Bool
forall a. Eq a => a -> a -> Bool
== [Token]
omTs
  _ -> Bool
False

unQualName :: Id -> Id
unQualName :: Id -> Id
unQualName j :: Id
j@(Id _ cs :: [Id]
cs _) = case [Id]
cs of
  i :: Id
i : _ | Id -> Bool
isQualName Id
j -> Id
i
  _ -> Id
j

libNameToId :: LibName -> Id
libNameToId :: LibName -> Id
libNameToId ln :: LibName
ln = let
  path :: [String]
path = Char -> String -> [String]
forall a. Eq a => a -> [a] -> [[a]]
splitOn '/' (String -> [String]) -> String -> [String]
forall a b. (a -> b) -> a -> b
$ LibName -> String
libToFileName LibName
ln
  toTok :: String -> Token
toTok s :: String
s = String -> Range -> Token
Token String
s (Range -> Token) -> Range -> Token
forall a b. (a -> b) -> a -> b
$ LibName -> Range
forall a. GetRange a => a -> Range
getRange LibName
ln
  in [Token] -> Id
mkId ([Token] -> Id) -> [Token] -> Id
forall a b. (a -> b) -> a -> b
$ (String -> Token) -> [String] -> [Token]
forall a b. (a -> b) -> [a] -> [b]
map String -> Token
toTok ([String] -> [Token]) -> [String] -> [Token]
forall a b. (a -> b) -> a -> b
$ String -> [String] -> [String]
forall a. a -> [a] -> [a]
intersperse "/" [String]
path

data LibName = LibName
    { LibName -> IRI
getLibId :: IRI
    , LibName -> Maybe IRI
locIRI :: Maybe IRI
    , LibName -> Maybe String
mimeType :: Maybe String
    , LibName -> Maybe VersionNumber
libVersion :: Maybe VersionNumber }
  deriving (Typeable, Typeable LibName
Constr
DataType
Typeable LibName =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> LibName -> c LibName)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c LibName)
-> (LibName -> Constr)
-> (LibName -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c LibName))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LibName))
-> ((forall b. Data b => b -> b) -> LibName -> LibName)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> LibName -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> LibName -> r)
-> (forall u. (forall d. Data d => d -> u) -> LibName -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> LibName -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> LibName -> m LibName)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> LibName -> m LibName)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> LibName -> m LibName)
-> Data LibName
LibName -> Constr
LibName -> DataType
(forall b. Data b => b -> b) -> LibName -> LibName
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> LibName -> c LibName
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c LibName
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> LibName -> u
forall u. (forall d. Data d => d -> u) -> LibName -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> LibName -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> LibName -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> LibName -> m LibName
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> LibName -> m LibName
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c LibName
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> LibName -> c LibName
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c LibName)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LibName)
$cLibName :: Constr
$tLibName :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> LibName -> m LibName
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> LibName -> m LibName
gmapMp :: (forall d. Data d => d -> m d) -> LibName -> m LibName
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> LibName -> m LibName
gmapM :: (forall d. Data d => d -> m d) -> LibName -> m LibName
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> LibName -> m LibName
gmapQi :: Int -> (forall d. Data d => d -> u) -> LibName -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> LibName -> u
gmapQ :: (forall d. Data d => d -> u) -> LibName -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> LibName -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> LibName -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> LibName -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> LibName -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> LibName -> r
gmapT :: (forall b. Data b => b -> b) -> LibName -> LibName
$cgmapT :: (forall b. Data b => b -> b) -> LibName -> LibName
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LibName)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LibName)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c LibName)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c LibName)
dataTypeOf :: LibName -> DataType
$cdataTypeOf :: LibName -> DataType
toConstr :: LibName -> Constr
$ctoConstr :: LibName -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c LibName
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c LibName
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> LibName -> c LibName
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> LibName -> c LibName
$cp1Data :: Typeable LibName
Data)

iriLibName :: IRI -> LibName
iriLibName :: IRI -> LibName
iriLibName i :: IRI
i = IRI -> Maybe IRI -> Maybe String -> Maybe VersionNumber -> LibName
LibName IRI
i Maybe IRI
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing Maybe VersionNumber
forall a. Maybe a
Nothing

mkLibName :: IRI -> Maybe VersionNumber -> LibName
mkLibName :: IRI -> Maybe VersionNumber -> LibName
mkLibName i :: IRI
i v :: Maybe VersionNumber
v = (IRI -> LibName
iriLibName IRI
i) { libVersion :: Maybe VersionNumber
libVersion = Maybe VersionNumber
v }

emptyLibName :: String -> LibName
emptyLibName :: String -> LibName
emptyLibName s :: String
s = IRI -> LibName
iriLibName (IRI -> LibName) -> (Maybe IRI -> IRI) -> Maybe IRI -> LibName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
  IRI -> Maybe IRI -> IRI
forall a. a -> Maybe a -> a
fromMaybe (if String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
s then IRI
nullIRI else String -> IRI
forall a. HasCallStack => String -> a
error (String -> IRI) -> String -> IRI
forall a b. (a -> b) -> a -> b
$ "emptyLibName: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
s)
  (Maybe IRI -> LibName) -> Maybe IRI -> LibName
forall a b. (a -> b) -> a -> b
$ String -> Maybe IRI
parseIRICurie String
s

-- | convert file name to IRI reference
filePathToIri :: FilePath -> IRI
filePathToIri :: String -> IRI
filePathToIri fp :: String
fp = IRI -> Maybe IRI -> IRI
forall a. a -> Maybe a -> a
fromMaybe (String -> IRI
forall a. HasCallStack => String -> a
error (String -> IRI) -> String -> IRI
forall a b. (a -> b) -> a -> b
$ "filePathToIri: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
fp)
  (Maybe IRI -> IRI) -> (String -> Maybe IRI) -> String -> IRI
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Maybe IRI
parseIRIReference (String -> IRI) -> String -> IRI
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> String -> String
encodeBut (\ c :: Char
c -> Char -> Bool
isUnreserved Char
c Bool -> Bool -> Bool
|| Char -> String -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem Char
c String
reserved) String
fp

-- | use file name as library IRI
filePathToLibId :: FilePath -> IRI
filePathToLibId :: String -> IRI
filePathToLibId = Bool -> IRI -> IRI
setAngles Bool
True (IRI -> IRI) -> (String -> IRI) -> String -> IRI
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IRI
filePathToIri

-- | insert file name as location IRI
setFilePath :: FilePath -> LibName -> LibName
setFilePath :: String -> LibName -> LibName
setFilePath fp :: String
fp ln :: LibName
ln = LibName
ln { locIRI :: Maybe IRI
locIRI = IRI -> Maybe IRI
forall a. a -> Maybe a
Just (IRI -> Maybe IRI) -> IRI -> Maybe IRI
forall a b. (a -> b) -> a -> b
$ String -> IRI
filePathToIri String
fp }

-- | insert optional mime type
setMimeType :: Maybe String -> LibName -> LibName
setMimeType :: Maybe String -> LibName -> LibName
setMimeType m :: Maybe String
m ln :: LibName
ln = LibName
ln { mimeType :: Maybe String
mimeType = Maybe String
m }

-- | interpret library IRI as file path
libToFileName :: LibName -> FilePath
libToFileName :: LibName -> String
libToFileName ln :: LibName
ln = let iri :: IRI
iri = LibName -> IRI
getLibId LibName
ln in
  if IRI -> Bool
hasFullIRI IRI
iri then IRI -> String
showIRIFull (IRI -> String) -> (IRI -> IRI) -> IRI -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> IRI -> IRI
setAngles Bool
False (IRI -> String) -> IRI -> String
forall a b. (a -> b) -> a -> b
$ IRI
iri else IRI -> String
showIRI IRI
iri

-- | interpret library IRI as path. Uses CURIE if available.
libToString :: LibName -> String
libToString :: LibName -> String
libToString = IRI -> String
iriToStringUnsecure (IRI -> String) -> (LibName -> IRI) -> LibName -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> IRI -> IRI
setAngles Bool
False (IRI -> IRI) -> (LibName -> IRI) -> LibName -> IRI
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LibName -> IRI
getLibId


-- | extract location IRI as file name
getFilePath :: LibName -> FilePath
getFilePath :: LibName -> String
getFilePath = String -> (IRI -> String) -> Maybe IRI -> String
forall b a. b -> (a -> b) -> Maybe a -> b
maybe "" IRI -> String
iriToStringUnsecure (Maybe IRI -> String)
-> (LibName -> Maybe IRI) -> LibName -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LibName -> Maybe IRI
locIRI

data VersionNumber = VersionNumber [String] Range
  deriving (Typeable, Typeable VersionNumber
Constr
DataType
Typeable VersionNumber =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> VersionNumber -> c VersionNumber)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c VersionNumber)
-> (VersionNumber -> Constr)
-> (VersionNumber -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c VersionNumber))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c VersionNumber))
-> ((forall b. Data b => b -> b) -> VersionNumber -> VersionNumber)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> VersionNumber -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> VersionNumber -> r)
-> (forall u. (forall d. Data d => d -> u) -> VersionNumber -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> VersionNumber -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> VersionNumber -> m VersionNumber)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> VersionNumber -> m VersionNumber)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> VersionNumber -> m VersionNumber)
-> Data VersionNumber
VersionNumber -> Constr
VersionNumber -> DataType
(forall b. Data b => b -> b) -> VersionNumber -> VersionNumber
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> VersionNumber -> c VersionNumber
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c VersionNumber
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> VersionNumber -> u
forall u. (forall d. Data d => d -> u) -> VersionNumber -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> VersionNumber -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> VersionNumber -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> VersionNumber -> m VersionNumber
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> VersionNumber -> m VersionNumber
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c VersionNumber
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> VersionNumber -> c VersionNumber
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c VersionNumber)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c VersionNumber)
$cVersionNumber :: Constr
$tVersionNumber :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> VersionNumber -> m VersionNumber
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> VersionNumber -> m VersionNumber
gmapMp :: (forall d. Data d => d -> m d) -> VersionNumber -> m VersionNumber
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> VersionNumber -> m VersionNumber
gmapM :: (forall d. Data d => d -> m d) -> VersionNumber -> m VersionNumber
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> VersionNumber -> m VersionNumber
gmapQi :: Int -> (forall d. Data d => d -> u) -> VersionNumber -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> VersionNumber -> u
gmapQ :: (forall d. Data d => d -> u) -> VersionNumber -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> VersionNumber -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> VersionNumber -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> VersionNumber -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> VersionNumber -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> VersionNumber -> r
gmapT :: (forall b. Data b => b -> b) -> VersionNumber -> VersionNumber
$cgmapT :: (forall b. Data b => b -> b) -> VersionNumber -> VersionNumber
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c VersionNumber)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c VersionNumber)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c VersionNumber)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c VersionNumber)
dataTypeOf :: VersionNumber -> DataType
$cdataTypeOf :: VersionNumber -> DataType
toConstr :: VersionNumber -> Constr
$ctoConstr :: VersionNumber -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c VersionNumber
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c VersionNumber
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> VersionNumber -> c VersionNumber
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> VersionNumber -> c VersionNumber
$cp1Data :: Typeable VersionNumber
Data)
                    -- pos: "version", start of first string

instance GetRange LibName where
  getRange :: LibName -> Range
getRange = IRI -> Range
forall a. GetRange a => a -> Range
getRange (IRI -> Range) -> (LibName -> IRI) -> LibName -> Range
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LibName -> IRI
getLibId

instance Show LibName where
  show :: LibName -> String
show = Doc -> String
forall a. Show a => a -> String
show (Doc -> String) -> (LibName -> Doc) -> LibName -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Doc] -> Doc
hsep ([Doc] -> Doc) -> (LibName -> [Doc]) -> LibName -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LibName -> [Doc]
prettyLibName

prettyVersionNumber :: VersionNumber -> [Doc]
prettyVersionNumber :: VersionNumber -> [Doc]
prettyVersionNumber (VersionNumber v :: [String]
v _) =
  [String -> Doc
keyword String
versionS, [Doc] -> Doc
hcat ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ Doc -> [Doc] -> [Doc]
punctuate Doc
dot ([Doc] -> [Doc]) -> [Doc] -> [Doc]
forall a b. (a -> b) -> a -> b
$ (String -> Doc) -> [String] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map String -> Doc
codeToken [String]
v]

prettyLibName :: LibName -> [Doc]
prettyLibName :: LibName -> [Doc]
prettyLibName ln :: LibName
ln =
  IRI -> Doc
forall a. Pretty a => a -> Doc
pretty (LibName -> IRI
getLibId LibName
ln) Doc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
: [Doc] -> (VersionNumber -> [Doc]) -> Maybe VersionNumber -> [Doc]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] VersionNumber -> [Doc]
prettyVersionNumber (LibName -> Maybe VersionNumber
libVersion LibName
ln)

instance Eq LibName where
  ln1 :: LibName
ln1 == :: LibName -> LibName -> Bool
== ln2 :: LibName
ln2 = LibName -> LibName -> Ordering
forall a. Ord a => a -> a -> Ordering
compare LibName
ln1 LibName
ln2 Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
== Ordering
EQ

instance Ord LibName where
  compare :: LibName -> LibName -> Ordering
compare = (LibName -> IRI) -> LibName -> LibName -> Ordering
forall a b. Ord a => (b -> a) -> b -> b -> Ordering
comparing LibName -> IRI
getLibId

instance Pretty LibName where
    pretty :: LibName -> Doc
pretty = [Doc] -> Doc
fsep ([Doc] -> Doc) -> (LibName -> [Doc]) -> LibName -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LibName -> [Doc]
prettyLibName

convertFileToLibStr :: FilePath -> String
convertFileToLibStr :: String -> String
convertFileToLibStr = String -> String
mkLibStr (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
takeBaseName

stripLibChars :: String -> String
stripLibChars :: String -> String
stripLibChars = (Char -> Bool) -> String -> String
forall a. (a -> Bool) -> [a] -> [a]
filter (\ c :: Char
c -> Char -> Bool
isAlphaNum Char
c Bool -> Bool -> Bool
|| Char -> String -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem Char
c "'_/")

mkLibStr :: String -> String
mkLibStr :: String -> String
mkLibStr = (Char -> Bool) -> String -> String
forall a. (a -> Bool) -> [a] -> [a]
dropWhile (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '/') (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
stripLibChars