From 1c7f639e01825b440cd416aa5cfcce4645522800 Mon Sep 17 00:00:00 2001
From: Julian Ospald <hasufell@posteo.de>
Date: Mon, 11 Dec 2023 17:34:39 +0800
Subject: [PATCH] Allow pstr quasiquoter as pattern too

---
 System/OsPath/Posix.hs   | 11 +++++++----
 System/OsPath/Windows.hs | 11 +++++++----
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/System/OsPath/Posix.hs b/System/OsPath/Posix.hs
index 266e9c3..0c933b0 100644
--- a/System/OsPath/Posix.hs
+++ b/System/OsPath/Posix.hs
@@ -1,4 +1,6 @@
 {-# LANGUAGE CPP #-}
+{-# LANGUAGE TemplateHaskellQuotes #-}
+{-# LANGUAGE ViewPatterns #-}
 
 #undef  WINDOWS
 #define POSIX
@@ -18,10 +20,11 @@ pstr =
       ps <- either (fail . show) pure $ encodeWith (mkUTF8 ErrorOnCodingFailure) s
       when (not $ isValid ps) $ fail ("filepath not valid: " ++ show ps)
       lift ps
-  , quotePat  = \_ ->
-      fail "illegal QuasiQuote (allowed as expression only, used as a pattern)"
+  , quotePat = \s -> do
+      osp' <- either (fail . show) pure . encodeWith (mkUTF8 ErrorOnCodingFailure) $ s
+      [p|((==) osp' -> True)|]
   , quoteType = \_ ->
-      fail "illegal QuasiQuote (allowed as expression only, used as a type)"
+      fail "illegal QuasiQuote (allowed as expression or pattern only, used as a type)"
   , quoteDec  = \_ ->
-      fail "illegal QuasiQuote (allowed as expression only, used as a declaration)"
+      fail "illegal QuasiQuote (allowed as expression or pattern only, used as a declaration)"
   }
diff --git a/System/OsPath/Windows.hs b/System/OsPath/Windows.hs
index 89d6faa..450f16b 100644
--- a/System/OsPath/Windows.hs
+++ b/System/OsPath/Windows.hs
@@ -1,4 +1,6 @@
 {-# LANGUAGE CPP #-}
+{-# LANGUAGE TemplateHaskellQuotes #-}
+{-# LANGUAGE ViewPatterns #-}
 
 #undef  POSIX
 #define IS_WINDOWS True
@@ -19,10 +21,11 @@ pstr =
       ps <- either (fail . show) pure $ encodeWith (mkUTF16le ErrorOnCodingFailure) s
       when (not $ isValid ps) $ fail ("filepath not valid: " ++ show ps)
       lift ps
-  , quotePat  = \_ ->
-      fail "illegal QuasiQuote (allowed as expression only, used as a pattern)"
+  , quotePat = \s -> do
+      osp' <- either (fail . show) pure . encodeWith (mkUTF16le ErrorOnCodingFailure) $ s
+      [p|((==) osp' -> True)|]
   , quoteType = \_ ->
-      fail "illegal QuasiQuote (allowed as expression only, used as a type)"
+      fail "illegal QuasiQuote (allowed as expression or pattern only, used as a type)"
   , quoteDec  = \_ ->
-      fail "illegal QuasiQuote (allowed as expression only, used as a declaration)"
+      fail "illegal QuasiQuote (allowed as expression or pattern only, used as a declaration)"
   }
-- 
GitLab