Readd TH constructors

This commit is contained in:
Julian Ospald 2016-04-05 00:54:36 +02:00
parent bd71947b2a
commit 8c1bd139c0
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
2 changed files with 41 additions and 0 deletions

View File

@ -21,6 +21,7 @@ library
, exceptions
, deepseq
, word8
, template-haskell
test-suite test
type: exitcode-stdio-1.0

View File

@ -11,6 +11,7 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE PatternSynonyms #-}
@ -32,6 +33,10 @@ module HPath
,parseAbs
,parseFn
,parseRel
-- * Path Constructors
,mkAbs
,mkFn
,mkRel
-- * Path Conversion
,canonicalizePath
,fromAbs
@ -93,6 +98,8 @@ import Foreign.C.String
import Foreign.Marshal.Alloc(allocaBytes)
import HPath.Foreign
import HPath.Internal
import Language.Haskell.TH
--------------------------------------------------------------------------------
-- Types
@ -167,6 +174,39 @@ parseFn filepath =
else throwM (InvalidFn filepath)
--------------------------------------------------------------------------------
-- Constructors
-- | Make a 'Path Abs TPS'.
--
-- Remember: due to the nature of absolute paths this (e.g. @\/home\/foo@)
-- may compile on your platform, but it may not compile on another
-- platform (Windows).
mkAbs :: ByteString -> Q Exp
mkAbs s =
case parseAbs s of
Left err -> error (show err)
Right (MkPath str) ->
[|MkPath $(return (LitE (StringL (show str)))) :: Path Abs|]
-- | Make a 'Path Rel TPS'.
mkRel :: ByteString -> Q Exp
mkRel s =
case parseRel s of
Left err -> error (show err)
Right (MkPath str) ->
[|MkPath $(return (LitE (StringL (show str)))) :: Path Rel|]
-- | Make a 'Path Rel TPS'.
mkFn :: ByteString -> Q Exp
mkFn s =
case parseFn s of
Left err -> error (show err)
Right (MkPath str) ->
[|MkPath $(return (LitE (StringL (show str)))) :: Path Fn|]
--------------------------------------------------------------------------------
-- Path Conversion