From d7be39cd8a16e22f6f8784fdae06c223df5864c1 Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Tue, 12 Nov 2024 10:42:21 -0600 Subject: Writing some basic scaffolding for colors --- src/WWW/Colors/QQ.hs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/WWW/Colors/QQ.hs (limited to 'src/WWW/Colors/QQ.hs') diff --git a/src/WWW/Colors/QQ.hs b/src/WWW/Colors/QQ.hs new file mode 100644 index 0000000..4a03dbb --- /dev/null +++ b/src/WWW/Colors/QQ.hs @@ -0,0 +1,27 @@ +{-# LANGUAGE TemplateHaskell #-} +module WWW.Colors.QQ + ( hex + ) where + +-- import Data.Colour +-- import Data.Colour.SRGB +import Control.Monad ((>=>)) +import Diagrams.Backend.CmdLine (readHexColor) +import Language.Haskell.TH.Quote + + + +-- | QuasiQuoter which reads in a hex color code and ouputs a 'AlphaColour Double'. +hex :: QuasiQuoter +hex = QuasiQuoter + { quoteExp = readHexColor >=> \x -> x `seq` pure [|x|] + , quotePat = failure "quotePat" + , quoteType = failure "quoteType" + , quoteDec = failure "quoteDec" + } where + failure s = const $ fail $ "No " <> s <> " defined for the hexcolor quasiquoter." + -- readit = sRGB24reads :: ReadS (Colour Double) + -- parseit s = + -- case readit s of + -- [(x,[])] -> x `seq` [|x|] + -- _ -> fail $ "Can't understand " <> s <> " as a valid hex color" -- cgit v1.2.3