Skip to content

Commit

Permalink
Allow pstr quasiquoter as pattern too
Browse files Browse the repository at this point in the history
  • Loading branch information
hasufell committed Dec 11, 2023
1 parent 2031d91 commit 1c7f639
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
11 changes: 7 additions & 4 deletions System/OsPath/Posix.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE TemplateHaskellQuotes #-}
{-# LANGUAGE ViewPatterns #-}

#undef WINDOWS
#define POSIX
Expand All @@ -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)"
}
11 changes: 7 additions & 4 deletions System/OsPath/Windows.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE TemplateHaskellQuotes #-}
{-# LANGUAGE ViewPatterns #-}

#undef POSIX
#define IS_WINDOWS True
Expand All @@ -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)"
}

0 comments on commit 1c7f639

Please sign in to comment.