From 7e8a779adbf5f82543e7081e67ea2c57398e0923 Mon Sep 17 00:00:00 2001 From: Olle Fredriksson Date: Mon, 22 Jan 2024 22:22:50 +0100 Subject: [PATCH] wip --- src/UTF8.hs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/UTF8.hs diff --git a/src/UTF8.hs b/src/UTF8.hs new file mode 100644 index 0000000..b592ee4 --- /dev/null +++ b/src/UTF8.hs @@ -0,0 +1,31 @@ +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE OverloadedStrings #-} + +module UTF8 where + +import qualified Data.Char as Char +import qualified Data.Text.Internal.Encoding.Utf8 as Utf8 +import qualified Language.Haskell.TH.Lib as TH +import Language.Haskell.TH.Quote +import Protolude + +unit1 :: QuasiQuoter +unit1 = + QuasiQuoter + { quoteExp = \case + [c] + | word8 <- fromIntegral $ Char.ord c + , Utf8.validate1 word8 -> + TH.litE $ TH.integerL $ fromIntegral word8 + _ -> + panic "UTF8.unit1 needs a single char" + , quotePat = \case + [c] + | word8 <- fromIntegral $ Char.ord c + , Utf8.validate1 word8 -> + TH.litP $ TH.integerL $ fromIntegral word8 + _ -> + panic "UTF8.unit1 needs a single char" + , quoteType = panic "UTF8.unit1 quoteType" + , quoteDec = panic "UTF8.unit1 quoteDec" + }