|
3 | 3 | {-# LANGUAGE PatternSynonyms #-}
|
4 | 4 | {-# LANGUAGE RankNTypes #-}
|
5 | 5 | {-# LANGUAGE ScopedTypeVariables #-}
|
| 6 | +{-# LANGUAGE TemplateHaskellQuotes #-} |
| 7 | +{-# LANGUAGE ViewPatterns #-} |
6 | 8 | {-# OPTIONS_GHC -Wno-unused-imports #-}
|
7 | 9 |
|
8 | 10 | -- This template expects CPP definitions for:
|
@@ -175,7 +177,7 @@ import GHC.IO.Encoding.UTF8 ( mkUTF8 )
|
175 | 177 | import qualified System.OsString.Data.ByteString.Short as BSP
|
176 | 178 | #endif
|
177 | 179 | import GHC.Stack (HasCallStack)
|
178 |
| -import Prelude (Bool, Int, Maybe(..), IO, String, Either(..), fmap, ($), (.), mconcat, fromEnum, fromInteger, mempty, fromIntegral, fail, (<$>), show, either, pure, const, flip) |
| 180 | +import Prelude (Bool(..), Int, Maybe(..), IO, String, Either(..), fmap, ($), (.), mconcat, fromEnum, fromInteger, mempty, fromIntegral, fail, (<$>), show, either, pure, const, flip) |
179 | 181 | import Data.Bifunctor ( bimap )
|
180 | 182 | import qualified System.OsString.Data.ByteString.Short.Word16 as BS16
|
181 | 183 | import qualified System.OsString.Data.ByteString.Short as BS8
|
@@ -345,23 +347,25 @@ pstr =
|
345 | 347 | { quoteExp = \s -> do
|
346 | 348 | ps <- either (fail . show) pure $ encodeWith (mkUTF16le ErrorOnCodingFailure) s
|
347 | 349 | lift ps
|
348 |
| - , quotePat = \_ -> |
349 |
| - fail "illegal QuasiQuote (allowed as expression only, used as a pattern)" |
| 350 | + , quotePat = \s -> do |
| 351 | + osp' <- either (fail . show) pure . encodeWith (mkUTF16le ErrorOnCodingFailure) $ s |
| 352 | + [p|((==) osp' -> True)|] |
350 | 353 | , quoteType = \_ ->
|
351 |
| - fail "illegal QuasiQuote (allowed as expression only, used as a type)" |
| 354 | + fail "illegal QuasiQuote (allowed as expression or pattern only, used as a type)" |
352 | 355 | , quoteDec = \_ ->
|
353 |
| - fail "illegal QuasiQuote (allowed as expression only, used as a declaration)" |
| 356 | + fail "illegal QuasiQuote (allowed as expression or pattern only, used as a declaration)" |
354 | 357 | }
|
355 | 358 | #else
|
356 | 359 | { quoteExp = \s -> do
|
357 | 360 | ps <- either (fail . show) pure $ encodeWith (mkUTF8 ErrorOnCodingFailure) s
|
358 | 361 | lift ps
|
359 |
| - , quotePat = \_ -> |
360 |
| - fail "illegal QuasiQuote (allowed as expression only, used as a pattern)" |
| 362 | + , quotePat = \s -> do |
| 363 | + osp' <- either (fail . show) pure . encodeWith (mkUTF8 ErrorOnCodingFailure) $ s |
| 364 | + [p|((==) osp' -> True)|] |
361 | 365 | , quoteType = \_ ->
|
362 |
| - fail "illegal QuasiQuote (allowed as expression only, used as a type)" |
| 366 | + fail "illegal QuasiQuote (allowed as expression or pattern only, used as a type)" |
363 | 367 | , quoteDec = \_ ->
|
364 |
| - fail "illegal QuasiQuote (allowed as expression only, used as a declaration)" |
| 368 | + fail "illegal QuasiQuote (allowed as expression or pattern only, used as a declaration)" |
365 | 369 | }
|
366 | 370 | #endif
|
367 | 371 |
|
|
0 commit comments