    {-# LANGUAGE FlexibleInstances, OverlappingInstances, UndecidableInstances, Rank2Types, ScopedTypeVariables #-}
    {-# OPTIONS_GHC -fno-warn-orphans #-}
    --------------------------------------------------------------------
    -- | Generic Instance for ToSElem using standard Data.Generic libraries.
    --------------------------------------------------------------------}

    module Text.StringTemplate.GenericStandard() where
    import qualified Data.Map as M
    import Text.StringTemplate.Classes
    import Text.StringTemplate.Instances()
    import Data.Generics.Basics
    import Data.Generics.Aliases
    import qualified Data.ByteString.Char8 as B
    import qualified Data.ByteString.Lazy.Char8 as LB
    -- import qualified System.Time as OldTime
    -- import System.Locale
    -- import Data.Time
    import qualified Data.Text as T
    import qualified Data.Text.Lazy as LT

    gToSElem :: forall a b.(Data a, Stringable b) => a -> SElem b
    gToSElem :: forall a b. (Data a, Stringable b) => a -> SElem b
    gToSElem = (\a
    x ->
                case ((String -> String) -> [String] -> [String]
    forall a b. (a -> b) -> [a] -> [b]
    map String -> String
    stripInitUnder (Constr -> [String]
    constrFields (Constr -> [String]) -> (a -> Constr) -> a -> [String]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> Constr
    forall a. Data a => a -> Constr
    toConstr (a -> [String]) -> a -> [String]
    forall a b. (a -> b) -> a -> b
    $ a
    x)) of
                  [] -> [SElem b] -> SElem b
    forall a. [SElem a] -> SElem a
    LI (String -> SElem b
    forall a. String -> SElem a
    STR (Constr -> String
    showConstr (a -> Constr
    forall a. Data a => a -> Constr
    toConstr a
    x)) SElem b -> [SElem b] -> [SElem b]
    forall a. a -> [a] -> [a]
    :
                            (forall d. Data d => d -> SElem b) -> a -> [SElem b]
    forall a u. Data a => (forall d. Data d => d -> u) -> a -> [u]
    forall u. (forall d. Data d => d -> u) -> a -> [u]
    gmapQ d -> SElem b
    forall d. Data d => d -> SElem b
    forall a b. (Data a, Stringable b) => a -> SElem b
    gToSElem a
    x)
                  [String]
    fs -> SMap b -> SElem b
    forall a. SMap a -> SElem a
    SM ([(String, SElem b)] -> SMap b
    forall k a. Ord k => [(k, a)] -> Map k a
    M.fromList ([String] -> [SElem b] -> [(String, SElem b)]
    forall a b. [a] -> [b] -> [(a, b)]
    zip [String]
    fs ((forall d. Data d => d -> SElem b) -> a -> [SElem b]
    forall a u. Data a => (forall d. Data d => d -> u) -> a -> [u]
    forall u. (forall d. Data d => d -> u) -> a -> [u]
    gmapQ d -> SElem b
    forall d. Data d => d -> SElem b
    forall a b. (Data a, Stringable b) => a -> SElem b
    gToSElem a
    x)))
               )
               (a -> SElem b)
    -> (forall e. Data e => Maybe e -> SElem b) -> a -> SElem b
    forall d (t :: * -> *) q.
    (Data d, Typeable t) =>
    (d -> q) -> (forall e. Data e => t e -> q) -> d -> q
    `ext1Q` (\Maybe e
    t -> case Maybe e
    t of (Just e
    x) -> e -> SElem b
    forall a b. (Data a, Stringable b) => a -> SElem b
    gToSElem e
    x; Maybe e
    _ -> SElem b
    forall a. SElem a
    SNull)
               (a -> SElem b)
    -> (forall e. Data e => Map String e -> SElem b) -> a -> SElem b
    forall d (t :: * -> *) q.
    (Data d, Typeable t) =>
    (d -> q) -> (forall e. Data e => t e -> q) -> d -> q
    `ext1Q` (SMap b -> SElem b
    forall a. SMap a -> SElem a
    SM (SMap b -> SElem b)
    -> (Map String e -> SMap b) -> Map String e -> SElem b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (e -> SElem b) -> Map String e -> SMap b
    forall a b. (a -> b) -> Map String a -> Map String b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap e -> SElem b
    forall a b. (Data a, Stringable b) => a -> SElem b
    gToSElem)
               (a -> SElem b)
    -> (forall e. Data e => [e] -> SElem b) -> a -> SElem b
    forall d (t :: * -> *) q.
    (Data d, Typeable t) =>
    (d -> q) -> (forall e. Data e => t e -> q) -> d -> q
    `ext1Q` ([SElem b] -> SElem b
    forall a. [SElem a] -> SElem a
    LI ([SElem b] -> SElem b) -> ([e] -> [SElem b]) -> [e] -> SElem b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (e -> SElem b) -> [e] -> [SElem b]
    forall a b. (a -> b) -> [a] -> [b]
    map e -> SElem b
    forall a b. (Data a, Stringable b) => a -> SElem b
    gToSElem)
               -- `extQ` (toSElem :: OldTime.CalendarTime -> SElem b)
               -- `extQ` (toSElem :: OldTime.TimeDiff -> SElem b)
               -- `extQ` (toSElem :: TimeOfDay -> SElem b)
               -- `extQ` (toSElem :: UTCTime -> SElem b)
               -- `extQ` (toSElem :: TimeZone -> SElem b)
               -- `extQ` (toSElem :: ZonedTime -> SElem b)
               -- `extQ` (toSElem :: Day -> SElem b)
               -- `extQ` (toSElem :: LocalTime -> SElem b)
               (a -> SElem b) -> (Char -> SElem b) -> a -> SElem b
    forall a b r.
    (Typeable a, Typeable b) =>
    (a -> r) -> (b -> r) -> a -> r
    `extQ` (Char -> SElem b
    forall b. Stringable b => Char -> SElem b
    forall a b. (ToSElem a, Stringable b) => a -> SElem b
    toSElem :: Char -> SElem b)
               (a -> SElem b) -> (ByteString -> SElem b) -> a -> SElem b
    forall a b r.
    (Typeable a, Typeable b) =>
    (a -> r) -> (b -> r) -> a -> r
    `extQ` (ByteString -> SElem b
    forall b. Stringable b => ByteString -> SElem b
    forall a b. (ToSElem a, Stringable b) => a -> SElem b
    toSElem :: LB.ByteString -> SElem b)
               (a -> SElem b) -> (ByteString -> SElem b) -> a -> SElem b
    forall a b r.
    (Typeable a, Typeable b) =>
    (a -> r) -> (b -> r) -> a -> r
    `extQ` (ByteString -> SElem b
    forall b. Stringable b => ByteString -> SElem b
    forall a b. (ToSElem a, Stringable b) => a -> SElem b
    toSElem :: B.ByteString -> SElem b)
               (a -> SElem b) -> (Text -> SElem b) -> a -> SElem b
    forall a b r.
    (Typeable a, Typeable b) =>
    (a -> r) -> (b -> r) -> a -> r
    `extQ` (Text -> SElem b
    forall b. Stringable b => Text -> SElem b
    forall a b. (ToSElem a, Stringable b) => a -> SElem b
    toSElem :: LT.Text -> SElem b)
               (a -> SElem b) -> (Text -> SElem b) -> a -> SElem b
    forall a b r.
    (Typeable a, Typeable b) =>
    (a -> r) -> (b -> r) -> a -> r
    `extQ` (Text -> SElem b
    forall b. Stringable b => Text -> SElem b
    forall a b. (ToSElem a, Stringable b) => a -> SElem b
    toSElem :: T.Text -> SElem b)
               (a -> SElem b) -> (Bool -> SElem b) -> a -> SElem b
    forall a b r.
    (Typeable a, Typeable b) =>
    (a -> r) -> (b -> r) -> a -> r
    `extQ` (Bool -> SElem b
    forall b. Stringable b => Bool -> SElem b
    forall a b. (ToSElem a, Stringable b) => a -> SElem b
    toSElem :: Bool -> SElem b)
               (a -> SElem b) -> (Float -> SElem b) -> a -> SElem b
    forall a b r.
    (Typeable a, Typeable b) =>
    (a -> r) -> (b -> r) -> a -> r
    `extQ` (Float -> SElem b
    forall b. Stringable b => Float -> SElem b
    forall a b. (ToSElem a, Stringable b) => a -> SElem b
    toSElem :: Float -> SElem b)
               (a -> SElem b) -> (Double -> SElem b) -> a -> SElem b
    forall a b r.
    (Typeable a, Typeable b) =>
    (a -> r) -> (b -> r) -> a -> r
    `extQ` (Double -> SElem b
    forall b. Stringable b => Double -> SElem b
    forall a b. (ToSElem a, Stringable b) => a -> SElem b
    toSElem :: Double -> SElem b)
               (a -> SElem b) -> (Int -> SElem b) -> a -> SElem b
    forall a b r.
    (Typeable a, Typeable b) =>
    (a -> r) -> (b -> r) -> a -> r
    `extQ` (Int -> SElem b
    forall b. Stringable b => Int -> SElem b
    forall a b. (ToSElem a, Stringable b) => a -> SElem b
    toSElem :: Int -> SElem b)
               (a -> SElem b) -> (Integer -> SElem b) -> a -> SElem b
    forall a b r.
    (Typeable a, Typeable b) =>
    (a -> r) -> (b -> r) -> a -> r
    `extQ` (Integer -> SElem b
    forall b. Stringable b => Integer -> SElem b
    forall a b. (ToSElem a, Stringable b) => a -> SElem b
    toSElem :: Integer -> SElem b)
               (a -> SElem b) -> (String -> SElem b) -> a -> SElem b
    forall a b r.
    (Typeable a, Typeable b) =>
    (a -> r) -> (b -> r) -> a -> r
    `extQ` (String -> SElem b
    forall b. Stringable b => String -> SElem b
    forall a b. (ToSElem a, Stringable b) => a -> SElem b
    toSElem :: String -> SElem b)

    instance Data a => ToSElem a
        where toSElem :: forall b. Stringable b => a -> SElem b
    toSElem = a -> SElem b
    forall a b. (Data a, Stringable b) => a -> SElem b
    gToSElem

    stripInitUnder :: String -> String
    stripInitUnder :: String -> String
    stripInitUnder (Char
    '_':String
    s) = String -> String
    stripInitUnder String
    s
    stripInitUnder String
    s       = String
    s