{-# OPTIONS_GHC -Wno-orphans #-}{-# LANGUAGE CPP #-}{-# LANGUAGE DeriveDataTypeable #-}{-# LANGUAGE DeriveLift #-}{-# LANGUAGE FlexibleInstances #-}{-# LANGUAGE StandaloneDeriving #-}{-# LANGUAGE TemplateHaskellQuotes #-}{-|Module : GHCup.Utils.Version.QQDescription : Version quasi-quotersCopyright : (c) Julian Ospald, 2020License : LGPL-3.0Maintainer : hasufell@hasufell.deStability : experimentalPortability : portable-}module GHCup.Prelude.Version.QQ whereimport Data.Dataimport Data.Text ( Text )import Data.Versions#if !MIN_VERSION_base(4,13,0)import GHC.Base#endifimport qualified Data.Text as Timport Language.Haskell.THimport Language.Haskell.TH.Quote ( QuasiQuoter (..) )import Language.Haskell.TH.Syntax ( dataToExpQ )import qualified Language.Haskell.TH.Syntax as TH#if !MIN_VERSION_base(4,13,0)deriving instance Lift (NonEmpty Word)deriving instance Lift (NonEmpty MChunk)#endifqq :: (Text -> Q Exp) -> QuasiQuoterqq quoteExp' = QuasiQuoter { quoteExp = \s -> quoteExp' . T.pack $ s , quotePat = \_ -> fail "illegal QuasiQuote (allowed as expression only, used as a pattern)" , quoteType = \_ -> fail "illegal QuasiQuote (allowed as expression only, used as a type)" , quoteDec = \_ -> fail "illegal QuasiQuote (allowed as expression only, used as a declaration)" }vver :: QuasiQuotervver = qq mkV where mkV :: Text -> Q Exp mkV = either (fail . show) liftDataWithText . versionmver :: QuasiQuotermver = qq mkV where mkV :: Text -> Q Exp mkV = either (fail . show) liftDataWithText . messsver :: QuasiQuotersver = qq mkV where mkV :: Text -> Q Exp mkV = either (fail . show) liftDataWithText . semververs :: QuasiQuotervers = qq mkV where mkV :: Text -> Q Exp mkV = either (fail . show) liftDataWithText . versioningpver :: QuasiQuoterpver = qq mkV where mkV :: Text -> Q Exp mkV = either (fail . show) liftDataWithText . pvp-- https://stackoverflow.com/questions/38143464/cant-find-inerface-file-declaration-for-variableliftText :: T.Text -> Q ExpliftText txt = AppE (VarE 'T.pack) <$> TH.lift (T.unpack txt)liftDataWithText :: Data a => a -> Q ExpliftDataWithText = dataToExpQ (fmap liftText . cast)