module TextShow.Language.Haskell.TH (
#if MIN_VERSION_template_haskell(2,9,0)
showbAnnLookupPrec
, showbAnnTargetPrec,
#endif
#if MIN_VERSION_template_haskell(2,11,0)
showbBangPrec,
#endif
showbBodyPrec
, showbCallconv
#if MIN_VERSION_template_haskell(2,5,0) && !(MIN_VERSION_template_haskell(2,7,0))
, showbClassInstancePrec
#endif
, showbClausePrec
, showbConPrec
#if MIN_VERSION_template_haskell(2,11,0)
, showbDecidedStrictness
#endif
, showbDecPrec
, showbExpPrec
, showbFamFlavour
#if MIN_VERSION_template_haskell(2,11,0)
, showbFamilyResultSigPrec
#endif
, showbFixityPrec
, showbFixityDirection
, showbForeignPrec
, showbFunDepPrec
, showbGuardPrec
, showbInfoPrec
#if MIN_VERSION_template_haskell(2,11,0)
, showbInjectivityAnnPrec
#endif
#if MIN_VERSION_template_haskell(2,8,0)
, showbInline
#else
, showbInlineSpecPrec
#endif
, showbKindPrec
, showbLitPrec
, showbLocPrec
, showbMatchPrec
, showbModNamePrec
#if MIN_VERSION_template_haskell(2,9,0)
, showbModulePrec
, showbModuleInfoPrec
#endif
, showbName
, showbName'
, showbOccNamePrec
, showbPatPrec
#if MIN_VERSION_template_haskell(2,8,0)
, showbPhasesPrec
#endif
, showbPkgNamePrec
, showbPragmaPrec
, showbPredPrec
, showbRangePrec
#if MIN_VERSION_template_haskell(2,9,0)
, showbRole
#endif
#if MIN_VERSION_template_haskell(2,8,0)
, showbRuleBndrPrec
, showbRuleMatch
#endif
, showbSafety
#if MIN_VERSION_template_haskell(2,11,0)
, showbSourceStrictness
, showbSourceUnpackedness
#endif
, showbStmtPrec
, showbStrictPrec
#if MIN_VERSION_template_haskell(2,11,0)
, showbTypeFamilyHeadPrec
#endif
#if MIN_VERSION_template_haskell(2,8,0)
, showbTyLitPrec
#endif
, showbTypePrec
#if MIN_VERSION_template_haskell(2,9,0)
, showbTySynEqnPrec
#endif
, showbTyVarBndrPrec
, showbDoc
) where
import Data.Char (isAlpha)
import Data.Maybe (fromJust)
import Data.Monoid.Compat
import qualified Data.Text.Lazy as TL (Text, dropWhile, null, tail)
import Data.Text.Lazy (uncons)
#if !(MIN_VERSION_template_haskell(2,10,0))
import GHC.Exts (Int(I#))
#endif
import Language.Haskell.TH.PprLib (Doc, to_HPJ_Doc)
import Language.Haskell.TH.Syntax
import TextShow (TextShow(..), Builder,
fromString, singleton, toLazyText)
import TextShow.Data.Integral (showbIntPrec)
import TextShow.Text.PrettyPrint (renderB)
import TextShow.TH (deriveTextShow)
showbBodyPrec :: Int -> Body -> Builder
showbBodyPrec = showbPrec
showbCallconv :: Callconv -> Builder
showbCallconv = showb
showbClausePrec :: Int -> Clause -> Builder
showbClausePrec = showbPrec
showbConPrec :: Int -> Con -> Builder
showbConPrec = showbPrec
showbDecPrec :: Int -> Dec -> Builder
showbDecPrec = showbPrec
showbExpPrec :: Int -> Exp -> Builder
showbExpPrec = showbPrec
showbFamFlavour :: FamFlavour -> Builder
showbFamFlavour = showb
showbFixityPrec :: Int -> Fixity -> Builder
showbFixityPrec = showbPrec
showbFixityDirection :: FixityDirection -> Builder
showbFixityDirection = showb
showbForeignPrec :: Int -> Foreign -> Builder
showbForeignPrec = showbPrec
showbFunDepPrec :: Int -> FunDep -> Builder
showbFunDepPrec = showbPrec
showbGuardPrec :: Int -> Guard -> Builder
showbGuardPrec = showbPrec
showbInfoPrec :: Int -> Info -> Builder
showbInfoPrec = showbPrec
showbKindPrec :: Int -> Kind -> Builder
#if MIN_VERSION_template_haskell(2,8,0)
showbKindPrec = showbTypePrec
#else
showbKindPrec = showbPrec
#endif
showbLitPrec :: Int -> Dec -> Builder
showbLitPrec = showbPrec
showbLocPrec :: Int -> Loc -> Builder
showbLocPrec = showbPrec
showbMatchPrec :: Int -> Match -> Builder
showbMatchPrec = showbPrec
showbModNamePrec :: Int -> ModName -> Builder
showbModNamePrec = showbPrec
showbName :: Name -> Builder
showbName = showbName' Alone
showbName' :: NameIs -> Name -> Builder
showbName' ni nm = case ni of
Alone -> nms
Applied
| pnam -> nms
| otherwise -> singleton '(' <> nms <> singleton ')'
Infix
| pnam -> singleton '`' <> nms <> singleton '`'
| otherwise -> nms
where
nms :: Builder
nms = case nm of
Name occ NameS -> occB occ
Name occ (NameQ m) -> modB m <> singleton '.' <> occB occ
Name occ (NameG _ _ m) -> modB m <> singleton '.' <> occB occ
Name occ (NameU u) -> occB occ <> singleton '_' <> showbIntPrec 0 (mkInt u)
Name occ (NameL u) -> occB occ <> singleton '_' <> showbIntPrec 0 (mkInt u)
#if MIN_VERSION_template_haskell(2,10,0)
mkInt = id
#else
mkInt i# = I# i#
#endif
occB :: OccName -> Builder
occB = fromString . occString
modB :: ModName -> Builder
modB = fromString . modString
pnam :: Bool
pnam = classify $ toLazyText nms
classify :: TL.Text -> Bool
classify t
| TL.null t = False
| otherwise = case fromJust $ uncons t of
(x, xs) -> if isAlpha x || (x `elem` "_[]()")
then let t' = TL.dropWhile (/= '.') xs
in if TL.null t'
then True
else classify $ TL.tail t'
else False
showbOccNamePrec :: Int -> OccName -> Builder
showbOccNamePrec = showbPrec
showbPatPrec :: Int -> Pat -> Builder
showbPatPrec = showbPrec
showbPkgNamePrec :: Int -> PkgName -> Builder
showbPkgNamePrec = showbPrec
showbPragmaPrec :: Int -> Pragma -> Builder
showbPragmaPrec = showbPrec
showbPredPrec :: Int -> Pred -> Builder
#if MIN_VERSION_template_haskell(2,10,0)
showbPredPrec = showbTypePrec
#else
showbPredPrec = showbPrec
#endif
showbRangePrec :: Int -> Range -> Builder
showbRangePrec = showbPrec
showbSafety :: Safety -> Builder
showbSafety = showb
showbStmtPrec :: Int -> Stmt -> Builder
showbStmtPrec = showbPrec
showbStrictPrec :: Int -> Strict -> Builder
#if MIN_VERSION_template_haskell(2,11,0)
showbStrictPrec = showbBangPrec
#else
showbStrictPrec = showbPrec
#endif
showbTypePrec :: Int -> Type -> Builder
showbTypePrec = showbPrec
showbTyVarBndrPrec :: Int -> TyVarBndr -> Builder
showbTyVarBndrPrec = showbPrec
showbDoc :: Doc -> Builder
showbDoc = renderB . to_HPJ_Doc
#if MIN_VERSION_template_haskell(2,5,0) && !(MIN_VERSION_template_haskell(2,7,0))
showbClassInstancePrec :: Int -> ClassInstance -> Builder
showbClassInstancePrec = showbPrec
#endif
#if MIN_VERSION_template_haskell(2,8,0)
showbInline :: Inline -> Builder
showbInline = showb
showbPhasesPrec :: Int -> Phases -> Builder
showbPhasesPrec = showbPrec
showbRuleMatch :: RuleMatch -> Builder
showbRuleMatch = showb
showbRuleBndrPrec :: Int -> RuleBndr -> Builder
showbRuleBndrPrec = showbPrec
showbTyLitPrec :: Int -> TyLit -> Builder
showbTyLitPrec = showbPrec
#else
showbInlineSpecPrec :: Int -> InlineSpec -> Builder
showbInlineSpecPrec = showbPrec
#endif
#if MIN_VERSION_template_haskell(2,9,0)
showbAnnLookupPrec :: Int -> AnnLookup -> Builder
showbAnnLookupPrec = showbPrec
showbAnnTargetPrec :: Int -> AnnTarget -> Builder
showbAnnTargetPrec = showbPrec
showbModulePrec :: Int -> Module -> Builder
showbModulePrec = showbPrec
showbModuleInfoPrec :: Int -> ModuleInfo -> Builder
showbModuleInfoPrec = showbPrec
showbRole :: Role -> Builder
showbRole = showb
showbTySynEqnPrec :: Int -> TySynEqn -> Builder
showbTySynEqnPrec = showbPrec
#endif
#if MIN_VERSION_template_haskell(2,11,0)
showbBangPrec :: Int -> Bang -> Builder
showbBangPrec = showbPrec
showbDecidedStrictness :: DecidedStrictness -> Builder
showbDecidedStrictness = showb
showbFamilyResultSigPrec :: Int -> FamilyResultSig -> Builder
showbFamilyResultSigPrec = showbPrec
showbInjectivityAnnPrec :: Int -> InjectivityAnn -> Builder
showbInjectivityAnnPrec = showbPrec
showbSourceStrictness :: SourceStrictness -> Builder
showbSourceStrictness = showb
showbSourceUnpackedness :: SourceUnpackedness -> Builder
showbSourceUnpackedness = showb
showbTypeFamilyHeadPrec :: Int -> TypeFamilyHead -> Builder
showbTypeFamilyHeadPrec = showbPrec
#endif
$(deriveTextShow ''Body)
$(deriveTextShow ''Callconv)
$(deriveTextShow ''Clause)
$(deriveTextShow ''Con)
$(deriveTextShow ''Dec)
$(deriveTextShow ''Exp)
$(deriveTextShow ''FamFlavour)
$(deriveTextShow ''Fixity)
$(deriveTextShow ''FixityDirection)
$(deriveTextShow ''Foreign)
$(deriveTextShow ''FunDep)
$(deriveTextShow ''Guard)
$(deriveTextShow ''Info)
$(deriveTextShow ''Lit)
$(deriveTextShow ''Loc)
$(deriveTextShow ''Match)
$(deriveTextShow ''ModName)
instance TextShow Name where
showb = showbName
$(deriveTextShow ''OccName)
$(deriveTextShow ''Pat)
$(deriveTextShow ''PkgName)
$(deriveTextShow ''Pragma)
$(deriveTextShow ''Range)
$(deriveTextShow ''Safety)
$(deriveTextShow ''Stmt)
$(deriveTextShow ''Type)
$(deriveTextShow ''TyVarBndr)
instance TextShow Doc where
showb = showbDoc
#if MIN_VERSION_template_haskell(2,5,0) && !(MIN_VERSION_template_haskell(2,7,0))
$(deriveTextShow ''ClassInstance)
#endif
#if MIN_VERSION_template_haskell(2,8,0)
$(deriveTextShow ''Inline)
$(deriveTextShow ''Phases)
$(deriveTextShow ''RuleBndr)
$(deriveTextShow ''RuleMatch)
$(deriveTextShow ''TyLit)
#else
$(deriveTextShow ''InlineSpec)
$(deriveTextShow ''Kind)
#endif
#if MIN_VERSION_template_haskell(2,9,0)
$(deriveTextShow ''AnnLookup)
$(deriveTextShow ''AnnTarget)
$(deriveTextShow ''Module)
$(deriveTextShow ''ModuleInfo)
$(deriveTextShow ''Role)
$(deriveTextShow ''TySynEqn)
#endif
#if !(MIN_VERSION_template_haskell(2,10,0))
$(deriveTextShow ''Pred)
#endif
#if MIN_VERSION_template_haskell(2,11,0)
$(deriveTextShow ''Bang)
$(deriveTextShow ''DecidedStrictness)
$(deriveTextShow ''FamilyResultSig)
$(deriveTextShow ''InjectivityAnn)
$(deriveTextShow ''SourceStrictness)
$(deriveTextShow ''SourceUnpackedness)
$(deriveTextShow ''TypeFamilyHead)
#else
$(deriveTextShow ''Strict)
#endif