    {-# LANGUAGE RelaxedPolyRec, DeriveDataTypeable #-}
    {-# OPTIONS_HADDOCK not-home #-}

    module Text.StringTemplate.Base
        (StringTemplate(..), StringTemplateShows(..), ToSElem(..), STGroup,
         Stringable(..), stShowsToSE, inSGen,
         toString, toPPDoc, render, newSTMP, newAngleSTMP,
         getStringTemplate, getStringTemplate',
         setAttribute, setManyAttrib,
         setNativeAttribute, setManyNativeAttrib,
         withContext, optInsertTmpl, setEncoder,
         paddedTrans, SEnv(..), parseSTMP, dumpAttribs,
         checkTemplate, checkTemplateDeep,
         parseSTMPNames
        ) where
    import Control.Arrow
    import Control.Applicative hiding ((<|>),many,optional)
    import Control.Monad
    import Control.DeepSeq
    import qualified Control.Exception as C
    import Data.List
    import Data.Maybe
    import Data.Monoid
    import Data.Typeable
    import System.IO.Unsafe

    import Text.ParserCombinators.Parsec
    import qualified Data.Map as M
    import qualified Text.PrettyPrint.HughesPJ as PP

    import Text.StringTemplate.Classes
    import Text.StringTemplate.Instances()

    {--------------------------------------------------------------------
      Generic Utilities
    --------------------------------------------------------------------}

    type TmplParser = GenParser Char ((Char, Char),[String],[String],[String])

    (<$$>) :: (Functor f1, Functor f) => (a -> b) -> f (f1 a) -> f (f1 b)
    <$$> :: forall (f1 :: * -> *) (f :: * -> *) a b.
    (Functor f1, Functor f) =>
    (a -> b) -> f (f1 a) -> f (f1 b)
    (<$$>) = (f1 a -> f1 b) -> f (f1 a) -> f (f1 b)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    (<$>) ((f1 a -> f1 b) -> f (f1 a) -> f (f1 b))
    -> ((a -> b) -> f1 a -> f1 b) -> (a -> b) -> f (f1 a) -> f (f1 b)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (a -> b) -> f1 a -> f1 b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    (<$>)
    infixr 8 <$$>

    (|.) :: (t1 -> t2) -> (t -> t1) -> t -> t2
    |. :: forall b c a. (b -> c) -> (a -> b) -> a -> c
    (|.) t1 -> t2
    f t -> t1
    g = t1 -> t2
    f (t1 -> t2) -> (t -> t1) -> t -> t2
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t -> t1
    g
    infixr 3 |.

    (.>>) :: (Monad m) => m a -> m b -> m b
    .>> :: forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    (.>>) m a
    f m b
    g = m a
    f m a -> m b -> m b
    forall a b. m a -> m b -> m b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> m b
    g
    infixr 5 .>>

    fromMany :: b -> ([a] -> b) -> [a] -> b
    fromMany :: forall b a. b -> ([a] -> b) -> [a] -> b
    fromMany b
    e [a] -> b
    _ [] = b
    e
    fromMany b
    _ [a] -> b
    f [a]
    xs  = [a] -> b
    f [a]
    xs

    swing :: (((a -> c1) -> c1) -> b -> c) -> b -> a -> c
    swing :: forall a c1 b c. (((a -> c1) -> c1) -> b -> c) -> b -> a -> c
    swing = (a -> b -> c) -> b -> a -> c
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip ((a -> b -> c) -> b -> a -> c)
    -> ((((a -> c1) -> c1) -> b -> c) -> a -> b -> c)
    -> (((a -> c1) -> c1) -> b -> c)
    -> b
    -> a
    -> c
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ((((a -> c1) -> c1) -> b -> c)
    -> (a -> (a -> c1) -> c1) -> a -> b -> c
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ((a -> c1) -> a -> c1) -> a -> (a -> c1) -> c1
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip (a -> c1) -> a -> c1
    forall a. a -> a
    id)

    paddedTrans :: a -> [[a]] -> [[a]]
    paddedTrans :: forall a. a -> [[a]] -> [[a]]
    paddedTrans a
    _ [] = []
    paddedTrans a
    n [[a]]
    as = Int -> [[a]] -> [[a]]
    forall a. Int -> [a] -> [a]
    take ([Int] -> Int
    forall a. Ord a => [a] -> a
    forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
    maximum ([Int] -> Int) -> ([[a]] -> [Int]) -> [[a]] -> Int
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ([a] -> Int) -> [[a]] -> [Int]
    forall a b. (a -> b) -> [a] -> [b]
    map [a] -> Int
    forall a. [a] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length ([[a]] -> Int) -> [[a]] -> Int
    forall a b. (a -> b) -> a -> b
    $ [[a]]
    as) ([[a]] -> [[a]]) -> ([[a]] -> [[a]]) -> [[a]] -> [[a]]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [[a]] -> [[a]]
    trans ([[a]] -> [[a]]) -> [[a]] -> [[a]]
    forall a b. (a -> b) -> a -> b
    $ [[a]]
    as
        where trans :: [[a]] -> [[a]]
    trans ([] : [[a]]
    xss)  = (a
    n a -> [a] -> [a]
    forall a. a -> [a] -> [a]
    : ([a] -> a) -> [[a]] -> [a]
    forall a b. (a -> b) -> [a] -> [b]
    map [a] -> a
    h [[a]]
    xss) [a] -> [[a]] -> [[a]]
    forall a. a -> [a] -> [a]
    :  [[a]] -> [[a]]
    trans ([a
    n] [a] -> [[a]] -> [[a]]
    forall a. a -> [a] -> [a]
    : ([a] -> [a]) -> [[a]] -> [[a]]
    forall a b. (a -> b) -> [a] -> [b]
    map [a] -> [a]
    t [[a]]
    xss)
              trans ((a
    x : [a]
    xs) : [[a]]
    xss) = (a
    x a -> [a] -> [a]
    forall a. a -> [a] -> [a]
    : ([a] -> a) -> [[a]] -> [a]
    forall a b. (a -> b) -> [a] -> [b]
    map [a] -> a
    h [[a]]
    xss) [a] -> [[a]] -> [[a]]
    forall a. a -> [a] -> [a]
    : [[a]] -> [[a]]
    trans ([a] -> [a]
    m [a]
    xs [a] -> [[a]] -> [[a]]
    forall a. a -> [a] -> [a]
    : ([a] -> [a]) -> [[a]] -> [[a]]
    forall a b. (a -> b) -> [a] -> [b]
    map [a] -> [a]
    t [[a]]
    xss)
              trans [[a]]
    _ = [];
              h :: [a] -> a
    h (a
    x:[a]
    _) = a
    x; h [a]
    _ = a
    n; t :: [a] -> [a]
    t (a
    _:a
    y:[a]
    xs) = a
    ya -> [a] -> [a]
    forall a. a -> [a] -> [a]
    :[a]
    xs; t [a]
    _ = [a
    n];
              m :: [a] -> [a]
    m (a
    x:[a]
    xs) = a
    xa -> [a] -> [a]
    forall a. a -> [a] -> [a]
    :[a]
    xs; m [a]
    _ = [a
    n];

    {--------------------------------------------------------------------
      StringTemplate and the API
    --------------------------------------------------------------------}

    -- | A function that generates StringTemplates.
    -- This is conceptually a query function into a \"group\" of StringTemplates.
    type STGroup a = String -> (StFirst (StringTemplate a))

    -- | A String with \"holes\" in it. StringTemplates may be composed of any
    -- 'Stringable' type, which at the moment includes 'String's, 'ByteString's,
    -- PrettyPrinter 'Doc's, and 'Endo' 'String's, which are actually of type
    -- 'ShowS'. When a StringTemplate is composed of a type, its internals are
    -- as well, so it is, so to speak \"turtles all the way down.\"
    data StringTemplate a = STMP {forall a. StringTemplate a -> SEnv a
    senv :: SEnv a,  forall a. StringTemplate a -> Either [Char] (SEnv a -> a)
    runSTMP :: Either String (SEnv a -> a), forall a.
    StringTemplate a
    -> SEnv a -> (Maybe [Char], Maybe [[Char]], Maybe [[Char]])
    chkSTMP :: SEnv a -> (Maybe String, Maybe [String], Maybe [String])}

    -- | Renders a StringTemplate to a String.
    toString :: StringTemplate String -> String
    toString :: StringTemplate [Char] -> [Char]
    toString = StringTemplate [Char] -> [Char]
    forall a. Stringable a => StringTemplate a -> a
    render

    -- | Renders a StringTemplate to a 'Text.PrettyPrint.HughesPJ.Doc'.
    toPPDoc :: StringTemplate PP.Doc -> PP.Doc
    toPPDoc :: StringTemplate Doc -> Doc
    toPPDoc = StringTemplate Doc -> Doc
    forall a. Stringable a => StringTemplate a -> a
    render

    -- | Generic render function for a StringTemplate of any type.
    render :: Stringable a => StringTemplate a -> a
    render :: forall a. Stringable a => StringTemplate a -> a
    render = ([Char] -> SEnv a -> a)
    -> ((SEnv a -> a) -> SEnv a -> a)
    -> Either [Char] (SEnv a -> a)
    -> SEnv a
    -> a
    forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
    either ([Char] -> SEnv a -> a
    forall a. Stringable a => [Char] -> SEnv a -> a
    showStr) (SEnv a -> a) -> SEnv a -> a
    forall a. a -> a
    id (Either [Char] (SEnv a -> a) -> SEnv a -> a)
    -> (StringTemplate a -> Either [Char] (SEnv a -> a))
    -> StringTemplate a
    -> SEnv a
    -> a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . StringTemplate a -> Either [Char] (SEnv a -> a)
    forall a. StringTemplate a -> Either [Char] (SEnv a -> a)
    runSTMP (StringTemplate a -> SEnv a -> a)
    -> (StringTemplate a -> SEnv a) -> StringTemplate a -> a
    forall a b.
    (StringTemplate a -> a -> b)
    -> (StringTemplate a -> a) -> StringTemplate a -> b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> StringTemplate a -> SEnv a
    forall a. StringTemplate a -> SEnv a
    senv

    nullEnv :: SEnv a
    nullEnv :: forall a. SEnv a
    nullEnv = SMap a
    -> [([Char], SEnv a -> SElem a)] -> STGroup a -> (a -> a) -> SEnv a
    forall a.
    SMap a
    -> [([Char], SEnv a -> SElem a)] -> STGroup a -> (a -> a) -> SEnv a
    SEnv SMap a
    forall k a. Map k a
    M.empty [] STGroup a
    forall a. Monoid a => a
    mempty a -> a
    forall a. a -> a
    id

    -- | Returns a tuple of three Maybes. The first is set if there is a parse error in the template.
    -- The next is set to a list of attributes that have not been set, or Nothing if all attributes are set.
    -- The last is set to a list of invoked templates that cannot be looked up, or Nothing if all invoked templates can be found.
    -- Note that this check is shallow -- i.e. missing attributes and templates are only caught in the top level template, not any invoked subtemplate.
    checkTemplate :: Stringable a => StringTemplate a -> (Maybe String, Maybe [String], Maybe [String])
    checkTemplate :: forall a.
    Stringable a =>
    StringTemplate a -> (Maybe [Char], Maybe [[Char]], Maybe [[Char]])
    checkTemplate StringTemplate a
    t = StringTemplate a
    -> SEnv a -> (Maybe [Char], Maybe [[Char]], Maybe [[Char]])
    forall a.
    StringTemplate a
    -> SEnv a -> (Maybe [Char], Maybe [[Char]], Maybe [[Char]])
    chkSTMP StringTemplate a
    t (StringTemplate a -> SEnv a
    forall a. StringTemplate a -> SEnv a
    senv StringTemplate a
    t)

    -- | Parses a String to produce a StringTemplate, with \'$\'s as delimiters.
    -- It is constructed with a stub group that cannot look up other templates.
    newSTMP :: Stringable a => String -> StringTemplate a
    newSTMP :: forall a. Stringable a => [Char] -> StringTemplate a
    newSTMP [Char]
    s = SEnv a
    -> Either [Char] (SEnv a -> a)
    -> (SEnv a -> (Maybe [Char], Maybe [[Char]], Maybe [[Char]]))
    -> StringTemplate a
    forall a.
    SEnv a
    -> Either [Char] (SEnv a -> a)
    -> (SEnv a -> (Maybe [Char], Maybe [[Char]], Maybe [[Char]]))
    -> StringTemplate a
    STMP SEnv a
    forall a. SEnv a
    nullEnv ((Char, Char) -> [Char] -> Either [Char] (SEnv a -> a)
    forall a.
    Stringable a =>
    (Char, Char) -> [Char] -> Either [Char] (SEnv a -> a)
    parseSTMP (Char
    '$',Char
    '$') [Char]
    s) ((Char, Char)
    -> [Char]
    -> SEnv a
    -> (Maybe [Char], Maybe [[Char]], Maybe [[Char]])
    forall a.
    Stringable a =>
    (Char, Char)
    -> [Char]
    -> SEnv a
    -> (Maybe [Char], Maybe [[Char]], Maybe [[Char]])
    chkStmp (Char
    '$',Char
    '$') [Char]
    s)

    -- | Parses a String to produce a StringTemplate, delimited by angle brackets.
    -- It is constructed with a stub group that cannot look up other templates.
    newAngleSTMP :: Stringable a => String -> StringTemplate a
    newAngleSTMP :: forall a. Stringable a => [Char] -> StringTemplate a
    newAngleSTMP [Char]
    s = SEnv a
    -> Either [Char] (SEnv a -> a)
    -> (SEnv a -> (Maybe [Char], Maybe [[Char]], Maybe [[Char]]))
    -> StringTemplate a
    forall a.
    SEnv a
    -> Either [Char] (SEnv a -> a)
    -> (SEnv a -> (Maybe [Char], Maybe [[Char]], Maybe [[Char]]))
    -> StringTemplate a
    STMP SEnv a
    forall a. SEnv a
    nullEnv ((Char, Char) -> [Char] -> Either [Char] (SEnv a -> a)
    forall a.
    Stringable a =>
    (Char, Char) -> [Char] -> Either [Char] (SEnv a -> a)
    parseSTMP (Char
    '<',Char
    '>') [Char]
    s) ((Char, Char)
    -> [Char]
    -> SEnv a
    -> (Maybe [Char], Maybe [[Char]], Maybe [[Char]])
    forall a.
    Stringable a =>
    (Char, Char)
    -> [Char]
    -> SEnv a
    -> (Maybe [Char], Maybe [[Char]], Maybe [[Char]])
    chkStmp (Char
    '<',Char
    '>') [Char]
    s)

    -- | Yields a StringTemplate with the appropriate attribute set.
    -- If the attribute already exists, it is appended to a list.
    setAttribute :: (ToSElem a, Stringable b) => String -> a -> StringTemplate b -> StringTemplate b
    setAttribute :: forall a b.
    (ToSElem a, Stringable b) =>
    [Char] -> a -> StringTemplate b -> StringTemplate b
    setAttribute [Char]
    s a
    x StringTemplate b
    st = StringTemplate b
    st {senv = envInsApp s (toSElem x) (senv st)}

    -- | Yields a StringTemplate with the appropriate attributes set.
    -- If any attribute already exists, it is appended to a list.
    setManyAttrib :: (ToSElem a, Stringable b) => [(String, a)] -> StringTemplate b -> StringTemplate b
    setManyAttrib :: forall a b.
    (ToSElem a, Stringable b) =>
    [([Char], a)] -> StringTemplate b -> StringTemplate b
    setManyAttrib = (StringTemplate b -> [([Char], a)] -> StringTemplate b)
    -> [([Char], a)] -> StringTemplate b -> StringTemplate b
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip ((StringTemplate b -> [([Char], a)] -> StringTemplate b)
     -> [([Char], a)] -> StringTemplate b -> StringTemplate b)
    -> ((([Char], a) -> StringTemplate b -> StringTemplate b)
        -> StringTemplate b -> [([Char], a)] -> StringTemplate b)
    -> (([Char], a) -> StringTemplate b -> StringTemplate b)
    -> [([Char], a)]
    -> StringTemplate b
    -> StringTemplate b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (StringTemplate b -> ([Char], a) -> StringTemplate b)
    -> StringTemplate b -> [([Char], a)] -> StringTemplate b
    forall b a. (b -> a -> b) -> b -> [a] -> b
    forall (t :: * -> *) b a.
    Foldable t =>
    (b -> a -> b) -> b -> t a -> b
    foldl' ((StringTemplate b -> ([Char], a) -> StringTemplate b)
     -> StringTemplate b -> [([Char], a)] -> StringTemplate b)
    -> ((([Char], a) -> StringTemplate b -> StringTemplate b)
        -> StringTemplate b -> ([Char], a) -> StringTemplate b)
    -> (([Char], a) -> StringTemplate b -> StringTemplate b)
    -> StringTemplate b
    -> [([Char], a)]
    -> StringTemplate b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (([Char], a) -> StringTemplate b -> StringTemplate b)
    -> StringTemplate b -> ([Char], a) -> StringTemplate b
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip ((([Char], a) -> StringTemplate b -> StringTemplate b)
     -> [([Char], a)] -> StringTemplate b -> StringTemplate b)
    -> (([Char], a) -> StringTemplate b -> StringTemplate b)
    -> [([Char], a)]
    -> StringTemplate b
    -> StringTemplate b
    forall a b. (a -> b) -> a -> b
    $ ([Char] -> a -> StringTemplate b -> StringTemplate b)
    -> ([Char], a) -> StringTemplate b -> StringTemplate b
    forall a b c. (a -> b -> c) -> (a, b) -> c
    uncurry [Char] -> a -> StringTemplate b -> StringTemplate b
    forall a b.
    (ToSElem a, Stringable b) =>
    [Char] -> a -> StringTemplate b -> StringTemplate b
    setAttribute

    -- | Yields a StringTemplate with the appropriate attribute set.
    -- If the attribute already exists, it is appended to a list.
    -- This will not translate the attribute through any intermediate
    -- representation, so is more efficient when, e.g. setting
    -- attributes that are large bytestrings in a bytestring template.
    setNativeAttribute :: Stringable b => String -> b -> StringTemplate b -> StringTemplate b
    setNativeAttribute :: forall b.
    Stringable b =>
    [Char] -> b -> StringTemplate b -> StringTemplate b
    setNativeAttribute [Char]
    s b
    x StringTemplate b
    st = StringTemplate b
    st {senv = envInsApp s (SNAT x) (senv st)}

    -- | Yields a StringTemplate with the appropriate attributes set.
    -- If any attribute already exists, it is appended to a list.
    -- Attributes are added natively, which may provide
    -- efficiency gains.
    setManyNativeAttrib :: (Stringable b) => [(String, b)] -> StringTemplate b -> StringTemplate b
    setManyNativeAttrib :: forall b.
    Stringable b =>
    [([Char], b)] -> StringTemplate b -> StringTemplate b
    setManyNativeAttrib = (StringTemplate b -> [([Char], b)] -> StringTemplate b)
    -> [([Char], b)] -> StringTemplate b -> StringTemplate b
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip ((StringTemplate b -> [([Char], b)] -> StringTemplate b)
     -> [([Char], b)] -> StringTemplate b -> StringTemplate b)
    -> ((([Char], b) -> StringTemplate b -> StringTemplate b)
        -> StringTemplate b -> [([Char], b)] -> StringTemplate b)
    -> (([Char], b) -> StringTemplate b -> StringTemplate b)
    -> [([Char], b)]
    -> StringTemplate b
    -> StringTemplate b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (StringTemplate b -> ([Char], b) -> StringTemplate b)
    -> StringTemplate b -> [([Char], b)] -> StringTemplate b
    forall b a. (b -> a -> b) -> b -> [a] -> b
    forall (t :: * -> *) b a.
    Foldable t =>
    (b -> a -> b) -> b -> t a -> b
    foldl' ((StringTemplate b -> ([Char], b) -> StringTemplate b)
     -> StringTemplate b -> [([Char], b)] -> StringTemplate b)
    -> ((([Char], b) -> StringTemplate b -> StringTemplate b)
        -> StringTemplate b -> ([Char], b) -> StringTemplate b)
    -> (([Char], b) -> StringTemplate b -> StringTemplate b)
    -> StringTemplate b
    -> [([Char], b)]
    -> StringTemplate b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (([Char], b) -> StringTemplate b -> StringTemplate b)
    -> StringTemplate b -> ([Char], b) -> StringTemplate b
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip ((([Char], b) -> StringTemplate b -> StringTemplate b)
     -> [([Char], b)] -> StringTemplate b -> StringTemplate b)
    -> (([Char], b) -> StringTemplate b -> StringTemplate b)
    -> [([Char], b)]
    -> StringTemplate b
    -> StringTemplate b
    forall a b. (a -> b) -> a -> b
    $ ([Char] -> b -> StringTemplate b -> StringTemplate b)
    -> ([Char], b) -> StringTemplate b -> StringTemplate b
    forall a b c. (a -> b -> c) -> (a, b) -> c
    uncurry [Char] -> b -> StringTemplate b -> StringTemplate b
    forall b.
    Stringable b =>
    [Char] -> b -> StringTemplate b -> StringTemplate b
    setNativeAttribute

    -- | Replaces the attributes of a StringTemplate with those
    -- described in the second argument. If the argument does not yield
    -- a set of named attributes but only a single one, that attribute
    -- is named, as a default, \"it\".
    withContext :: (ToSElem a, Stringable b) => StringTemplate b -> a -> StringTemplate b
    withContext :: forall a b.
    (ToSElem a, Stringable b) =>
    StringTemplate b -> a -> StringTemplate b
    withContext StringTemplate b
    st a
    x = case a -> SElem b
    forall b. Stringable b => a -> SElem b
    forall a b. (ToSElem a, Stringable b) => a -> SElem b
    toSElem a
    x of
                         SM SMap b
    a -> StringTemplate b
    st {senv = (senv st) {smp = a}}
                         SElem b
    b -> StringTemplate b
    st {senv = (senv st) {smp = M.singleton "it" b}}

    -- | Queries an String Template Group and returns Just the appropriate
    -- StringTemplate if it exists, otherwise, Nothing.
    getStringTemplate :: (Stringable a) => String -> STGroup a -> Maybe (StringTemplate a)
    getStringTemplate :: forall a.
    Stringable a =>
    [Char] -> STGroup a -> Maybe (StringTemplate a)
    getStringTemplate [Char]
    s STGroup a
    sg = StFirst (StringTemplate a) -> Maybe (StringTemplate a)
    forall a. StFirst a -> Maybe a
    stGetFirst (STGroup a
    sg [Char]
    s)

    -- | As with 'getStringTemplate' but never inlined, so appropriate for use
    -- with volatile template groups.
    {-# NOINLINE getStringTemplate' #-}
    getStringTemplate' :: (Stringable a) => String -> STGroup a -> Maybe (StringTemplate a)
    getStringTemplate' :: forall a.
    Stringable a =>
    [Char] -> STGroup a -> Maybe (StringTemplate a)
    getStringTemplate' [Char]
    s STGroup a
    sg = StFirst (StringTemplate a) -> Maybe (StringTemplate a)
    forall a. StFirst a -> Maybe a
    stGetFirst (STGroup a
    sg [Char]
    s)

    -- | Adds a set of global options to a single template
    optInsertTmpl :: [(String, String)] -> StringTemplate a -> StringTemplate a
    optInsertTmpl :: forall a.
    [([Char], [Char])] -> StringTemplate a -> StringTemplate a
    optInsertTmpl [([Char], [Char])]
    x StringTemplate a
    st = StringTemplate a
    st {senv = optInsert (map (second justSTR) x) (senv st)}

    -- | Sets an encoding function of a template that all values are
    -- rendered with. For example one useful encoder would be 'Text.Html.stringToHtmlString'. All attributes will be encoded once and only once.
    setEncoder :: (Stringable a) => (a -> a) -> StringTemplate a -> StringTemplate a
    setEncoder :: forall a.
    Stringable a =>
    (a -> a) -> StringTemplate a -> StringTemplate a
    setEncoder a -> a
    x StringTemplate a
    st = StringTemplate a
    st {senv = (senv st) {senc = x} }

    -- | A special template that simply dumps the values of all the attributes set in it.
    -- This may be made available to any template as a function by adding it to its group.
    -- I.e. @ myNewGroup = addSuperGroup myGroup $ groupStringTemplates [("dumpAttribs", dumpAttribs)] @
    dumpAttribs :: Stringable a => StringTemplate a
    dumpAttribs :: forall a. Stringable a => StringTemplate a
    dumpAttribs = SEnv a
    -> Either [Char] (SEnv a -> a)
    -> (SEnv a -> (Maybe [Char], Maybe [[Char]], Maybe [[Char]]))
    -> StringTemplate a
    forall a.
    SEnv a
    -> Either [Char] (SEnv a -> a)
    -> (SEnv a -> (Maybe [Char], Maybe [[Char]], Maybe [[Char]]))
    -> StringTemplate a
    STMP SEnv a
    forall a. SEnv a
    nullEnv ((SEnv a -> a) -> Either [Char] (SEnv a -> a)
    forall a b. b -> Either a b
    Right ((SEnv a -> a) -> Either [Char] (SEnv a -> a))
    -> (SEnv a -> a) -> Either [Char] (SEnv a -> a)
    forall a b. (a -> b) -> a -> b
    $ \SEnv a
    env -> SEnv a -> SElem a -> a
    forall a. Stringable a => SEnv a -> SElem a -> a
    showVal SEnv a
    env (SMap a -> SElem a
    forall a. SMap a -> SElem a
    SM (SMap a -> SElem a) -> SMap a -> SElem a
    forall a b. (a -> b) -> a -> b
    $ SEnv a -> SMap a
    forall a. SEnv a -> SMap a
    smp SEnv a
    env)) ((Maybe [Char], Maybe [[Char]], Maybe [[Char]])
    -> SEnv a -> (Maybe [Char], Maybe [[Char]], Maybe [[Char]])
    forall a b. a -> b -> a
    const (Maybe [Char]
    forall a. Maybe a
    Nothing, Maybe [[Char]]
    forall a. Maybe a
    Nothing, Maybe [[Char]]
    forall a. Maybe a
    Nothing))

    {--------------------------------------------------------------------
      Internal API
    --------------------------------------------------------------------}
    --IMPLEMENT groups having stLookup return a Maybe for regions

    data SEnv a = SEnv {forall a. SEnv a -> SMap a
    smp :: SMap a, forall a. SEnv a -> [([Char], SEnv a -> SElem a)]
    sopts :: [(String, (SEnv a -> SElem a))], forall a. SEnv a -> STGroup a
    sgen :: STGroup a, forall a. SEnv a -> a -> a
    senc :: a -> a}

    inSGen :: (STGroup a -> STGroup a) -> StringTemplate a -> StringTemplate a
    inSGen :: forall a.
    (STGroup a -> STGroup a) -> StringTemplate a -> StringTemplate a
    inSGen STGroup a -> STGroup a
    f st :: StringTemplate a
    st@STMP{senv :: forall a. StringTemplate a -> SEnv a
    senv = SEnv a
    env} = StringTemplate a
    st {senv = env {sgen = f (sgen env)} }

    {-
    envLookup :: String -> SEnv a -> Maybe (SElem a)
    envLookup x = M.lookup x . smp
    -}

    envLookupEx :: String -> SEnv a -> SElem a
    envLookupEx :: forall a. [Char] -> SEnv a -> SElem a
    envLookupEx [Char]
    x SEnv a
    snv = case [Char] -> Map [Char] (SElem a) -> Maybe (SElem a)
    forall k a. Ord k => k -> Map k a -> Maybe a
    M.lookup [Char]
    x (SEnv a -> Map [Char] (SElem a)
    forall a. SEnv a -> SMap a
    smp SEnv a
    snv) of
                          Just SElem a
    a -> SElem a
    a
                          Maybe (SElem a)
    Nothing -> case [Char] -> SEnv a -> Maybe (SEnv a -> SElem a)
    forall a. [Char] -> SEnv a -> Maybe (SEnv a -> SElem a)
    optLookup [Char]
    "throwException" SEnv a
    snv of
                                       Just SEnv a -> SElem a
    _ -> TmplException -> SElem a
    forall a e. (HasCallStack, Exception e) => e -> a
    C.throw (TmplException -> SElem a) -> TmplException -> SElem a
    forall a b. (a -> b) -> a -> b
    $ [Char] -> TmplException
    NoAttrib [Char]
    x
                                       Maybe (SEnv a -> SElem a)
    Nothing -> SElem a
    forall a. SElem a
    SNull

    envInsert :: (String, SElem a) -> SEnv a -> SEnv a
    envInsert :: forall a. ([Char], SElem a) -> SEnv a -> SEnv a
    envInsert ([Char]
    s, SElem a
    x) SEnv a
    y = SEnv a
    y {smp = M.insert s x (smp y)}
    envInsApp :: Stringable a => String -> SElem a -> SEnv a -> SEnv a
    envInsApp :: forall a. Stringable a => [Char] -> SElem a -> SEnv a -> SEnv a
    envInsApp  [Char]
    s  SElem a
    x  SEnv a
    y = SEnv a
    y {smp = M.insertWith go s x (smp y)}
        where go :: SElem a -> SElem a -> SElem a
    go SElem a
    a (LI [SElem a]
    bs) = [SElem a] -> SElem a
    forall a. [SElem a] -> SElem a
    LI (SElem a
    aSElem a -> [SElem a] -> [SElem a]
    forall a. a -> [a] -> [a]
    :[SElem a]
    bs)
              go SElem a
    a SElem a
    b = [SElem a] -> SElem a
    forall a. [SElem a] -> SElem a
    LI [SElem a
    a,SElem a
    b]

    optLookup :: String -> SEnv a -> Maybe (SEnv a -> SElem a)
    optLookup :: forall a. [Char] -> SEnv a -> Maybe (SEnv a -> SElem a)
    optLookup [Char]
    x = [Char]
    -> [([Char], SEnv a -> SElem a)] -> Maybe (SEnv a -> SElem a)
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup [Char]
    x ([([Char], SEnv a -> SElem a)] -> Maybe (SEnv a -> SElem a))
    -> (SEnv a -> [([Char], SEnv a -> SElem a)])
    -> SEnv a
    -> Maybe (SEnv a -> SElem a)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . SEnv a -> [([Char], SEnv a -> SElem a)]
    forall a. SEnv a -> [([Char], SEnv a -> SElem a)]
    sopts
    optInsert :: [(String, SEnv a -> SElem a)] -> SEnv a -> SEnv a
    optInsert :: forall a. [([Char], SEnv a -> SElem a)] -> SEnv a -> SEnv a
    optInsert [([Char], SEnv a -> SElem a)]
    x SEnv a
    env = SEnv a
    env {sopts = x ++ sopts env}
    nullOpt :: SEnv a -> SElem a
    nullOpt :: forall a. SEnv a -> SElem a
    nullOpt = (SEnv a -> SElem a)
    -> Maybe (SEnv a -> SElem a) -> SEnv a -> SElem a
    forall a. a -> Maybe a -> a
    fromMaybe ([Char] -> SEnv a -> SElem a
    forall b a. [Char] -> b -> SElem a
    justSTR [Char]
    "") (Maybe (SEnv a -> SElem a) -> SEnv a -> SElem a)
    -> (SEnv a -> Maybe (SEnv a -> SElem a)) -> SEnv a -> SElem a
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
    =<< [Char] -> SEnv a -> Maybe (SEnv a -> SElem a)
    forall a. [Char] -> SEnv a -> Maybe (SEnv a -> SElem a)
    optLookup [Char]
    "null"

    stLookup :: (Stringable a) => String -> SEnv a -> StringTemplate a
    stLookup :: forall a. Stringable a => [Char] -> SEnv a -> StringTemplate a
    stLookup [Char]
    x SEnv a
    env = StringTemplate a
    -> (StringTemplate a -> StringTemplate a)
    -> Maybe (StringTemplate a)
    -> StringTemplate a
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe ([Char] -> StringTemplate a
    forall a. Stringable a => [Char] -> StringTemplate a
    newSTMP ([Char]
    "No Template Found for: " [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ [Char]
    x))
                     (\StringTemplate a
    st-> StringTemplate a
    st {senv = mergeSEnvs env (senv st)}) (Maybe (StringTemplate a) -> StringTemplate a)
    -> Maybe (StringTemplate a) -> StringTemplate a
    forall a b. (a -> b) -> a -> b
    $ StFirst (StringTemplate a) -> Maybe (StringTemplate a)
    forall a. StFirst a -> Maybe a
    stGetFirst (SEnv a -> STGroup a
    forall a. SEnv a -> STGroup a
    sgen SEnv a
    env [Char]
    x)

    --merges values of former into latter, preserving encoder
    --of latter, as well as non-overriden options. group of latter is overridden.
    mergeSEnvs :: SEnv a -> SEnv a -> SEnv a
    mergeSEnvs :: forall a. SEnv a -> SEnv a -> SEnv a
    mergeSEnvs SEnv a
    x SEnv a
    y = SEnv {smp :: SMap a
    smp = SMap a -> SMap a -> SMap a
    forall k a. Ord k => Map k a -> Map k a -> Map k a
    M.union (SEnv a -> SMap a
    forall a. SEnv a -> SMap a
    smp SEnv a
    x) (SEnv a -> SMap a
    forall a. SEnv a -> SMap a
    smp SEnv a
    y), sopts :: [([Char], SEnv a -> SElem a)]
    sopts = (SEnv a -> [([Char], SEnv a -> SElem a)]
    forall a. SEnv a -> [([Char], SEnv a -> SElem a)]
    sopts SEnv a
    y [([Char], SEnv a -> SElem a)]
    -> [([Char], SEnv a -> SElem a)] -> [([Char], SEnv a -> SElem a)]
    forall a. [a] -> [a] -> [a]
    ++ SEnv a -> [([Char], SEnv a -> SElem a)]
    forall a. SEnv a -> [([Char], SEnv a -> SElem a)]
    sopts SEnv a
    x), sgen :: STGroup a
    sgen = SEnv a -> STGroup a
    forall a. SEnv a -> STGroup a
    sgen SEnv a
    x, senc :: a -> a
    senc = SEnv a -> a -> a
    forall a. SEnv a -> a -> a
    senc SEnv a
    y}

    parseSTMP :: (Stringable a) => (Char, Char) -> String -> Either String (SEnv a -> a)
    parseSTMP :: forall a.
    Stringable a =>
    (Char, Char) -> [Char] -> Either [Char] (SEnv a -> a)
    parseSTMP (Char, Char)
    x = (ParseError -> Either [Char] (SEnv a -> a))
    -> ((SEnv a -> a) -> Either [Char] (SEnv a -> a))
    -> Either ParseError (SEnv a -> a)
    -> Either [Char] (SEnv a -> a)
    forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
    either ([Char] -> Either [Char] (SEnv a -> a)
    forall a b. a -> Either a b
    Left ([Char] -> Either [Char] (SEnv a -> a))
    -> (ParseError -> [Char])
    -> ParseError
    -> Either [Char] (SEnv a -> a)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ParseError -> [Char]
    forall a. Show a => a -> [Char]
    show) (SEnv a -> a) -> Either [Char] (SEnv a -> a)
    forall a b. b -> Either a b
    Right (Either ParseError (SEnv a -> a) -> Either [Char] (SEnv a -> a))
    -> ([Char] -> Either ParseError (SEnv a -> a))
    -> [Char]
    -> Either [Char] (SEnv a -> a)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . GenParser
      Char ((Char, Char), [[Char]], [[Char]], [[Char]]) (SEnv a -> a)
    -> ((Char, Char), [[Char]], [[Char]], [[Char]])
    -> [Char]
    -> [Char]
    -> Either ParseError (SEnv a -> a)
    forall tok st a.
    GenParser tok st a -> st -> [Char] -> [tok] -> Either ParseError a
    runParser (Bool
    -> GenParser
         Char ((Char, Char), [[Char]], [[Char]], [[Char]]) (SEnv a -> a)
    forall a. Stringable a => Bool -> TmplParser (SEnv a -> a)
    stmpl Bool
    False) ((Char, Char)
    x,[],[],[]) [Char]
    "" ([Char] -> Either ParseError (SEnv a -> a))
    -> ([Char] -> [Char]) -> [Char] -> Either ParseError (SEnv a -> a)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Char] -> [Char]
    dropTrailingBr

    dropTrailingBr :: String -> String
    dropTrailingBr :: [Char] -> [Char]
    dropTrailingBr (Char
    '\r':Char
    '\n':[]) = []
    dropTrailingBr (Char
    '\n':[]) = []
    dropTrailingBr [] = []
    dropTrailingBr (Char
    x:[Char]
    xs) = Char
    x Char -> [Char] -> [Char]
    forall a. a -> [a] -> [a]
    : [Char] -> [Char]
    dropTrailingBr [Char]
    xs

    getSeps :: TmplParser (Char, Char)
    getSeps :: TmplParser (Char, Char)
    getSeps = (\((Char, Char)
    x,[[Char]]
    _,[[Char]]
    _,[[Char]]
    _) -> (Char, Char)
    x) (((Char, Char), [[Char]], [[Char]], [[Char]]) -> (Char, Char))
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         ((Char, Char), [[Char]], [[Char]], [[Char]])
    -> TmplParser (Char, Char)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      ((Char, Char), [[Char]], [[Char]], [[Char]])
    forall (m :: * -> *) s u. Monad m => ParsecT s u m u
    getState

    tellName :: String -> TmplParser ()
    tellName :: [Char] -> TmplParser ()
    tellName [Char]
    x = ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      ((Char, Char), [[Char]], [[Char]], [[Char]])
    forall (m :: * -> *) s u. Monad m => ParsecT s u m u
    getState ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      ((Char, Char), [[Char]], [[Char]], [[Char]])
    -> (((Char, Char), [[Char]], [[Char]], [[Char]]) -> TmplParser ())
    -> TmplParser ()
    forall a b.
    ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity a
    -> (a
        -> ParsecT
             [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity b)
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= \((Char, Char)
    s,[[Char]]
    q,[[Char]]
    n,[[Char]]
    t) -> ((Char, Char), [[Char]], [[Char]], [[Char]]) -> TmplParser ()
    forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
    setState ((Char, Char)
    s,[[Char]]
    q,[Char]
    x[Char] -> [[Char]] -> [[Char]]
    forall a. a -> [a] -> [a]
    :[[Char]]
    n,[[Char]]
    t)

    tellQQ :: String -> TmplParser ()
    tellQQ :: [Char] -> TmplParser ()
    tellQQ [Char]
    x = ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      ((Char, Char), [[Char]], [[Char]], [[Char]])
    forall (m :: * -> *) s u. Monad m => ParsecT s u m u
    getState ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      ((Char, Char), [[Char]], [[Char]], [[Char]])
    -> (((Char, Char), [[Char]], [[Char]], [[Char]]) -> TmplParser ())
    -> TmplParser ()
    forall a b.
    ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity a
    -> (a
        -> ParsecT
             [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity b)
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= \((Char, Char)
    s,[[Char]]
    q,[[Char]]
    n,[[Char]]
    t) -> ((Char, Char), [[Char]], [[Char]], [[Char]]) -> TmplParser ()
    forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
    setState ((Char, Char)
    s,[Char]
    x[Char] -> [[Char]] -> [[Char]]
    forall a. a -> [a] -> [a]
    :[[Char]]
    q,[[Char]]
    n,[[Char]]
    t)

    tellTmpl :: String -> TmplParser ()
    tellTmpl :: [Char] -> TmplParser ()
    tellTmpl [Char]
    x = ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      ((Char, Char), [[Char]], [[Char]], [[Char]])
    forall (m :: * -> *) s u. Monad m => ParsecT s u m u
    getState ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      ((Char, Char), [[Char]], [[Char]], [[Char]])
    -> (((Char, Char), [[Char]], [[Char]], [[Char]]) -> TmplParser ())
    -> TmplParser ()
    forall a b.
    ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity a
    -> (a
        -> ParsecT
             [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity b)
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= \((Char, Char)
    s,[[Char]]
    q,[[Char]]
    n,[[Char]]
    t) -> ((Char, Char), [[Char]], [[Char]], [[Char]]) -> TmplParser ()
    forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
    setState ((Char, Char)
    s,[[Char]]
    q,[[Char]]
    n,[Char]
    x[Char] -> [[Char]] -> [[Char]]
    forall a. a -> [a] -> [a]
    :[[Char]]
    t)

    -- | Gets all quasiquoted names, normal names & templates used in a given template.
    -- Must be passed a pair of chars denoting the delimeters to be used.
    parseSTMPNames :: (Char, Char) -> String -> Either ParseError ([String],[String],[String])
    parseSTMPNames :: (Char, Char)
    -> [Char] -> Either ParseError ([[Char]], [[Char]], [[Char]])
    parseSTMPNames (Char, Char)
    cs [Char]
    s = GenParser
      Char
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      ([[Char]], [[Char]], [[Char]])
    -> ((Char, Char), [[Char]], [[Char]], [[Char]])
    -> [Char]
    -> [Char]
    -> Either ParseError ([[Char]], [[Char]], [[Char]])
    forall tok st a.
    GenParser tok st a -> st -> [Char] -> [tok] -> Either ParseError a
    runParser GenParser
      Char
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      ([[Char]], [[Char]], [[Char]])
    getRefs ((Char, Char)
    cs,[],[],[]) [Char]
    "" [Char]
    s
        where getRefs :: GenParser
      Char
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      ([[Char]], [[Char]], [[Char]])
    getRefs = do
                _ <- Bool -> TmplParser (SEnv [Char] -> [Char])
    forall a. Stringable a => Bool -> TmplParser (SEnv a -> a)
    stmpl Bool
    False :: TmplParser (SEnv String -> String)
                (_,qqnames,regnames,tmpls) <- getState
                return (qqnames, regnames, tmpls)

    chkStmp :: Stringable a => (Char, Char) -> String -> SEnv a -> (Maybe String, Maybe [String], Maybe [String])
    chkStmp :: forall a.
    Stringable a =>
    (Char, Char)
    -> [Char]
    -> SEnv a
    -> (Maybe [Char], Maybe [[Char]], Maybe [[Char]])
    chkStmp (Char, Char)
    cs [Char]
    s SEnv a
    snv = case (Char, Char)
    -> [Char] -> Either ParseError ([[Char]], [[Char]], [[Char]])
    parseSTMPNames (Char, Char)
    cs [Char]
    s of
                         Left ParseError
    err -> ([Char] -> Maybe [Char]
    forall a. a -> Maybe a
    Just ([Char] -> Maybe [Char]) -> [Char] -> Maybe [Char]
    forall a b. (a -> b) -> a -> b
    $ [Char]
    "Parse error: " [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ ParseError -> [Char]
    forall a. Show a => a -> [Char]
    show ParseError
    err, Maybe [[Char]]
    forall a. Maybe a
    Nothing, Maybe [[Char]]
    forall a. Maybe a
    Nothing)
                         Right ([[Char]]
    _, [[Char]]
    regnames, [[Char]]
    tmpls) ->
                             let nonms :: [[Char]]
    nonms   = ([Char] -> Bool) -> [[Char]] -> [[Char]]
    forall a. (a -> Bool) -> [a] -> [a]
    filter (\[Char]
    x -> Bool -> Bool
    not (Bool -> Bool) -> Bool -> Bool
    forall a b. (a -> b) -> a -> b
    $ [Char] -> [[Char]] -> Bool
    forall a. Eq a => a -> [a] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    elem [Char]
    x (Map [Char] (SElem a) -> [[Char]]
    forall k a. Map k a -> [k]
    M.keys (Map [Char] (SElem a) -> [[Char]])
    -> Map [Char] (SElem a) -> [[Char]]
    forall a b. (a -> b) -> a -> b
    $ SEnv a -> Map [Char] (SElem a)
    forall a. SEnv a -> SMap a
    smp SEnv a
    snv)) [[Char]]
    regnames
                                 notmpls :: [[Char]]
    notmpls = ([Char] -> Bool) -> [[Char]] -> [[Char]]
    forall a. (a -> Bool) -> [a] -> [a]
    filter (\[Char]
    x -> Maybe (StringTemplate a) -> Bool
    forall a. Maybe a -> Bool
    isNothing (Maybe (StringTemplate a) -> Bool)
    -> Maybe (StringTemplate a) -> Bool
    forall a b. (a -> b) -> a -> b
    $ StFirst (StringTemplate a) -> Maybe (StringTemplate a)
    forall a. StFirst a -> Maybe a
    stGetFirst (SEnv a -> STGroup a
    forall a. SEnv a -> STGroup a
    sgen SEnv a
    snv [Char]
    x)) [[Char]]
    tmpls
                             in (Maybe [Char]
    forall a. Maybe a
    Nothing, if [[Char]] -> Bool
    forall a. [a] -> Bool
    forall (t :: * -> *) a. Foldable t => t a -> Bool
    null [[Char]]
    nonms then Maybe [[Char]]
    forall a. Maybe a
    Nothing else [[Char]] -> Maybe [[Char]]
    forall a. a -> Maybe a
    Just [[Char]]
    nonms,
                                          if [[Char]] -> Bool
    forall a. [a] -> Bool
    forall (t :: * -> *) a. Foldable t => t a -> Bool
    null [[Char]]
    notmpls then Maybe [[Char]]
    forall a. Maybe a
    Nothing else [[Char]] -> Maybe [[Char]]
    forall a. a -> Maybe a
    Just [[Char]]
    notmpls)

    data TmplException = NoAttrib String | NoTmpl String | ParseError String String deriving (Int -> TmplException -> [Char] -> [Char]
    [TmplException] -> [Char] -> [Char]
    TmplException -> [Char]
    (Int -> TmplException -> [Char] -> [Char])
    -> (TmplException -> [Char])
    -> ([TmplException] -> [Char] -> [Char])
    -> Show TmplException
    forall a.
    (Int -> a -> [Char] -> [Char])
    -> (a -> [Char]) -> ([a] -> [Char] -> [Char]) -> Show a
    $cshowsPrec :: Int -> TmplException -> [Char] -> [Char]
    showsPrec :: Int -> TmplException -> [Char] -> [Char]
    $cshow :: TmplException -> [Char]
    show :: TmplException -> [Char]
    $cshowList :: [TmplException] -> [Char] -> [Char]
    showList :: [TmplException] -> [Char] -> [Char]
    Show, Typeable)
    instance C.Exception TmplException

    -- | Generic render function for a StringTemplate of any type.
    renderErr :: Stringable a => String -> StringTemplate a -> a
    renderErr :: forall a. Stringable a => [Char] -> StringTemplate a -> a
    renderErr [Char]
    n StringTemplate a
    t = case StringTemplate a -> Either [Char] (SEnv a -> a)
    forall a. StringTemplate a -> Either [Char] (SEnv a -> a)
    runSTMP StringTemplate a
    t of
                    Right SEnv a -> a
    rt -> SEnv a -> a
    rt (StringTemplate a -> SEnv a
    forall a. StringTemplate a -> SEnv a
    senv StringTemplate a
    t)
                    Left [Char]
    err -> case [Char] -> SEnv a -> Maybe (SEnv a -> SElem a)
    forall a. [Char] -> SEnv a -> Maybe (SEnv a -> SElem a)
    optLookup [Char]
    "throwException" (StringTemplate a -> SEnv a
    forall a. StringTemplate a -> SEnv a
    senv StringTemplate a
    t) of
                                  Just SEnv a -> SElem a
    _ -> TmplException -> a
    forall a e. (HasCallStack, Exception e) => e -> a
    C.throw (TmplException -> a) -> TmplException -> a
    forall a b. (a -> b) -> a -> b
    $ [Char] -> [Char] -> TmplException
    ParseError [Char]
    n [Char]
    err
                                  Maybe (SEnv a -> SElem a)
    Nothing -> [Char] -> SEnv a -> a
    forall a. Stringable a => [Char] -> SEnv a -> a
    showStr [Char]
    err (StringTemplate a -> SEnv a
    forall a. StringTemplate a -> SEnv a
    senv StringTemplate a
    t)

    -- | Returns a tuple of three lists. The first is of templates with parse errors, and their errors. The next is of missing attributes, and the last is of missing templates. If there are no errors, then all lists will be empty. This check is performed recursively.
    checkTemplateDeep :: (Stringable a, NFData a) => StringTemplate a -> ([(String,String)], [String], [String])
    checkTemplateDeep :: forall a.
    (Stringable a, NFData a) =>
    StringTemplate a -> ([([Char], [Char])], [[Char]], [[Char]])
    checkTemplateDeep StringTemplate a
    t = case StringTemplate a -> Either [Char] (SEnv a -> a)
    forall a. StringTemplate a -> Either [Char] (SEnv a -> a)
    runSTMP StringTemplate a
    t of
                            Left [Char]
    err -> ([([Char]
    "Top Level Template", [Char]
    err)], [],[])
                            Right SEnv a -> a
    _ -> IO ([([Char], [Char])], [[Char]], [[Char]])
    -> ([([Char], [Char])], [[Char]], [[Char]])
    forall a. IO a -> a
    unsafePerformIO (IO ([([Char], [Char])], [[Char]], [[Char]])
     -> ([([Char], [Char])], [[Char]], [[Char]]))
    -> IO ([([Char], [Char])], [[Char]], [[Char]])
    -> ([([Char], [Char])], [[Char]], [[Char]])
    forall a b. (a -> b) -> a -> b
    $ ([([Char], [Char])], [[Char]], [[Char]])
    -> StringTemplate a -> IO ([([Char], [Char])], [[Char]], [[Char]])
    forall {a}.
    (NFData a, Stringable a) =>
    ([([Char], [Char])], [[Char]], [[Char]])
    -> StringTemplate a -> IO ([([Char], [Char])], [[Char]], [[Char]])
    go ([],[],[]) (StringTemplate a -> IO ([([Char], [Char])], [[Char]], [[Char]]))
    -> StringTemplate a -> IO ([([Char], [Char])], [[Char]], [[Char]])
    forall a b. (a -> b) -> a -> b
    $ (STGroup a -> STGroup a) -> StringTemplate a -> StringTemplate a
    forall a.
    (STGroup a -> STGroup a) -> StringTemplate a -> StringTemplate a
    inSGen (STGroup a -> STGroup a -> STGroup a
    forall a. Monoid a => a -> a -> a
    `mappend` STGroup a
    forall {a}. [Char] -> StFirst a
    nullGroup) (StringTemplate a -> StringTemplate a)
    -> StringTemplate a -> StringTemplate a
    forall a b. (a -> b) -> a -> b
    $ [([Char], [Char])] -> StringTemplate a -> StringTemplate a
    forall a.
    [([Char], [Char])] -> StringTemplate a -> StringTemplate a
    optInsertTmpl [([Char]
    "throwException",[Char]
    "true")] StringTemplate a
    t
        where go :: ([([Char], [Char])], [[Char]], [[Char]])
    -> StringTemplate a -> IO ([([Char], [Char])], [[Char]], [[Char]])
    go ([([Char], [Char])]
    e1,[[Char]]
    e2,[[Char]]
    e3) StringTemplate a
    tmpl = (() -> IO ()
    forall a. a -> IO a
    C.evaluate (a -> ()
    forall a. NFData a => a -> ()
    rnf (a -> ()) -> a -> ()
    forall a b. (a -> b) -> a -> b
    $ StringTemplate a -> a
    forall a. Stringable a => StringTemplate a -> a
    render StringTemplate a
    tmpl) IO ()
    -> IO ([([Char], [Char])], [[Char]], [[Char]])
    -> IO ([([Char], [Char])], [[Char]], [[Char]])
    forall a b. IO a -> IO b -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> ([([Char], [Char])], [[Char]], [[Char]])
    -> IO ([([Char], [Char])], [[Char]], [[Char]])
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ([([Char], [Char])]
    e1,[[Char]]
    e2,[[Char]]
    e3)) IO ([([Char], [Char])], [[Char]], [[Char]])
    -> (TmplException -> IO ([([Char], [Char])], [[Char]], [[Char]]))
    -> IO ([([Char], [Char])], [[Char]], [[Char]])
    forall e a. Exception e => IO a -> (e -> IO a) -> IO a
    `C.catch`
                                      \TmplException
    e -> case TmplException
    e of NoTmpl [Char]
    x -> ([([Char], [Char])], [[Char]], [[Char]])
    -> StringTemplate a -> IO ([([Char], [Char])], [[Char]], [[Char]])
    go ([([Char], [Char])]
    e1,[[Char]]
    e2,[Char]
    x[Char] -> [[Char]] -> [[Char]]
    forall a. a -> [a] -> [a]
    :[[Char]]
    e3) (StringTemplate a -> IO ([([Char], [Char])], [[Char]], [[Char]]))
    -> StringTemplate a -> IO ([([Char], [Char])], [[Char]], [[Char]])
    forall a b. (a -> b) -> a -> b
    $ [Char] -> StringTemplate a -> StringTemplate a
    forall {a}.
    Stringable a =>
    [Char] -> StringTemplate a -> StringTemplate a
    addSub [Char]
    x StringTemplate a
    tmpl
                                                      NoAttrib [Char]
    x -> ([([Char], [Char])], [[Char]], [[Char]])
    -> StringTemplate a -> IO ([([Char], [Char])], [[Char]], [[Char]])
    go ([([Char], [Char])]
    e1,[Char]
    x[Char] -> [[Char]] -> [[Char]]
    forall a. a -> [a] -> [a]
    :[[Char]]
    e2, [[Char]]
    e3) (StringTemplate a -> IO ([([Char], [Char])], [[Char]], [[Char]]))
    -> StringTemplate a -> IO ([([Char], [Char])], [[Char]], [[Char]])
    forall a b. (a -> b) -> a -> b
    $ [Char] -> [Char] -> StringTemplate a -> StringTemplate a
    forall a b.
    (ToSElem a, Stringable b) =>
    [Char] -> a -> StringTemplate b -> StringTemplate b
    setAttribute [Char]
    x [Char]
    "" StringTemplate a
    tmpl
                                                      ParseError [Char]
    n [Char]
    x -> ([([Char], [Char])], [[Char]], [[Char]])
    -> StringTemplate a -> IO ([([Char], [Char])], [[Char]], [[Char]])
    go (([Char]
    n,[Char]
    x)([Char], [Char]) -> [([Char], [Char])] -> [([Char], [Char])]
    forall a. a -> [a] -> [a]
    :[([Char], [Char])]
    e1,[[Char]]
    e2,[[Char]]
    e3) (StringTemplate a -> IO ([([Char], [Char])], [[Char]], [[Char]]))
    -> StringTemplate a -> IO ([([Char], [Char])], [[Char]], [[Char]])
    forall a b. (a -> b) -> a -> b
    $ [Char] -> StringTemplate a -> StringTemplate a
    forall {a}.
    Stringable a =>
    [Char] -> StringTemplate a -> StringTemplate a
    addSub [Char]
    n StringTemplate a
    tmpl
              addSub :: [Char] -> StringTemplate a -> StringTemplate a
    addSub [Char]
    x StringTemplate a
    tmpl = (STGroup a -> STGroup a) -> StringTemplate a -> StringTemplate a
    forall a.
    (STGroup a -> STGroup a) -> StringTemplate a -> StringTemplate a
    inSGen (STGroup a -> STGroup a -> STGroup a
    forall a. Monoid a => a -> a -> a
    mappend (STGroup a -> STGroup a -> STGroup a)
    -> STGroup a -> STGroup a -> STGroup a
    forall a b. (a -> b) -> a -> b
    $ [Char] -> STGroup a
    forall {a} {a}.
    (Eq a, Stringable a) =>
    a -> a -> StFirst (StringTemplate a)
    blankGroup [Char]
    x) StringTemplate a
    tmpl
              blankGroup :: a -> a -> StFirst (StringTemplate a)
    blankGroup a
    x a
    s = Maybe (StringTemplate a) -> StFirst (StringTemplate a)
    forall a. Maybe a -> StFirst a
    StFirst (Maybe (StringTemplate a) -> StFirst (StringTemplate a))
    -> Maybe (StringTemplate a) -> StFirst (StringTemplate a)
    forall a b. (a -> b) -> a -> b
    $ if a
    x a -> a -> Bool
    forall a. Eq a => a -> a -> Bool
    == a
    s then StringTemplate a -> Maybe (StringTemplate a)
    forall a. a -> Maybe a
    Just ([Char] -> StringTemplate a
    forall a. Stringable a => [Char] -> StringTemplate a
    newSTMP [Char]
    "") else Maybe (StringTemplate a)
    forall a. Maybe a
    Nothing
              nullGroup :: [Char] -> StFirst a
    nullGroup [Char]
    x = Maybe a -> StFirst a
    forall a. Maybe a -> StFirst a
    StFirst (Maybe a -> StFirst a) -> Maybe a -> StFirst a
    forall a b. (a -> b) -> a -> b
    $ a -> Maybe a
    forall a. a -> Maybe a
    Just (TmplException -> a
    forall a e. (HasCallStack, Exception e) => e -> a
    C.throw (TmplException -> a) -> TmplException -> a
    forall a b. (a -> b) -> a -> b
    $ [Char] -> TmplException
    NoTmpl [Char]
    x)

    {--------------------------------------------------------------------
      Internal API for polymorphic display of elements
    --------------------------------------------------------------------}

    mconcatMap' :: Stringable a => SEnv a -> [b] -> (b -> a) -> a
    mconcatMap' :: forall a b. Stringable a => SEnv a -> [b] -> (b -> a) -> a
    mconcatMap' SEnv a
    snv [b]
    xs b -> a
    f = a -> [a] -> a
    forall a. Stringable a => a -> [a] -> a
    mintercalate a
    sep ([a] -> a) -> ([b] -> [a]) -> [b] -> a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (b -> a) -> [b] -> [a]
    forall a b. (a -> b) -> [a] -> [b]
    map b -> a
    f ([b] -> a) -> [b] -> a
    forall a b. (a -> b) -> a -> b
    $ [b]
    xs
        where sep :: a
    sep = SEnv a -> SElem a -> a
    forall a. Stringable a => SEnv a -> SElem a -> a
    showVal SEnv a
    snv (SElem a -> a) -> SElem a -> a
    forall a b. (a -> b) -> a -> b
    $ (SEnv a -> SElem a)
    -> Maybe (SEnv a -> SElem a) -> SEnv a -> SElem a
    forall a. a -> Maybe a -> a
    fromMaybe ([Char] -> SEnv a -> SElem a
    forall b a. [Char] -> b -> SElem a
    justSTR [Char]
    "") (Maybe (SEnv a -> SElem a) -> SEnv a -> SElem a)
    -> (SEnv a -> Maybe (SEnv a -> SElem a)) -> SEnv a -> SElem a
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
    =<< [Char] -> SEnv a -> Maybe (SEnv a -> SElem a)
    forall a. [Char] -> SEnv a -> Maybe (SEnv a -> SElem a)
    optLookup [Char]
    "separator" (SEnv a -> SElem a) -> SEnv a -> SElem a
    forall a b. (a -> b) -> a -> b
    $ SEnv a
    snv

    showVal :: Stringable a => SEnv a -> SElem a -> a
    showVal :: forall a. Stringable a => SEnv a -> SElem a -> a
    showVal SEnv a
    snv SElem a
    se = case SElem a
    se of
                       STR [Char]
    x  -> [Char] -> a
    stEncode [Char]
    x
                       BS  ByteString
    x  -> ByteString -> a
    stEncodeBS ByteString
    x
                       TXT Text
    x  -> Text -> a
    stEncodeText Text
    x
                       LI [SElem a]
    xs  -> (SEnv a -> SElem a -> a) -> [SElem a] -> a
    forall {b}. (SEnv a -> b -> a) -> [b] -> a
    joinUpWith SEnv a -> SElem a -> a
    forall a. Stringable a => SEnv a -> SElem a -> a
    showVal [SElem a]
    xs
                       SM SMap a
    sm  -> (SEnv a -> ([Char], SElem a) -> a) -> [([Char], SElem a)] -> a
    forall {b}. (SEnv a -> b -> a) -> [b] -> a
    joinUpWith SEnv a -> ([Char], SElem a) -> a
    showAssoc ([([Char], SElem a)] -> a) -> [([Char], SElem a)] -> a
    forall a b. (a -> b) -> a -> b
    $ SMap a -> [([Char], SElem a)]
    forall k a. Map k a -> [(k, a)]
    M.assocs SMap a
    sm
                       STSH STShow
    x -> [Char] -> a
    stEncode (STShow -> [Char]
    format STShow
    x)
                       SNAT a
    x -> SEnv a -> a -> a
    forall a. SEnv a -> a -> a
    senc SEnv a
    snv a
    x
                       SBLE a
    x -> a
    x
                       SElem a
    SNull  -> SEnv a -> SElem a -> a
    forall a. Stringable a => SEnv a -> SElem a -> a
    showVal (SEnv a -> SElem a -> a) -> (SEnv a -> SElem a) -> SEnv a -> a
    forall a b. (SEnv a -> a -> b) -> (SEnv a -> a) -> SEnv a -> b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> SEnv a -> SElem a
    forall a. SEnv a -> SElem a
    nullOpt (SEnv a -> a) -> SEnv a -> a
    forall a b. (a -> b) -> a -> b
    $ SEnv a
    snv
        where format :: STShow -> [Char]
    format = (STShow -> [Char])
    -> ((SEnv a -> SElem a) -> STShow -> [Char])
    -> Maybe (SEnv a -> SElem a)
    -> STShow
    -> [Char]
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe STShow -> [Char]
    stshow (((SEnv a -> SElem a) -> STShow -> [Char])
     -> Maybe (SEnv a -> SElem a) -> STShow -> [Char])
    -> (SEnv a -> (SEnv a -> SElem a) -> STShow -> [Char])
    -> SEnv a
    -> Maybe (SEnv a -> SElem a)
    -> STShow
    -> [Char]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . SEnv a -> (SEnv a -> SElem a) -> STShow -> [Char]
    forall a.
    Stringable a =>
    SEnv a -> (SEnv a -> SElem a) -> STShow -> [Char]
    stfshow (SEnv a -> Maybe (SEnv a -> SElem a) -> STShow -> [Char])
    -> (SEnv a -> Maybe (SEnv a -> SElem a))
    -> SEnv a
    -> STShow
    -> [Char]
    forall a b. (SEnv a -> a -> b) -> (SEnv a -> a) -> SEnv a -> b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> [Char] -> SEnv a -> Maybe (SEnv a -> SElem a)
    forall a. [Char] -> SEnv a -> Maybe (SEnv a -> SElem a)
    optLookup [Char]
    "format" (SEnv a -> STShow -> [Char]) -> SEnv a -> STShow -> [Char]
    forall a b. (a -> b) -> a -> b
    $ SEnv a
    snv
              joinUpWith :: (SEnv a -> b -> a) -> [b] -> a
    joinUpWith SEnv a -> b -> a
    f [b]
    xs = SEnv a -> [b] -> (b -> a) -> a
    forall a b. Stringable a => SEnv a -> [b] -> (b -> a) -> a
    mconcatMap' SEnv a
    snv [b]
    xs (SEnv a -> b -> a
    f SEnv a
    snv)
              showAssoc :: SEnv a -> ([Char], SElem a) -> a
    showAssoc SEnv a
    e ([Char]
    k,SElem a
    v) = [Char] -> a
    stEncode ([Char]
    k [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ [Char]
    ": ") a -> a -> a
    forall a. Stringable a => a -> a -> a
    `mlabel` SEnv a -> SElem a -> a
    forall a. Stringable a => SEnv a -> SElem a -> a
    showVal SEnv a
    e SElem a
    v
              stEncode :: [Char] -> a
    stEncode     = SEnv a -> a -> a
    forall a. SEnv a -> a -> a
    senc SEnv a
    snv (a -> a) -> ([Char] -> a) -> [Char] -> a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Char] -> a
    forall a. Stringable a => [Char] -> a
    stFromString
              stEncodeBS :: ByteString -> a
    stEncodeBS   = SEnv a -> a -> a
    forall a. SEnv a -> a -> a
    senc SEnv a
    snv (a -> a) -> (ByteString -> a) -> ByteString -> a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ByteString -> a
    forall a. Stringable a => ByteString -> a
    stFromByteString
              stEncodeText :: Text -> a
    stEncodeText = SEnv a -> a -> a
    forall a. SEnv a -> a -> a
    senc SEnv a
    snv (a -> a) -> (Text -> a) -> Text -> a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> a
    forall a. Stringable a => Text -> a
    stFromText

    showStr :: Stringable a => String -> SEnv a -> a
    showStr :: forall a. Stringable a => [Char] -> SEnv a -> a
    showStr = a -> SEnv a -> a
    forall a b. a -> b -> a
    const (a -> SEnv a -> a) -> ([Char] -> a) -> [Char] -> SEnv a -> a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Char] -> a
    forall a. Stringable a => [Char] -> a
    stFromString

    {--------------------------------------------------------------------
      Utility Combinators
    --------------------------------------------------------------------}

    justSTR :: String -> b -> SElem a
    justSTR :: forall b a. [Char] -> b -> SElem a
    justSTR = SElem a -> b -> SElem a
    forall a b. a -> b -> a
    const (SElem a -> b -> SElem a)
    -> ([Char] -> SElem a) -> [Char] -> b -> SElem a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Char] -> SElem a
    forall a. [Char] -> SElem a
    STR
    stshow :: STShow -> String
    stshow :: STShow -> [Char]
    stshow (STShow a
    a) = a -> [Char]
    forall a. StringTemplateShows a => a -> [Char]
    stringTemplateShow a
    a
    stfshow :: Stringable a => SEnv a -> (SEnv a -> SElem a) -> STShow -> String
    stfshow :: forall a.
    Stringable a =>
    SEnv a -> (SEnv a -> SElem a) -> STShow -> [Char]
    stfshow SEnv a
    snv SEnv a -> SElem a
    fs (STShow a
    a) = [Char] -> a -> [Char]
    forall a. StringTemplateShows a => [Char] -> a -> [Char]
    stringTemplateFormattedShow
                                (a -> [Char]
    forall a. Stringable a => a -> [Char]
    stToString (a -> [Char])
    -> (SEnv a -> SElem a -> a) -> SEnv a -> SElem a -> [Char]
    forall (f1 :: * -> *) (f :: * -> *) a b.
    (Functor f1, Functor f) =>
    (a -> b) -> f (f1 a) -> f (f1 b)
    <$$> SEnv a -> SElem a -> a
    forall a. Stringable a => SEnv a -> SElem a -> a
    showVal (SEnv a -> SElem a -> [Char])
    -> (SEnv a -> SElem a) -> SEnv a -> [Char]
    forall a b. (SEnv a -> a -> b) -> (SEnv a -> a) -> SEnv a -> b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> SEnv a -> SElem a
    fs (SEnv a -> [Char]) -> SEnv a -> [Char]
    forall a b. (a -> b) -> a -> b
    $ SEnv a
    snv) a
    a

    around :: Char -> GenParser Char st t -> Char -> GenParser Char st t
    around :: forall st t.
    Char -> GenParser Char st t -> Char -> GenParser Char st t
    around Char
    x GenParser Char st t
    p Char
    y = do {_ <- Char -> ParsecT [Char] st Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char Char
    x; v<-p; _ <- char y; return v}
    spaced :: GenParser Char st t -> GenParser Char st t
    spaced :: forall st t. GenParser Char st t -> GenParser Char st t
    spaced GenParser Char st t
    p = do {ParsecT [Char] st Identity ()
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
    spaces; v<-GenParser Char st t
    p; spaces; return v}

    identifierChar :: GenParser Char st Char
    identifierChar :: forall st. GenParser Char st Char
    identifierChar = ParsecT [Char] st Identity Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    alphaNum ParsecT [Char] st Identity Char
    -> ParsecT [Char] st Identity Char
    -> ParsecT [Char] st Identity Char
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Char -> ParsecT [Char] st Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char Char
    '_'

    word :: GenParser Char st String
    word :: forall st. GenParser Char st [Char]
    word = ParsecT [Char] st Identity Char
    -> ParsecT [Char] st Identity [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many1 ParsecT [Char] st Identity Char
    forall st. GenParser Char st Char
    identifierChar

    comlist :: GenParser Char st a -> GenParser Char st [a]
    comlist :: forall st a. GenParser Char st a -> GenParser Char st [a]
    comlist GenParser Char st a
    p = GenParser Char st [a] -> GenParser Char st [a]
    forall st t. GenParser Char st t -> GenParser Char st t
    spaced (GenParser Char st a
    p GenParser Char st a
    -> ParsecT [Char] st Identity Char -> GenParser Char st [a]
    forall s (m :: * -> *) t u a sep.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
    `sepBy1` ParsecT [Char] st Identity Char -> ParsecT [Char] st Identity Char
    forall st t. GenParser Char st t -> GenParser Char st t
    spaced (Char -> ParsecT [Char] st Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char Char
    ','))

    props :: Stringable a => TmplParser [SEnv a -> SElem a]
    props :: forall a. Stringable a => TmplParser [SEnv a -> SElem a]
    props = ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      (SEnv a -> SElem a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         [SEnv a -> SElem a]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many (ParsecT
       [Char]
       ((Char, Char), [[Char]], [[Char]], [[Char]])
       Identity
       (SEnv a -> SElem a)
     -> ParsecT
          [Char]
          ((Char, Char), [[Char]], [[Char]], [[Char]])
          Identity
          [SEnv a -> SElem a])
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         [SEnv a -> SElem a]
    forall a b. (a -> b) -> a -> b
    $ Char
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char Char
    '.' ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    forall a b.
    ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity a
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity b
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> (Char
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    -> Char
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    forall st t.
    Char -> GenParser Char st t -> Char -> GenParser Char st t
    around Char
    '(' ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      (SEnv a -> SElem a)
    forall a. Stringable a => TmplParser (SEnv a -> SElem a)
    subexprn Char
    ')' ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      (SEnv a -> SElem a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> [Char] -> SEnv a -> SElem a
    forall b a. [Char] -> b -> SElem a
    justSTR ([Char] -> SEnv a -> SElem a)
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    forall st. GenParser Char st [Char]
    word)

    escapedChar, escapedStr :: String -> GenParser Char st String
    escapedChar :: forall st. [Char] -> GenParser Char st [Char]
    escapedChar [Char]
    chs =
        [Char] -> ParsecT [Char] st Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m Char
    noneOf [Char]
    chs ParsecT [Char] st Identity Char
    -> (Char -> ParsecT [Char] st Identity [Char])
    -> ParsecT [Char] st Identity [Char]
    forall a b.
    ParsecT [Char] st Identity a
    -> (a -> ParsecT [Char] st Identity b)
    -> ParsecT [Char] st Identity b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= \Char
    x -> if Char
    x Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    == Char
    '\\' then ParsecT [Char] st Identity Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    anyChar ParsecT [Char] st Identity Char
    -> (Char -> ParsecT [Char] st Identity [Char])
    -> ParsecT [Char] st Identity [Char]
    forall a b.
    ParsecT [Char] st Identity a
    -> (a -> ParsecT [Char] st Identity b)
    -> ParsecT [Char] st Identity b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= \Char
    y -> [Char] -> ParsecT [Char] st Identity [Char]
    forall a. a -> ParsecT [Char] st Identity a
    forall (m :: * -> *) a. Monad m => a -> m a
    return [Char
    y] else [Char] -> ParsecT [Char] st Identity [Char]
    forall a. a -> ParsecT [Char] st Identity a
    forall (m :: * -> *) a. Monad m => a -> m a
    return [Char
    x]
    escapedStr :: forall st. [Char] -> GenParser Char st [Char]
    escapedStr [Char]
    chs = [[Char]] -> [Char]
    forall (t :: * -> *) a. Foldable t => t [a] -> [a]
    concat ([[Char]] -> [Char])
    -> ParsecT [Char] st Identity [[Char]]
    -> ParsecT [Char] st Identity [Char]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT [Char] st Identity [Char]
    -> ParsecT [Char] st Identity [[Char]]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many1 ([Char] -> ParsecT [Char] st Identity [Char]
    forall st. [Char] -> GenParser Char st [Char]
    escapedChar [Char]
    chs)

    {-
    escapedStr' chs = dropTrailingBr <$> escapedStr chs
    -}

    {--------------------------------------------------------------------
      The Grammar
    --------------------------------------------------------------------}
    myConcat :: Stringable a => [SEnv a -> a] -> (SEnv a -> a)
    myConcat :: forall a. Stringable a => [SEnv a -> a] -> SEnv a -> a
    myConcat [SEnv a -> a]
    xs SEnv a
    a = [SEnv a -> a] -> ((SEnv a -> a) -> a) -> a
    forall b. [b] -> (b -> a) -> a
    forall a b. Stringable a => [b] -> (b -> a) -> a
    mconcatMap [SEnv a -> a]
    xs ((SEnv a -> a) -> SEnv a -> a
    forall a b. (a -> b) -> a -> b
    $ SEnv a
    a)

    -- | if p is true, stmpl can fail gracefully, false it dies hard.
    -- Set to false at the top level, and true within if expressions.
    stmpl :: Stringable a => Bool -> TmplParser (SEnv a -> a)
    stmpl :: forall a. Stringable a => Bool -> TmplParser (SEnv a -> a)
    stmpl Bool
    p = do
      (ca, cb) <- TmplParser (Char, Char)
    getSeps
      myConcat <$> many (showStr <$> escapedStr [ca] <|> try (around ca optExpr cb)
                        <|> try comment <|> bl <?> "template")
          where bl :: ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      (SEnv a -> a)
    bl | Bool
    p = ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      (SEnv a -> a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> a)
    forall tok st a. GenParser tok st a -> GenParser tok st a
    try ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      (SEnv a -> a)
    forall a. Stringable a => TmplParser (SEnv a -> a)
    blank | Bool
    otherwise = ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      (SEnv a -> a)
    forall a. Stringable a => TmplParser (SEnv a -> a)
    blank

    subStmp :: Stringable a => TmplParser (([SElem a], [SElem a]) -> SEnv a -> a)
    subStmp :: forall a.
    Stringable a =>
    TmplParser (([SElem a], [SElem a]) -> SEnv a -> a)
    subStmp = do
      (ca, cb) <- TmplParser (Char, Char)
    getSeps
      udEnv <- option (transform ["it"]) (transform <$> try attribNames)
      st <- myConcat <$> many (showStr <$> escapedStr (ca:"}|")
                             <|> try (around ca optExpr cb)
                             <|> try comment <|> blank  <?> "subtemplate")
      return (st <$$> udEnv)
          where transform :: [[Char]] -> ([SElem a], [SElem a]) -> SEnv a -> SEnv a
    transform [[Char]]
    an ([SElem a]
    att,[SElem a]
    is) =
                    (SEnv a -> [([Char], SElem a)] -> SEnv a)
    -> [([Char], SElem a)] -> SEnv a -> SEnv a
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip ((([Char], SElem a) -> SEnv a -> SEnv a)
    -> SEnv a -> [([Char], SElem a)] -> SEnv a
    forall a b. (a -> b -> b) -> b -> [a] -> b
    forall (t :: * -> *) a b.
    Foldable t =>
    (a -> b -> b) -> b -> t a -> b
    foldr ([Char], SElem a) -> SEnv a -> SEnv a
    forall a. ([Char], SElem a) -> SEnv a -> SEnv a
    envInsert) ([([Char], SElem a)] -> SEnv a -> SEnv a)
    -> [([Char], SElem a)] -> SEnv a -> SEnv a
    forall a b. (a -> b) -> a -> b
    $ [[Char]] -> [SElem a] -> [([Char], SElem a)]
    forall a b. [a] -> [b] -> [(a, b)]
    zip ([Char]
    "i"[Char] -> [[Char]] -> [[Char]]
    forall a. a -> [a] -> [a]
    :[Char]
    "i0"[Char] -> [[Char]] -> [[Char]]
    forall a. a -> [a] -> [a]
    :[[Char]]
    an) ([SElem a]
    is[SElem a] -> [SElem a] -> [SElem a]
    forall a. [a] -> [a] -> [a]
    ++[SElem a]
    att)
                attribNames :: ParsecT [Char] u Identity [[Char]]
    attribNames = (Char -> ParsecT [Char] u Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char Char
    '|' ParsecT [Char] u Identity Char
    -> ParsecT [Char] u Identity [[Char]]
    -> ParsecT [Char] u Identity [[Char]]
    forall a b.
    ParsecT [Char] u Identity a
    -> ParsecT [Char] u Identity b -> ParsecT [Char] u Identity b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >>) (ParsecT [Char] u Identity [[Char]]
     -> ParsecT [Char] u Identity [[Char]])
    -> ([[Char]] -> ParsecT [Char] u Identity [[Char]])
    -> [[Char]]
    -> ParsecT [Char] u Identity [[Char]]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [[Char]] -> ParsecT [Char] u Identity [[Char]]
    forall a. a -> ParsecT [Char] u Identity a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ([[Char]] -> ParsecT [Char] u Identity [[Char]])
    -> ParsecT [Char] u Identity [[Char]]
    -> ParsecT [Char] u Identity [[Char]]
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
    =<< GenParser Char u [Char] -> ParsecT [Char] u Identity [[Char]]
    forall st a. GenParser Char st a -> GenParser Char st [a]
    comlist (GenParser Char u [Char] -> GenParser Char u [Char]
    forall st t. GenParser Char st t -> GenParser Char st t
    spaced GenParser Char u [Char]
    forall st. GenParser Char st [Char]
    word)

    comment :: Stringable a => TmplParser (SEnv a -> a)
    comment :: forall a. Stringable a => TmplParser (SEnv a -> a)
    comment = do
      (ca, cb) <- TmplParser (Char, Char)
    getSeps
      _ <- string [ca,'!'] >> manyTill anyChar (try . string $ ['!',cb])
      return (showStr "")

    blank :: Stringable a => TmplParser (SEnv a -> a)
    blank :: forall a. Stringable a => TmplParser (SEnv a -> a)
    blank = do
      (ca, cb) <- TmplParser (Char, Char)
    getSeps
      _ <- char ca
      spaces
      _ <- char cb
      return (showStr "")

    optExpr :: Stringable a => TmplParser (SEnv a -> a)
    optExpr :: forall a. Stringable a => TmplParser (SEnv a -> a)
    optExpr = do
      (_, cb) <- TmplParser (Char, Char)
    getSeps
      (try (string ("else"++[cb])) <|> try (string "elseif(") <|>
        try (string "endif")) .>> fail "Malformed If Statement." <|> return ()
      expr <- try ifstat <|> spaced exprn
      opts <- (char ';' >> optList) <|> return []
      return $ expr . optInsert opts
          where -- opt = around ';' (spaced word) '=' >>= (<$> spaced subexprn) . (,)
                optList :: ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      [([Char], SEnv a -> SElem a)]
    optList = ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      ([Char], SEnv a -> SElem a)
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         [([Char], SEnv a -> SElem a)]
    forall s (m :: * -> *) t u a sep.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
    sepBy ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      ([Char], SEnv a -> SElem a)
    oneOpt (Char
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char Char
    ',' ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Char
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char Char
    ';')
                oneOpt :: ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      ([Char], SEnv a -> SElem a)
    oneOpt = do
                  o <- ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    forall st t. GenParser Char st t -> GenParser Char st t
    spaced ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    forall st. GenParser Char st [Char]
    word
                  _ <- char '='
                  v <- spaced subexprn
                  return (o,v)

    {--------------------------------------------------------------------
      Statements
    --------------------------------------------------------------------}

    optLine :: TmplParser ()
    optLine :: TmplParser ()
    optLine = ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    -> TmplParser ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    optional (Char
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char Char
    '\r') TmplParser () -> TmplParser () -> TmplParser ()
    forall a b.
    ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity a
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity b
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    -> TmplParser ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    optional (Char
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char Char
    '\n')

    --if env then do stuff
    getProp :: Stringable a => [SEnv a -> SElem a] -> SElem a -> SEnv a -> SElem a
    getProp :: forall a.
    Stringable a =>
    [SEnv a -> SElem a] -> SElem a -> SEnv a -> SElem a
    getProp (SEnv a -> SElem a
    p:[SEnv a -> SElem a]
    ps) (SM SMap a
    mp) SEnv a
    env =
      case [Char] -> SMap a -> Maybe (SElem a)
    forall k a. Ord k => k -> Map k a -> Maybe a
    M.lookup (a -> [Char]
    forall a. Stringable a => a -> [Char]
    stToString (a -> [Char]) -> (SElem a -> a) -> SElem a -> [Char]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . SEnv a -> SElem a -> a
    forall a. Stringable a => SEnv a -> SElem a -> a
    showVal SEnv a
    env (SElem a -> [Char]) -> SElem a -> [Char]
    forall a b. (a -> b) -> a -> b
    $ SEnv a -> SElem a
    p SEnv a
    env) SMap a
    mp of
        Just SElem a
    prop -> [SEnv a -> SElem a] -> SElem a -> SEnv a -> SElem a
    forall a.
    Stringable a =>
    [SEnv a -> SElem a] -> SElem a -> SEnv a -> SElem a
    getProp [SEnv a -> SElem a]
    ps SElem a
    prop SEnv a
    env
        Maybe (SElem a)
    Nothing -> case [Char] -> SEnv a -> Maybe (SEnv a -> SElem a)
    forall a. [Char] -> SEnv a -> Maybe (SEnv a -> SElem a)
    optLookup [Char]
    "throwException" SEnv a
    env of
                     Just SEnv a -> SElem a
    _ -> TmplException -> SElem a
    forall a e. (HasCallStack, Exception e) => e -> a
    C.throw (TmplException -> SElem a)
    -> ([Char] -> TmplException) -> [Char] -> SElem a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Char] -> TmplException
    NoAttrib ([Char] -> SElem a) -> [Char] -> SElem a
    forall a b. (a -> b) -> a -> b
    $ [Char]
    "yeek" --intercalate "." . map showIt $ (p:ps)
                     Maybe (SEnv a -> SElem a)
    Nothing -> SElem a
    forall a. SElem a
    SNull
      --where showIt x = stToString . showVal env $ x env
    getProp (SEnv a -> SElem a
    _:[SEnv a -> SElem a]
    _) SElem a
    _ SEnv a
    _ = SElem a
    forall a. SElem a
    SNull
    getProp [SEnv a -> SElem a]
    _ SElem a
    se SEnv a
    _ = SElem a
    se

    ifIsSet :: t -> t -> Bool -> SElem a -> t
    ifIsSet :: forall t a. t -> t -> Bool -> SElem a -> t
    ifIsSet t
    t t
    e Bool
    n SElem a
    SNull = if Bool
    n then t
    e else t
    t
    ifIsSet t
    t t
    e Bool
    n SElem a
    _ = if Bool
    n then t
    t else t
    e

    ifstat ::Stringable a => TmplParser (SEnv a -> a)
    ifstat :: forall a. Stringable a => TmplParser (SEnv a -> a)
    ifstat = do
      (_, cb) <- TmplParser (Char, Char)
    getSeps
      _ <- string "if("
      n <- option True (char '!' >> return False)
      e <- subexprn
      p <- props
      char ')' >> char cb >> optLine
      act <- stmpl True
      cont <- (try elseifstat <|> try elsestat <|> endifstat)
      return (ifIsSet act cont n =<< getProp p =<< e)

    elseifstat ::Stringable a => TmplParser (SEnv a -> a)
    elseifstat :: forall a. Stringable a => TmplParser (SEnv a -> a)
    elseifstat = TmplParser (Char, Char)
    getSeps TmplParser (Char, Char)
    -> ((Char, Char)
        -> ParsecT
             [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char)
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    forall a b.
    ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity a
    -> (a
        -> ParsecT
             [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity b)
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Char
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char (Char
     -> ParsecT
          [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char)
    -> ((Char, Char) -> Char)
    -> (Char, Char)
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Char, Char) -> Char
    forall a b. (a, b) -> a
    fst ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    forall a b.
    ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity a
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity b
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> [Char]
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m [Char]
    string [Char]
    "else" ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> a)
    forall a b.
    ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity a
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity b
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      (SEnv a -> a)
    forall a. Stringable a => TmplParser (SEnv a -> a)
    ifstat

    elsestat ::Stringable a => TmplParser (SEnv a -> a)
    elsestat :: forall a. Stringable a => TmplParser (SEnv a -> a)
    elsestat = do
      (ca, cb) <- TmplParser (Char, Char)
    getSeps
      _ <- around ca (string "else") cb
      optLine
      act <- stmpl True
      _ <- char ca >> string "endif"
      return act

    endifstat ::Stringable a => TmplParser (SEnv a -> a)
    endifstat :: forall a. Stringable a => TmplParser (SEnv a -> a)
    endifstat = TmplParser (Char, Char)
    getSeps TmplParser (Char, Char)
    -> ((Char, Char)
        -> ParsecT
             [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char)
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    forall a b.
    ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity a
    -> (a
        -> ParsecT
             [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity b)
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Char
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char (Char
     -> ParsecT
          [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char)
    -> ((Char, Char) -> Char)
    -> (Char, Char)
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Char, Char) -> Char
    forall a b. (a, b) -> a
    fst ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    forall a b.
    ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity a
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity b
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> [Char]
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m [Char]
    string [Char]
    "endif" ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> a)
    forall a b.
    ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity a
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity b
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> (SEnv a -> a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> a)
    forall a.
    a
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ([Char] -> SEnv a -> a
    forall a. Stringable a => [Char] -> SEnv a -> a
    showStr [Char]
    "")

    {--------------------------------------------------------------------
      Expressions
    --------------------------------------------------------------------}

    exprn :: Stringable a => TmplParser (SEnv a -> a)
    exprn :: forall a. Stringable a => TmplParser (SEnv a -> a)
    exprn = do
      exprs <- GenParser
      Char
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      (SEnv a -> SElem a)
    -> GenParser
         Char
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         [SEnv a -> SElem a]
    forall st a. GenParser Char st a -> GenParser Char st [a]
    comlist ( (a -> SElem a
    forall a. a -> SElem a
    SBLE (a -> SElem a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> a)
    -> GenParser
         Char
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         (SEnv a -> SElem a)
    forall (f1 :: * -> *) (f :: * -> *) a b.
    (Functor f1, Functor f) =>
    (a -> b) -> f (f1 a) -> f (f1 b)
    <$$> Char
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> a)
    -> Char
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> a)
    forall st t.
    Char -> GenParser Char st t -> Char -> GenParser Char st t
    around Char
    '(' ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      (SEnv a -> a)
    forall a. Stringable a => TmplParser (SEnv a -> a)
    exprn Char
    ')')
                         GenParser
      Char
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      (SEnv a -> SElem a)
    -> GenParser
         Char
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         (SEnv a -> SElem a)
    -> GenParser
         Char
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         (SEnv a -> SElem a)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> GenParser
      Char
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      (SEnv a -> SElem a)
    forall a. Stringable a => TmplParser (SEnv a -> SElem a)
    subexprn)
                 GenParser
      Char
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      [SEnv a -> SElem a]
    -> [Char]
    -> GenParser
         Char
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         [SEnv a -> SElem a]
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> [Char] -> ParsecT s u m a
    <?> [Char]
    "expression"
      templ <- tmplChain
      return $ fromMany (showVal <*> head exprs)
                 ((sequence exprs >>=) . seqTmpls') templ
          where tmplChain :: ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      [[SElem a] -> SEnv a -> [a]]
    tmplChain = ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      ([SElem a] -> SEnv a -> [a])
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         [[SElem a] -> SEnv a -> [a]]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many (Char
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char Char
    ':' ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         ([SElem a] -> SEnv a -> [a])
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         ([SElem a] -> SEnv a -> [a])
    forall a b.
    ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity a
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity b
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> [([SElem a], [SElem a]) -> SEnv a -> a]
    -> [SElem a] -> SEnv a -> [a]
    forall a.
    Stringable a =>
    [([SElem a], [SElem a]) -> SEnv a -> a]
    -> [SElem a] -> SEnv a -> [a]
    iterApp ([([SElem a], [SElem a]) -> SEnv a -> a]
     -> [SElem a] -> SEnv a -> [a])
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         [([SElem a], [SElem a]) -> SEnv a -> a]
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         ([SElem a] -> SEnv a -> [a])
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> GenParser
      Char
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      (([SElem a], [SElem a]) -> SEnv a -> a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         [([SElem a], [SElem a]) -> SEnv a -> a]
    forall st a. GenParser Char st a -> GenParser Char st [a]
    comlist (GenParser
      Char
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      (([SElem a], [SElem a]) -> SEnv a -> a)
    forall a.
    Stringable a =>
    TmplParser (([SElem a], [SElem a]) -> SEnv a -> a)
    anonTmpl GenParser
      Char
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      (([SElem a], [SElem a]) -> SEnv a -> a)
    -> GenParser
         Char
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         (([SElem a], [SElem a]) -> SEnv a -> a)
    -> GenParser
         Char
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         (([SElem a], [SElem a]) -> SEnv a -> a)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> GenParser
      Char
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      (([SElem a], [SElem a]) -> SEnv a -> a)
    forall a.
    Stringable a =>
    TmplParser (([SElem a], [SElem a]) -> SEnv a -> a)
    regTemplate)) ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      [[SElem a] -> SEnv a -> [a]]
    -> [Char]
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         [[SElem a] -> SEnv a -> [a]]
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> [Char] -> ParsecT s u m a
    <?> [Char]
    "template call"

    seqTmpls' :: Stringable a => [[SElem a] -> SEnv a -> [a]] -> [SElem a] -> SEnv a -> a
    seqTmpls' :: forall a.
    Stringable a =>
    [[SElem a] -> SEnv a -> [a]] -> [SElem a] -> SEnv a -> a
    seqTmpls' [[SElem a] -> SEnv a -> [a]]
    tmpls [SElem a]
    elems SEnv a
    snv = a -> [a] -> a
    forall a. Stringable a => a -> [a] -> a
    mintercalate a
    sep ([a] -> a) -> [a] -> a
    forall a b. (a -> b) -> a -> b
    $ [[SElem a] -> SEnv a -> [a]] -> [SElem a] -> SEnv a -> [a]
    forall a.
    Stringable a =>
    [[SElem a] -> SEnv a -> [a]] -> [SElem a] -> SEnv a -> [a]
    seqTmpls [[SElem a] -> SEnv a -> [a]]
    tmpls [SElem a]
    elems SEnv a
    snv
        where sep :: a
    sep = SEnv a -> SElem a -> a
    forall a. Stringable a => SEnv a -> SElem a -> a
    showVal SEnv a
    snv (SElem a -> a) -> SElem a -> a
    forall a b. (a -> b) -> a -> b
    $ (SEnv a -> SElem a)
    -> Maybe (SEnv a -> SElem a) -> SEnv a -> SElem a
    forall a. a -> Maybe a -> a
    fromMaybe ([Char] -> SEnv a -> SElem a
    forall b a. [Char] -> b -> SElem a
    justSTR [Char]
    "") (Maybe (SEnv a -> SElem a) -> SEnv a -> SElem a)
    -> (SEnv a -> Maybe (SEnv a -> SElem a)) -> SEnv a -> SElem a
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
    =<< [Char] -> SEnv a -> Maybe (SEnv a -> SElem a)
    forall a. [Char] -> SEnv a -> Maybe (SEnv a -> SElem a)
    optLookup [Char]
    "separator" (SEnv a -> SElem a) -> SEnv a -> SElem a
    forall a b. (a -> b) -> a -> b
    $ SEnv a
    snv

    seqTmpls :: Stringable a => [[SElem a] -> SEnv a -> [a]] -> [SElem a] -> SEnv a -> [a]
    seqTmpls :: forall a.
    Stringable a =>
    [[SElem a] -> SEnv a -> [a]] -> [SElem a] -> SEnv a -> [a]
    seqTmpls [[SElem a] -> SEnv a -> [a]
    f]    [SElem a]
    y SEnv a
    snv = [SElem a] -> SEnv a -> [a]
    f [SElem a]
    y SEnv a
    snv
    seqTmpls ([SElem a] -> SEnv a -> [a]
    f:[[SElem a] -> SEnv a -> [a]]
    fs) [SElem a]
    y SEnv a
    snv = ([SElem a] -> [a]) -> [[SElem a]] -> [a]
    forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
    concatMap (\[SElem a]
    x -> [[SElem a] -> SEnv a -> [a]] -> [SElem a] -> SEnv a -> [a]
    forall a.
    Stringable a =>
    [[SElem a] -> SEnv a -> [a]] -> [SElem a] -> SEnv a -> [a]
    seqTmpls [[SElem a] -> SEnv a -> [a]]
    fs [SElem a]
    x SEnv a
    snv) ((a -> [SElem a]) -> [a] -> [[SElem a]]
    forall a b. (a -> b) -> [a] -> [b]
    map ((SElem a -> [SElem a] -> [SElem a]
    forall a. a -> [a] -> [a]
    :[]) (SElem a -> [SElem a]) -> (a -> SElem a) -> a -> [SElem a]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> SElem a
    forall a. a -> SElem a
    SBLE) ([a] -> [[SElem a]]) -> [a] -> [[SElem a]]
    forall a b. (a -> b) -> a -> b
    $ [SElem a] -> SEnv a -> [a]
    f [SElem a]
    y SEnv a
    snv)
    seqTmpls  [[SElem a] -> SEnv a -> [a]]
    _ [SElem a]
    _ SEnv a
    _   = [[Char] -> a
    forall a. Stringable a => [Char] -> a
    stFromString [Char]
    ""]

    subexprn :: Stringable a => TmplParser (SEnv a -> SElem a)
    subexprn :: forall a. Stringable a => TmplParser (SEnv a -> SElem a)
    subexprn = [SEnv a -> SElem a] -> SEnv a -> SElem a
    forall {t1}.
    Stringable t1 =>
    [SEnv t1 -> SElem t1] -> SEnv t1 -> SElem t1
    cct ([SEnv a -> SElem a] -> SEnv a -> SElem a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         [SEnv a -> SElem a]
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      (SEnv a -> SElem a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    forall st t. GenParser Char st t -> GenParser Char st t
    spaced
                (ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      (SEnv a -> SElem a)
    forall a. Stringable a => TmplParser (SEnv a -> SElem a)
    braceConcat
                 ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      (SEnv a -> SElem a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> a -> SElem a
    forall a. a -> SElem a
    SBLE (a -> SElem a)
    -> ((([SElem a], [SElem a]) -> SEnv a -> a) -> SEnv a -> a)
    -> (([SElem a], [SElem a]) -> SEnv a -> a)
    -> SEnv a
    -> SElem a
    forall (f1 :: * -> *) (f :: * -> *) a b.
    (Functor f1, Functor f) =>
    (a -> b) -> f (f1 a) -> f (f1 b)
    <$$> ((([SElem a], [SElem a]) -> SEnv a -> a)
    -> ([SElem a], [SElem a]) -> SEnv a -> a
    forall a b. (a -> b) -> a -> b
    $ ([SElem a
    forall a. SElem a
    SNull],[SElem a]
    forall a. [SElem a]
    ix0)) ((([SElem a], [SElem a]) -> SEnv a -> a) -> SEnv a -> SElem a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (([SElem a], [SElem a]) -> SEnv a -> a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      (([SElem a], [SElem a]) -> SEnv a -> a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (([SElem a], [SElem a]) -> SEnv a -> a)
    forall tok st a. GenParser tok st a -> GenParser tok st a
    try ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      (([SElem a], [SElem a]) -> SEnv a -> a)
    forall a.
    Stringable a =>
    TmplParser (([SElem a], [SElem a]) -> SEnv a -> a)
    regTemplate
                 ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      (SEnv a -> SElem a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      (SEnv a -> SElem a)
    forall a. Stringable a => TmplParser (SEnv a -> SElem a)
    attrib
                 ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      (SEnv a -> SElem a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> a -> SElem a
    forall a. a -> SElem a
    SBLE (a -> SElem a)
    -> ((([SElem a], [SElem a]) -> SEnv a -> a) -> SEnv a -> a)
    -> (([SElem a], [SElem a]) -> SEnv a -> a)
    -> SEnv a
    -> SElem a
    forall (f1 :: * -> *) (f :: * -> *) a b.
    (Functor f1, Functor f) =>
    (a -> b) -> f (f1 a) -> f (f1 b)
    <$$> ((([SElem a], [SElem a]) -> SEnv a -> a)
    -> ([SElem a], [SElem a]) -> SEnv a -> a
    forall a b. (a -> b) -> a -> b
    $ ([SElem a
    forall a. SElem a
    SNull],[SElem a]
    forall a. [SElem a]
    ix0)) ((([SElem a], [SElem a]) -> SEnv a -> a) -> SEnv a -> SElem a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (([SElem a], [SElem a]) -> SEnv a -> a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      (([SElem a], [SElem a]) -> SEnv a -> a)
    forall a.
    Stringable a =>
    TmplParser (([SElem a], [SElem a]) -> SEnv a -> a)
    anonTmpl
                 ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      (SEnv a -> SElem a)
    -> [Char]
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> [Char] -> ParsecT s u m a
    <?> [Char]
    "expression")
               ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      (SEnv a -> SElem a)
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         [SEnv a -> SElem a]
    forall s (m :: * -> *) t u a sep.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
    `sepBy1` ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    forall st t. GenParser Char st t -> GenParser Char st t
    spaced (Char
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char Char
    '+')
        where cct :: [SEnv t1 -> SElem t1] -> SEnv t1 -> SElem t1
    cct xs :: [SEnv t1 -> SElem t1]
    xs@(SEnv t1 -> SElem t1
    _:SEnv t1 -> SElem t1
    _:[SEnv t1 -> SElem t1]
    _) = t1 -> SElem t1
    forall a. a -> SElem a
    SBLE (t1 -> SElem t1) -> (SEnv t1 -> t1) -> SEnv t1 -> SElem t1
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    |.
                               ([SElem t1] -> (SElem t1 -> t1) -> t1)
    -> (SElem t1 -> t1) -> [SElem t1] -> t1
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip [SElem t1] -> (SElem t1 -> t1) -> t1
    forall b. [b] -> (b -> t1) -> t1
    forall a b. Stringable a => [b] -> (b -> a) -> a
    mconcatMap ((SElem t1 -> t1) -> [SElem t1] -> t1)
    -> (SEnv t1 -> SElem t1 -> t1) -> SEnv t1 -> [SElem t1] -> t1
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> SEnv t1 -> SElem t1 -> t1
    forall a. Stringable a => SEnv a -> SElem a -> a
    showVal (SEnv t1 -> [SElem t1] -> t1)
    -> (SEnv t1 -> [SElem t1]) -> SEnv t1 -> t1
    forall a b. (SEnv t1 -> a -> b) -> (SEnv t1 -> a) -> SEnv t1 -> b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> [SEnv t1 -> SElem t1] -> SEnv t1 -> [SElem t1]
    forall (t :: * -> *) (m :: * -> *) a.
    (Traversable t, Monad m) =>
    t (m a) -> m (t a)
    forall (m :: * -> *) a. Monad m => [m a] -> m [a]
    sequence [SEnv t1 -> SElem t1]
    xs
              cct [SEnv t1 -> SElem t1
    x] = SEnv t1 -> SElem t1
    x
              cct  [SEnv t1 -> SElem t1]
    _  = SElem t1 -> SEnv t1 -> SElem t1
    forall a b. a -> b -> a
    const SElem t1
    forall a. SElem a
    SNull

    braceConcat :: Stringable a => TmplParser (SEnv a -> SElem a)
    braceConcat :: forall a. Stringable a => TmplParser (SEnv a -> SElem a)
    braceConcat = [SElem a] -> SElem a
    forall a. [SElem a] -> SElem a
    LI ([SElem a] -> SElem a)
    -> ([SElem a] -> [SElem a]) -> [SElem a] -> SElem a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (SElem a -> [SElem a] -> [SElem a])
    -> [SElem a] -> [SElem a] -> [SElem a]
    forall a b. (a -> b -> b) -> b -> [a] -> b
    forall (t :: * -> *) a b.
    Foldable t =>
    (a -> b -> b) -> b -> t a -> b
    foldr SElem a -> [SElem a] -> [SElem a]
    forall {a}. SElem a -> [SElem a] -> [SElem a]
    go [] ([SElem a] -> SElem a)
    -> ([SEnv a -> SElem a] -> SEnv a -> [SElem a])
    -> [SEnv a -> SElem a]
    -> SEnv a
    -> SElem a
    forall (f1 :: * -> *) (f :: * -> *) a b.
    (Functor f1, Functor f) =>
    (a -> b) -> f (f1 a) -> f (f1 b)
    <$$> [SEnv a -> SElem a] -> SEnv a -> [SElem a]
    forall (t :: * -> *) (m :: * -> *) a.
    (Traversable t, Monad m) =>
    t (m a) -> m (t a)
    forall (m :: * -> *) a. Monad m => [m a] -> m [a]
    sequence ([SEnv a -> SElem a] -> SEnv a -> SElem a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         [SEnv a -> SElem a]
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Char
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         [SEnv a -> SElem a]
    -> Char
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         [SEnv a -> SElem a]
    forall st t.
    Char -> GenParser Char st t -> Char -> GenParser Char st t
    around Char
    '['(ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      (SEnv a -> SElem a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         [SEnv a -> SElem a]
    forall st a. GenParser Char st a -> GenParser Char st [a]
    comlist ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      (SEnv a -> SElem a)
    forall a. Stringable a => TmplParser (SEnv a -> SElem a)
    subexprn)Char
    ']'
        where go :: SElem a -> [SElem a] -> [SElem a]
    go (LI [SElem a]
    x) [SElem a]
    lst = [SElem a]
    x[SElem a] -> [SElem a] -> [SElem a]
    forall a. [a] -> [a] -> [a]
    ++[SElem a]
    lst; go SElem a
    x [SElem a]
    lst = SElem a
    xSElem a -> [SElem a] -> [SElem a]
    forall a. a -> [a] -> [a]
    :[SElem a]
    lst

    literal :: GenParser Char st (b -> SElem a)
    literal :: forall st b a. GenParser Char st (b -> SElem a)
    literal = [Char] -> b -> SElem a
    forall b a. [Char] -> b -> SElem a
    justSTR ([Char] -> b -> SElem a)
    -> ParsecT [Char] st Identity [Char]
    -> ParsecT [Char] st Identity (b -> SElem a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (Char
    -> ParsecT [Char] st Identity [Char]
    -> Char
    -> ParsecT [Char] st Identity [Char]
    forall st t.
    Char -> GenParser Char st t -> Char -> GenParser Char st t
    around Char
    '"' ([[Char]] -> [Char]
    forall (t :: * -> *) a. Foldable t => t [a] -> [a]
    concat ([[Char]] -> [Char])
    -> ParsecT [Char] st Identity [[Char]]
    -> ParsecT [Char] st Identity [Char]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT [Char] st Identity [Char]
    -> ParsecT [Char] st Identity [[Char]]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many ([Char] -> ParsecT [Char] st Identity [Char]
    forall st. [Char] -> GenParser Char st [Char]
    escapedChar [Char]
    "\"")) Char
    '"'
                       ParsecT [Char] st Identity [Char]
    -> ParsecT [Char] st Identity [Char]
    -> ParsecT [Char] st Identity [Char]
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Char
    -> ParsecT [Char] st Identity [Char]
    -> Char
    -> ParsecT [Char] st Identity [Char]
    forall st t.
    Char -> GenParser Char st t -> Char -> GenParser Char st t
    around Char
    '\'' ([[Char]] -> [Char]
    forall (t :: * -> *) a. Foldable t => t [a] -> [a]
    concat ([[Char]] -> [Char])
    -> ParsecT [Char] st Identity [[Char]]
    -> ParsecT [Char] st Identity [Char]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT [Char] st Identity [Char]
    -> ParsecT [Char] st Identity [[Char]]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many ([Char] -> ParsecT [Char] st Identity [Char]
    forall st. [Char] -> GenParser Char st [Char]
    escapedChar [Char]
    "'")) Char
    '\'')

    attrib :: Stringable a => TmplParser (SEnv a -> SElem a)
    attrib :: forall a. Stringable a => TmplParser (SEnv a -> SElem a)
    attrib = do
      a <-     GenParser
      Char
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      (SEnv a -> SElem a)
    forall st b a. GenParser Char st (b -> SElem a)
    literal
           GenParser
      Char
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      (SEnv a -> SElem a)
    -> GenParser
         Char
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         (SEnv a -> SElem a)
    -> GenParser
         Char
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         (SEnv a -> SElem a)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> GenParser
      Char
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      (SEnv a -> SElem a)
    -> GenParser
         Char
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         (SEnv a -> SElem a)
    forall tok st a. GenParser tok st a -> GenParser tok st a
    try GenParser
      Char
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      (SEnv a -> SElem a)
    forall a. Stringable a => TmplParser (SEnv a -> SElem a)
    functn
           GenParser
      Char
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      (SEnv a -> SElem a)
    -> GenParser
         Char
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         (SEnv a -> SElem a)
    -> GenParser
         Char
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         (SEnv a -> SElem a)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> [Char] -> SEnv a -> SElem a
    forall a. [Char] -> SEnv a -> SElem a
    envLookupEx ([Char] -> SEnv a -> SElem a)
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    -> GenParser
         Char
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         (SEnv a -> SElem a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    regWord
           GenParser
      Char
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      (SEnv a -> SElem a)
    -> GenParser
         Char
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         (SEnv a -> SElem a)
    -> GenParser
         Char
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         (SEnv a -> SElem a)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> [Char] -> SEnv a -> SElem a
    forall a. [Char] -> SEnv a -> SElem a
    envLookupEx ([Char] -> SEnv a -> SElem a)
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    -> GenParser
         Char
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         (SEnv a -> SElem a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    qqWord
           GenParser
      Char
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      (SEnv a -> SElem a)
    -> GenParser
         Char
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         (SEnv a -> SElem a)
    -> GenParser
         Char
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         (SEnv a -> SElem a)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Char
    -> GenParser
         Char
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         (SEnv a -> SElem a)
    -> Char
    -> GenParser
         Char
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         (SEnv a -> SElem a)
    forall st t.
    Char -> GenParser Char st t -> Char -> GenParser Char st t
    around Char
    '(' GenParser
      Char
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      (SEnv a -> SElem a)
    forall a. Stringable a => TmplParser (SEnv a -> SElem a)
    subexprn Char
    ')'
              GenParser
      Char
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      (SEnv a -> SElem a)
    -> [Char]
    -> GenParser
         Char
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         (SEnv a -> SElem a)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> [Char] -> ParsecT s u m a
    <?> [Char]
    "attribute"
      proprs <- props
      return $ fromMany a ((a >>=) . getProp) proprs
          where qqWord :: ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    qqWord = do
                  w <- Char
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    -> Char
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    forall st t.
    Char -> GenParser Char st t -> Char -> GenParser Char st t
    around Char
    '`' ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    forall st. GenParser Char st [Char]
    word Char
    '`'
                  tellQQ w
                  return $ '`' : w ++ "`"
                regWord :: ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    regWord = do
                  w <- ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    forall st. GenParser Char st [Char]
    word
                  tellName w
                  return w

    --add null func
    functn :: Stringable a => TmplParser (SEnv a -> SElem a)
    functn :: forall a. Stringable a => TmplParser (SEnv a -> SElem a)
    functn = do
      f <- [Char]
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m [Char]
    string [Char]
    "first" ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    forall tok st a. GenParser tok st a -> GenParser tok st a
    try ([Char]
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m [Char]
    string [Char]
    "rest") ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> [Char]
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m [Char]
    string [Char]
    "reverse"
           ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> [Char]
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m [Char]
    string [Char]
    "strip"
           ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    forall tok st a. GenParser tok st a -> GenParser tok st a
    try ([Char]
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m [Char]
    string [Char]
    "length") ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> [Char]
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m [Char]
    string [Char]
    "last" ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    -> [Char]
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> [Char] -> ParsecT s u m a
    <?> [Char]
    "function"
      (fApply f .) <$> around '(' subexprn ')'
          where fApply :: [Char] -> SElem a -> SElem a
    fApply [Char]
    str (LI [SElem a]
    xs)
                    | [Char]
    str [Char] -> [Char] -> Bool
    forall a. Eq a => a -> a -> Bool
    == [Char]
    "first"  = if [SElem a] -> Bool
    forall a. [a] -> Bool
    forall (t :: * -> *) a. Foldable t => t a -> Bool
    null [SElem a]
    xs then SElem a
    forall a. SElem a
    SNull else [SElem a] -> SElem a
    forall a. HasCallStack => [a] -> a
    head [SElem a]
    xs
                    | [Char]
    str [Char] -> [Char] -> Bool
    forall a. Eq a => a -> a -> Bool
    == [Char]
    "last"   = if [SElem a] -> Bool
    forall a. [a] -> Bool
    forall (t :: * -> *) a. Foldable t => t a -> Bool
    null [SElem a]
    xs then SElem a
    forall a. SElem a
    SNull else [SElem a] -> SElem a
    forall a. HasCallStack => [a] -> a
    last [SElem a]
    xs
                    | [Char]
    str [Char] -> [Char] -> Bool
    forall a. Eq a => a -> a -> Bool
    == [Char]
    "rest"   = if [SElem a] -> Bool
    forall a. [a] -> Bool
    forall (t :: * -> *) a. Foldable t => t a -> Bool
    null [SElem a]
    xs then SElem a
    forall a. SElem a
    SNull else ([SElem a] -> SElem a
    forall a. [SElem a] -> SElem a
    LI ([SElem a] -> SElem a)
    -> ([SElem a] -> [SElem a]) -> [SElem a] -> SElem a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [SElem a] -> [SElem a]
    forall a. HasCallStack => [a] -> [a]
    tail) [SElem a]
    xs
                    | [Char]
    str [Char] -> [Char] -> Bool
    forall a. Eq a => a -> a -> Bool
    == [Char]
    "reverse" = [SElem a] -> SElem a
    forall a. [SElem a] -> SElem a
    LI ([SElem a] -> SElem a)
    -> ([SElem a] -> [SElem a]) -> [SElem a] -> SElem a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [SElem a] -> [SElem a]
    forall a. [a] -> [a]
    reverse ([SElem a] -> SElem a) -> [SElem a] -> SElem a
    forall a b. (a -> b) -> a -> b
    $ [SElem a]
    xs
                    | [Char]
    str [Char] -> [Char] -> Bool
    forall a. Eq a => a -> a -> Bool
    == [Char]
    "strip"  = [SElem a] -> SElem a
    forall a. [SElem a] -> SElem a
    LI ([SElem a] -> SElem a)
    -> ([SElem a] -> [SElem a]) -> [SElem a] -> SElem a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (SElem a -> Bool) -> [SElem a] -> [SElem a]
    forall a. (a -> Bool) -> [a] -> [a]
    filter (Bool -> Bool
    not (Bool -> Bool) -> (SElem a -> Bool) -> SElem a -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . SElem a -> Bool
    forall {a}. SElem a -> Bool
    liNil) ([SElem a] -> SElem a) -> [SElem a] -> SElem a
    forall a b. (a -> b) -> a -> b
    $ [SElem a]
    xs
                    | [Char]
    str [Char] -> [Char] -> Bool
    forall a. Eq a => a -> a -> Bool
    == [Char]
    "length" = [Char] -> SElem a
    forall a. [Char] -> SElem a
    STR ([Char] -> SElem a)
    -> ([SElem a] -> [Char]) -> [SElem a] -> SElem a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int -> [Char]
    forall a. Show a => a -> [Char]
    show (Int -> [Char]) -> ([SElem a] -> Int) -> [SElem a] -> [Char]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [SElem a] -> Int
    forall a. [a] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length ([SElem a] -> SElem a) -> [SElem a] -> SElem a
    forall a b. (a -> b) -> a -> b
    $ [SElem a]
    xs
                fApply [Char]
    str SElem a
    x
                    | [Char]
    str [Char] -> [Char] -> Bool
    forall a. Eq a => a -> a -> Bool
    == [Char]
    "rest"   = [SElem a] -> SElem a
    forall a. [SElem a] -> SElem a
    LI []
                    | [Char]
    str [Char] -> [Char] -> Bool
    forall a. Eq a => a -> a -> Bool
    == [Char]
    "length" = [Char] -> SElem a
    forall a. [Char] -> SElem a
    STR [Char]
    "1"
                    | Bool
    otherwise       = SElem a
    x
                liNil :: SElem a -> Bool
    liNil (LI [SElem a]
    x) = [SElem a] -> Bool
    forall a. [a] -> Bool
    forall (t :: * -> *) a. Foldable t => t a -> Bool
    null [SElem a]
    x
                liNil SElem a
    _      = Bool
    False

    {--------------------------------------------------------------------
      Templates
    --------------------------------------------------------------------}
    --change makeTmpl to do notation for clarity?

    mkIndex :: (Num b, Show b) => [b] -> [[SElem a]]
    mkIndex :: forall b a. (Num b, Show b) => [b] -> [[SElem a]]
    mkIndex = (b -> [SElem a]) -> [b] -> [[SElem a]]
    forall a b. (a -> b) -> [a] -> [b]
    map ((:) (SElem a -> [SElem a] -> [SElem a])
    -> (b -> SElem a) -> b -> [SElem a] -> [SElem a]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Char] -> SElem a
    forall a. [Char] -> SElem a
    STR ([Char] -> SElem a) -> (b -> [Char]) -> b -> SElem a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . b -> [Char]
    forall a. Show a => a -> [Char]
    show (b -> [Char]) -> (b -> b) -> b -> [Char]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (b
    1b -> b -> b
    forall a. Num a => a -> a -> a
    +) (b -> [SElem a] -> [SElem a]) -> (b -> [SElem a]) -> b -> [SElem a]
    forall a b. (b -> a -> b) -> (b -> a) -> b -> b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> (SElem a -> [SElem a] -> [SElem a]
    forall a. a -> [a] -> [a]
    :[]) (SElem a -> [SElem a]) -> (b -> SElem a) -> b -> [SElem a]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Char] -> SElem a
    forall a. [Char] -> SElem a
    STR ([Char] -> SElem a) -> (b -> [Char]) -> b -> SElem a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . b -> [Char]
    forall a. Show a => a -> [Char]
    show)
    ix0 :: [SElem a]
    ix0 :: forall a. [SElem a]
    ix0 = [[Char] -> SElem a
    forall a. [Char] -> SElem a
    STR [Char]
    "1",[Char] -> SElem a
    forall a. [Char] -> SElem a
    STR [Char]
    "0"]

    cycleApp :: (Stringable a) => [([SElem a], [SElem a]) -> SEnv a -> a] -> [([SElem a], [SElem a])]  -> SEnv a -> [a]
    cycleApp :: forall a.
    Stringable a =>
    [([SElem a], [SElem a]) -> SEnv a -> a]
    -> [([SElem a], [SElem a])] -> SEnv a -> [a]
    cycleApp [([SElem a], [SElem a]) -> SEnv a -> a]
    x [([SElem a], [SElem a])]
    y SEnv a
    snv = ((SEnv a -> a) -> a) -> [SEnv a -> a] -> [a]
    forall a b. (a -> b) -> [a] -> [b]
    map ((SEnv a -> a) -> SEnv a -> a
    forall a b. (a -> b) -> a -> b
    $ SEnv a
    snv) (((([SElem a], [SElem a]) -> SEnv a -> a)
     -> ([SElem a], [SElem a]) -> SEnv a -> a)
    -> [([SElem a], [SElem a]) -> SEnv a -> a]
    -> [([SElem a], [SElem a])]
    -> [SEnv a -> a]
    forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
    zipWith (([SElem a], [SElem a]) -> SEnv a -> a)
    -> ([SElem a], [SElem a]) -> SEnv a -> a
    forall a b. (a -> b) -> a -> b
    ($) ([([SElem a], [SElem a]) -> SEnv a -> a]
    -> [([SElem a], [SElem a]) -> SEnv a -> a]
    forall a. HasCallStack => [a] -> [a]
    cycle [([SElem a], [SElem a]) -> SEnv a -> a]
    x) [([SElem a], [SElem a])]
    y)

    pluslen :: [a] -> [([a], [SElem b])]
    pluslen :: forall a b. [a] -> [([a], [SElem b])]
    pluslen [a]
    xs = [[a]] -> [[SElem b]] -> [([a], [SElem b])]
    forall a b. [a] -> [b] -> [(a, b)]
    zip ((a -> [a]) -> [a] -> [[a]]
    forall a b. (a -> b) -> [a] -> [b]
    map (a -> [a] -> [a]
    forall a. a -> [a] -> [a]
    :[]) [a]
    xs) ([[SElem b]] -> [([a], [SElem b])])
    -> [[SElem b]] -> [([a], [SElem b])]
    forall a b. (a -> b) -> a -> b
    $ [Int] -> [[SElem b]]
    forall b a. (Num b, Show b) => [b] -> [[SElem a]]
    mkIndex [Int
    0..([a] -> Int
    forall a. [a] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length [a]
    xs)]

    liTrans :: [SElem a] -> [([SElem a], [SElem a])]
    liTrans :: forall a. [SElem a] -> [([SElem a], [SElem a])]
    liTrans = [[SElem a]] -> [([SElem a], [SElem a])]
    forall {a} {a}. [a] -> [(a, [SElem a])]
    pluslen' ([[SElem a]] -> [([SElem a], [SElem a])])
    -> ([SElem a] -> [[SElem a]])
    -> [SElem a]
    -> [([SElem a], [SElem a])]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . SElem a -> [[SElem a]] -> [[SElem a]]
    forall a. a -> [[a]] -> [[a]]
    paddedTrans SElem a
    forall a. SElem a
    SNull ([[SElem a]] -> [[SElem a]])
    -> ([SElem a] -> [[SElem a]]) -> [SElem a] -> [[SElem a]]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (SElem a -> [SElem a]) -> [SElem a] -> [[SElem a]]
    forall a b. (a -> b) -> [a] -> [b]
    map SElem a -> [SElem a]
    forall {a}. SElem a -> [SElem a]
    u
        where u :: SElem a -> [SElem a]
    u (LI [SElem a]
    x) = [SElem a]
    x; u SElem a
    x = [SElem a
    x]
              pluslen' :: [a] -> [(a, [SElem a])]
    pluslen' [a]
    xs = [a] -> [[SElem a]] -> [(a, [SElem a])]
    forall a b. [a] -> [b] -> [(a, b)]
    zip [a]
    xs ([[SElem a]] -> [(a, [SElem a])])
    -> [[SElem a]] -> [(a, [SElem a])]
    forall a b. (a -> b) -> a -> b
    $ [Int] -> [[SElem a]]
    forall b a. (Num b, Show b) => [b] -> [[SElem a]]
    mkIndex [Int
    0..([a] -> Int
    forall a. [a] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length [a]
    xs)]

    --map repeatedly, then finally concat
    iterApp :: Stringable a => [([SElem a], [SElem a]) -> SEnv a -> a] -> [SElem a] -> SEnv a -> [a]
    iterApp :: forall a.
    Stringable a =>
    [([SElem a], [SElem a]) -> SEnv a -> a]
    -> [SElem a] -> SEnv a -> [a]
    iterApp [([SElem a], [SElem a]) -> SEnv a -> a
    f] (LI [SElem a]
    xs:[])    SEnv a
    snv = (([SElem a], [SElem a]) -> a) -> [([SElem a], [SElem a])] -> [a]
    forall a b. (a -> b) -> [a] -> [b]
    map ((([SElem a], [SElem a]) -> SEnv a -> a)
    -> SEnv a -> ([SElem a], [SElem a]) -> a
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip ([SElem a], [SElem a]) -> SEnv a -> a
    f SEnv a
    snv) ([SElem a] -> [([SElem a], [SElem a])]
    forall a b. [a] -> [([a], [SElem b])]
    pluslen [SElem a]
    xs)
    iterApp [([SElem a], [SElem a]) -> SEnv a -> a
    f] vars :: [SElem a]
    vars@(LI [SElem a]
    _:[SElem a]
    _) SEnv a
    snv = (([SElem a], [SElem a]) -> a) -> [([SElem a], [SElem a])] -> [a]
    forall a b. (a -> b) -> [a] -> [b]
    map ((([SElem a], [SElem a]) -> SEnv a -> a)
    -> SEnv a -> ([SElem a], [SElem a]) -> a
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip ([SElem a], [SElem a]) -> SEnv a -> a
    f SEnv a
    snv) ([SElem a] -> [([SElem a], [SElem a])]
    forall a. [SElem a] -> [([SElem a], [SElem a])]
    liTrans [SElem a]
    vars)
    iterApp [([SElem a], [SElem a]) -> SEnv a -> a
    f] [SElem a]
    v             SEnv a
    snv = [([SElem a], [SElem a]) -> SEnv a -> a
    f ([SElem a]
    v,[SElem a]
    forall a. [SElem a]
    ix0) SEnv a
    snv]
    iterApp [([SElem a], [SElem a]) -> SEnv a -> a]
    fs (LI [SElem a]
    xs:[])     SEnv a
    snv = [([SElem a], [SElem a]) -> SEnv a -> a]
    -> [([SElem a], [SElem a])] -> SEnv a -> [a]
    forall a.
    Stringable a =>
    [([SElem a], [SElem a]) -> SEnv a -> a]
    -> [([SElem a], [SElem a])] -> SEnv a -> [a]
    cycleApp [([SElem a], [SElem a]) -> SEnv a -> a]
    fs ([SElem a] -> [([SElem a], [SElem a])]
    forall a b. [a] -> [([a], [SElem b])]
    pluslen [SElem a]
    xs) SEnv a
    snv
    iterApp [([SElem a], [SElem a]) -> SEnv a -> a]
    fs vars :: [SElem a]
    vars@(LI [SElem a]
    _:[SElem a]
    _)  SEnv a
    snv = [([SElem a], [SElem a]) -> SEnv a -> a]
    -> [([SElem a], [SElem a])] -> SEnv a -> [a]
    forall a.
    Stringable a =>
    [([SElem a], [SElem a]) -> SEnv a -> a]
    -> [([SElem a], [SElem a])] -> SEnv a -> [a]
    cycleApp [([SElem a], [SElem a]) -> SEnv a -> a]
    fs ([SElem a] -> [([SElem a], [SElem a])]
    forall a. [SElem a] -> [([SElem a], [SElem a])]
    liTrans [SElem a]
    vars) SEnv a
    snv
    iterApp [([SElem a], [SElem a]) -> SEnv a -> a]
    fs [SElem a]
    xs             SEnv a
    snv = [([SElem a], [SElem a]) -> SEnv a -> a]
    -> [([SElem a], [SElem a])] -> SEnv a -> [a]
    forall a.
    Stringable a =>
    [([SElem a], [SElem a]) -> SEnv a -> a]
    -> [([SElem a], [SElem a])] -> SEnv a -> [a]
    cycleApp [([SElem a], [SElem a]) -> SEnv a -> a]
    fs ([SElem a] -> [([SElem a], [SElem a])]
    forall a b. [a] -> [([a], [SElem b])]
    pluslen [SElem a]
    xs) SEnv a
    snv

    anonTmpl :: Stringable a => TmplParser (([SElem a], [SElem a]) -> SEnv a -> a)
    anonTmpl :: forall a.
    Stringable a =>
    TmplParser (([SElem a], [SElem a]) -> SEnv a -> a)
    anonTmpl = Char
    -> GenParser
         Char
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         (([SElem a], [SElem a]) -> SEnv a -> a)
    -> Char
    -> GenParser
         Char
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         (([SElem a], [SElem a]) -> SEnv a -> a)
    forall st t.
    Char -> GenParser Char st t -> Char -> GenParser Char st t
    around Char
    '{' GenParser
      Char
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      (([SElem a], [SElem a]) -> SEnv a -> a)
    forall a.
    Stringable a =>
    TmplParser (([SElem a], [SElem a]) -> SEnv a -> a)
    subStmp Char
    '}'

    regTemplate :: Stringable a => TmplParser (([SElem a], [SElem a]) -> SEnv a -> a)
    regTemplate :: forall a.
    Stringable a =>
    TmplParser (([SElem a], [SElem a]) -> SEnv a -> a)
    regTemplate = do
      GenParser
      Char
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      (SEnv [Char] -> SElem [Char])
    -> GenParser
         Char
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         (SEnv [Char] -> SElem [Char])
    forall tok st a. GenParser tok st a -> GenParser tok st a
    try (GenParser
      Char
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      (SEnv [Char] -> SElem [Char])
    forall a. Stringable a => TmplParser (SEnv a -> SElem a)
    functn::TmplParser (SEnv String -> SElem String)) GenParser
      Char
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      (SEnv [Char] -> SElem [Char])
    -> TmplParser () -> TmplParser ()
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    .>> [Char] -> TmplParser ()
    forall a.
    [Char]
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity a
    forall (m :: * -> *) a. MonadFail m => [Char] -> m a
    fail [Char]
    "" TmplParser () -> TmplParser () -> TmplParser ()
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> () -> TmplParser ()
    forall a.
    a
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ()
      name <- [Char] -> SEnv a -> SElem a
    forall b a. [Char] -> b -> SElem a
    justSTR ([Char] -> SEnv a -> SElem a)
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many1 (ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    forall st. GenParser Char st Char
    identifierChar ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Char
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char Char
    '/')
              ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      (SEnv a -> SElem a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Char
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    -> Char
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    forall st t.
    Char -> GenParser Char st t -> Char -> GenParser Char st t
    around Char
    '(' ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      (SEnv a -> SElem a)
    forall a. Stringable a => TmplParser (SEnv a -> SElem a)
    subexprn Char
    ')'
      tryTellTmpl (name nullEnv)
      vals <- around '(' (spaced $ try assgn <|> anonassgn <|> return []) ')'
      return $ join . (. name) . makeTmpl vals
          where makeTmpl :: [([Char], SEnv t2 -> SElem t2)]
    -> ([SElem t2], [SElem t2]) -> SElem a -> SEnv t2 -> t2
    makeTmpl [([Char], SEnv t2 -> SElem t2)]
    v ((SElem t2
    se:[SElem t2]
    _),[SElem t2]
    is) (STR [Char]
    x)  =
                    [Char] -> StringTemplate t2 -> t2
    forall a. Stringable a => [Char] -> StringTemplate a -> a
    renderErr [Char]
    x (StringTemplate t2 -> t2)
    -> (SEnv t2 -> StringTemplate t2) -> SEnv t2 -> t2
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    |. [([Char], SElem t2)] -> StringTemplate t2 -> StringTemplate t2
    forall {t :: * -> *} {a}.
    Foldable t =>
    t ([Char], SElem a) -> StringTemplate a -> StringTemplate a
    stBind ([([Char], SElem t2)] -> StringTemplate t2 -> StringTemplate t2)
    -> (SEnv t2 -> [([Char], SElem t2)])
    -> SEnv t2
    -> StringTemplate t2
    -> StringTemplate t2
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ([[Char]] -> [SElem t2] -> [([Char], SElem t2)]
    forall a b. [a] -> [b] -> [(a, b)]
    zip [[Char]
    "it",[Char]
    "i",[Char]
    "i0"] (SElem t2
    seSElem t2 -> [SElem t2] -> [SElem t2]
    forall a. a -> [a] -> [a]
    :[SElem t2]
    is) [([Char], SElem t2)]
    -> [([Char], SElem t2)] -> [([Char], SElem t2)]
    forall a. [a] -> [a] -> [a]
    ++)
                                 ([([Char], SElem t2)] -> [([Char], SElem t2)])
    -> (SEnv t2 -> [([Char], SElem t2)])
    -> SEnv t2
    -> [([Char], SElem t2)]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (((SEnv t2 -> SElem t2) -> SElem t2)
     -> [([Char], SEnv t2 -> SElem t2)] -> [([Char], SElem t2)])
    -> [([Char], SEnv t2 -> SElem t2)]
    -> SEnv t2
    -> [([Char], SElem t2)]
    forall a c1 b c. (((a -> c1) -> c1) -> b -> c) -> b -> a -> c
    swing ((([Char], SEnv t2 -> SElem t2) -> ([Char], SElem t2))
    -> [([Char], SEnv t2 -> SElem t2)] -> [([Char], SElem t2)]
    forall a b. (a -> b) -> [a] -> [b]
    map ((([Char], SEnv t2 -> SElem t2) -> ([Char], SElem t2))
     -> [([Char], SEnv t2 -> SElem t2)] -> [([Char], SElem t2)])
    -> (((SEnv t2 -> SElem t2) -> SElem t2)
        -> ([Char], SEnv t2 -> SElem t2) -> ([Char], SElem t2))
    -> ((SEnv t2 -> SElem t2) -> SElem t2)
    -> [([Char], SEnv t2 -> SElem t2)]
    -> [([Char], SElem t2)]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ((SEnv t2 -> SElem t2) -> SElem t2)
    -> ([Char], SEnv t2 -> SElem t2) -> ([Char], SElem t2)
    forall b c d. (b -> c) -> (d, b) -> (d, c)
    forall (a :: * -> * -> *) b c d.
    Arrow a =>
    a b c -> a (d, b) (d, c)
    second) [([Char], SEnv t2 -> SElem t2)]
    v (SEnv t2 -> StringTemplate t2 -> StringTemplate t2)
    -> (SEnv t2 -> StringTemplate t2) -> SEnv t2 -> StringTemplate t2
    forall a b. (SEnv t2 -> a -> b) -> (SEnv t2 -> a) -> SEnv t2 -> b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> [Char] -> SEnv t2 -> StringTemplate t2
    forall a. Stringable a => [Char] -> SEnv a -> StringTemplate a
    stLookup [Char]
    x
                makeTmpl [([Char], SEnv t2 -> SElem t2)]
    _ ([SElem t2], [SElem t2])
    _ SElem a
    _ = [Char] -> SEnv t2 -> t2
    forall a. Stringable a => [Char] -> SEnv a -> a
    showStr [Char]
    "Invalid Template Specified"
                stBind :: t ([Char], SElem a) -> StringTemplate a -> StringTemplate a
    stBind t ([Char], SElem a)
    v StringTemplate a
    st = StringTemplate a
    st {senv = foldr envInsert (senv st) v}
                anonassgn :: GenParser
      Char
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      [([Char], SEnv a -> SElem a)]
    anonassgn = (([Char], SEnv a -> SElem a)
    -> [([Char], SEnv a -> SElem a)] -> [([Char], SEnv a -> SElem a)]
    forall a. a -> [a] -> [a]
    :[]) (([Char], SEnv a -> SElem a) -> [([Char], SEnv a -> SElem a)])
    -> ((SEnv a -> SElem a) -> ([Char], SEnv a -> SElem a))
    -> (SEnv a -> SElem a)
    -> [([Char], SEnv a -> SElem a)]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (,) [Char]
    "it" ((SEnv a -> SElem a) -> [([Char], SEnv a -> SElem a)])
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    -> GenParser
         Char
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         [([Char], SEnv a -> SElem a)]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      (SEnv a -> SElem a)
    forall a. Stringable a => TmplParser (SEnv a -> SElem a)
    subexprn
                assgn :: GenParser
      Char
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      [([Char], SEnv a -> SElem a)]
    assgn = (ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    forall st t. GenParser Char st t -> GenParser Char st t
    spaced ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    forall st. GenParser Char st [Char]
    word ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity [Char]
    -> ([Char]
        -> ParsecT
             [Char]
             ((Char, Char), [[Char]], [[Char]], [[Char]])
             Identity
             ([Char], SEnv a -> SElem a))
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         ([Char], SEnv a -> SElem a)
    forall a b.
    ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity a
    -> (a
        -> ParsecT
             [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity b)
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= (((SEnv a -> SElem a) -> ([Char], SEnv a -> SElem a))
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         ([Char], SEnv a -> SElem a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Char
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char Char
    '=' ParsecT
      [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    .>> ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      (SEnv a -> SElem a)
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         (SEnv a -> SElem a)
    forall st t. GenParser Char st t -> GenParser Char st t
    spaced ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      (SEnv a -> SElem a)
    forall a. Stringable a => TmplParser (SEnv a -> SElem a)
    subexprn) (((SEnv a -> SElem a) -> ([Char], SEnv a -> SElem a))
     -> ParsecT
          [Char]
          ((Char, Char), [[Char]], [[Char]], [[Char]])
          Identity
          ([Char], SEnv a -> SElem a))
    -> ([Char] -> (SEnv a -> SElem a) -> ([Char], SEnv a -> SElem a))
    -> [Char]
    -> ParsecT
         [Char]
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         Identity
         ([Char], SEnv a -> SElem a)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (,))
                        ParsecT
      [Char]
      ((Char, Char), [[Char]], [[Char]], [[Char]])
      Identity
      ([Char], SEnv a -> SElem a)
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    -> GenParser
         Char
         ((Char, Char), [[Char]], [[Char]], [[Char]])
         [([Char], SEnv a -> SElem a)]
    forall s (m :: * -> *) t u a sep.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
    `sepEndBy1` Char
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char Char
    ';'
                tryTellTmpl :: SElem a -> TmplParser ()
    tryTellTmpl (STR [Char]
    x) = [Char] -> TmplParser ()
    tellTmpl [Char]
    x
                tryTellTmpl SElem a
    _ = () -> TmplParser ()
    forall a.
    a
    -> ParsecT
         [Char] ((Char, Char), [[Char]], [[Char]], [[Char]]) Identity a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ()

    --DEBUG

    {-pTrace s = pt <|> return ()
        where pt = try $
                   do
                     x <- try $ many1 anyChar
                     trace (s++": " ++x) $ try $ char 'z'
                     fail x
    -}