packages feed

HaskellAnalysisProgram-0.1.0: src/MetaHS/EDSL/Utils.hs

{-|
Module      : MetaHS.EDSL.Utils
Description : The MetaHS EDSL Utils part
Copyright   : Copyright (C) 2017-2019 H.H.R.F. Vos, S. Kamps
License     : -- This file is distributed under the  terms of the Apache License 2.0.
              For more information, see the file "LICENSE", which is included in the distribution.
Stability   : experimental
MetaHS EDSL Utils part
-}
module MetaHS.EDSL.Utils
    ( split
    , isLocal
    , locationToQuery
    ) where

import System.FilePath.Posix (joinPath, splitPath)
import MetaHS.DataModel.Utils (split, isLocal)
import qualified MetaHS.DataModel.MetaModel as MetaModel

-- | Converts a Location Element to a query String suitable for URLs.
--   An empty String is returned if the Element is not a Location Element.
locationToQuery :: MetaModel.Element  -- ^ The Location Element.
                -> String             -- ^ The resulting URL query String or an empty String.
locationToQuery loc@MetaModel.Location{} = concat
    ["?path="           , joinPath . drop 1 . splitPath $ MetaModel.locationPath loc
    ,"&startLine="  , show $ MetaModel.locationStartLine loc
    ,"&startColumn=", show $ MetaModel.locationStartColumn loc
    ,"&endLine="    , show $ MetaModel.locationEndLine loc
    ,"&endColumn="  , show $ MetaModel.locationEndColumn loc
    ]
locationToQuery _ = ""