Skip to content

Commit 1c7f639

Browse files
committed
Allow pstr quasiquoter as pattern too
1 parent 2031d91 commit 1c7f639

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

System/OsPath/Posix.hs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE TemplateHaskellQuotes #-}
3+
{-# LANGUAGE ViewPatterns #-}
24

35
#undef WINDOWS
46
#define POSIX
@@ -18,10 +20,11 @@ pstr =
1820
ps <- either (fail . show) pure $ encodeWith (mkUTF8 ErrorOnCodingFailure) s
1921
when (not $ isValid ps) $ fail ("filepath not valid: " ++ show ps)
2022
lift ps
21-
, quotePat = \_ ->
22-
fail "illegal QuasiQuote (allowed as expression only, used as a pattern)"
23+
, quotePat = \s -> do
24+
osp' <- either (fail . show) pure . encodeWith (mkUTF8 ErrorOnCodingFailure) $ s
25+
[p|((==) osp' -> True)|]
2326
, quoteType = \_ ->
24-
fail "illegal QuasiQuote (allowed as expression only, used as a type)"
27+
fail "illegal QuasiQuote (allowed as expression or pattern only, used as a type)"
2528
, quoteDec = \_ ->
26-
fail "illegal QuasiQuote (allowed as expression only, used as a declaration)"
29+
fail "illegal QuasiQuote (allowed as expression or pattern only, used as a declaration)"
2730
}

System/OsPath/Windows.hs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE TemplateHaskellQuotes #-}
3+
{-# LANGUAGE ViewPatterns #-}
24

35
#undef POSIX
46
#define IS_WINDOWS True
@@ -19,10 +21,11 @@ pstr =
1921
ps <- either (fail . show) pure $ encodeWith (mkUTF16le ErrorOnCodingFailure) s
2022
when (not $ isValid ps) $ fail ("filepath not valid: " ++ show ps)
2123
lift ps
22-
, quotePat = \_ ->
23-
fail "illegal QuasiQuote (allowed as expression only, used as a pattern)"
24+
, quotePat = \s -> do
25+
osp' <- either (fail . show) pure . encodeWith (mkUTF16le ErrorOnCodingFailure) $ s
26+
[p|((==) osp' -> True)|]
2427
, quoteType = \_ ->
25-
fail "illegal QuasiQuote (allowed as expression only, used as a type)"
28+
fail "illegal QuasiQuote (allowed as expression or pattern only, used as a type)"
2629
, quoteDec = \_ ->
27-
fail "illegal QuasiQuote (allowed as expression only, used as a declaration)"
30+
fail "illegal QuasiQuote (allowed as expression or pattern only, used as a declaration)"
2831
}

0 commit comments

Comments
 (0)