{-# LANGUAGE CPP #-}

#undef  POSIX
#define IS_WINDOWS True
#define WINDOWS
#define FILEPATH_NAME WindowsPath
#define OSSTRING_NAME WindowsString
#define WORD_NAME WindowsChar

#include "Common.hs"


-- | QuasiQuote a 'WindowsPath'. This accepts Unicode characters
-- and encodes as UTF-16LE. Runs 'isValid' on the input.
pstr :: QuasiQuoter
pstr :: QuasiQuoter
pstr =
  QuasiQuoter :: (String -> Q Exp)
-> (String -> Q Pat)
-> (String -> Q Type)
-> (String -> Q [Dec])
-> QuasiQuoter
QuasiQuoter
  { quoteExp :: String -> Q Exp
quoteExp = \String
s -> do
      WindowsString
ps <- (EncodingException -> Q WindowsString)
-> (WindowsString -> Q WindowsString)
-> Either EncodingException WindowsString
-> Q WindowsString
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (String -> Q WindowsString
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Q WindowsString)
-> (EncodingException -> String)
-> EncodingException
-> Q WindowsString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EncodingException -> String
forall a. Show a => a -> String
show) WindowsString -> Q WindowsString
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either EncodingException WindowsString -> Q WindowsString)
-> Either EncodingException WindowsString -> Q WindowsString
forall a b. (a -> b) -> a -> b
$ TextEncoding -> String -> Either EncodingException WindowsString
encodeWith (CodingFailureMode -> TextEncoding
mkUTF16le CodingFailureMode
ErrorOnCodingFailure) (String -> Either EncodingException WindowsString)
-> String -> Either EncodingException WindowsString
forall a b. (a -> b) -> a -> b
$ String
s
      Bool -> Q () -> Q ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ WindowsString -> Bool
isValid WindowsString
ps) (Q () -> Q ()) -> Q () -> Q ()
forall a b. (a -> b) -> a -> b
$ String -> Q ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"filepath now valid: " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> WindowsString -> String
forall a. Show a => a -> String
show WindowsString
ps)
      WindowsString -> Q Exp
forall t. Lift t => t -> Q Exp
lift WindowsString
ps
  , quotePat :: String -> Q Pat
quotePat  = \String
_ ->
      String -> Q Pat
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"illegal QuasiQuote (allowed as expression only, used as a pattern)"
  , quoteType :: String -> Q Type
quoteType = \String
_ ->
      String -> Q Type
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"illegal QuasiQuote (allowed as expression only, used as a type)"
  , quoteDec :: String -> Q [Dec]
quoteDec  = \String
_ ->
      String -> Q [Dec]
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"illegal QuasiQuote (allowed as expression only, used as a declaration)"
  }