{-# LANGUAGE CPP #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveTraversable #-}

{- |
   Module      : Text.DocTemplates.Internal
   Copyright   : Copyright (C) 2009-2019 John MacFarlane
   License     : BSD3

   Maintainer  : John MacFarlane <jgm@berkeley.edu>
   Stability   : alpha
   Portability : portable
-}

module Text.DocTemplates.Internal
      ( renderTemplate
      , TemplateMonad(..)
      , Context(..)
      , Val(..)
      , ToContext(..)
      , FromContext(..)
      , TemplateTarget
      , Template(..)
      , Variable(..)
      , Pipe(..)
      , Alignment(..)
      , Border(..)
      ) where

import Data.Text.Conversions (FromText(..), ToText(..))
import Data.Aeson (Value(..), ToJSON(..), FromJSON(..), Result(..), fromJSON)
import Control.Monad.Identity
import qualified Control.Monad.State.Strict as S
import Data.Char (chr, ord)
import Data.Maybe (fromMaybe)
import qualified Data.Text.Read as T
import qualified Data.Text as T
import qualified Data.Text.IO as TIO
import Text.DocLayout (Doc, HasChars)
import qualified Text.DocLayout as DL
import Data.String (IsString(..))
import Data.Data (Data)
import Data.Typeable (Typeable)
import GHC.Generics (Generic)
import Data.Text (Text)
import qualified Data.Map as M
import qualified Data.Vector as V
import Data.Scientific (floatingOrInteger)
import Data.List (intersperse)
#if MIN_VERSION_base(4,11,0)
#else
import Data.Semigroup
#endif

-- | A template.
data Template a =
       Interpolate Variable
     | Conditional Variable (Template a) (Template a)
     | Iterate Variable (Template a) (Template a)
     | Nested (Template a)
     | Partial [Pipe] (Template a)
     | Literal (Doc a)
     | Concat (Template a) (Template a)
     | Empty
     deriving (Int -> Template a -> ShowS
forall a. Show a => Int -> Template a -> ShowS
forall a. Show a => [Template a] -> ShowS
forall a. Show a => Template a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Template a] -> ShowS
$cshowList :: forall a. Show a => [Template a] -> ShowS
show :: Template a -> String
$cshow :: forall a. Show a => Template a -> String
showsPrec :: Int -> Template a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Template a -> ShowS
Show, ReadPrec [Template a]
ReadPrec (Template a)
ReadS [Template a]
forall a. Read a => ReadPrec [Template a]
forall a. Read a => ReadPrec (Template a)
forall a. Read a => Int -> ReadS (Template a)
forall a. Read a => ReadS [Template a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Template a]
$creadListPrec :: forall a. Read a => ReadPrec [Template a]
readPrec :: ReadPrec (Template a)
$creadPrec :: forall a. Read a => ReadPrec (Template a)
readList :: ReadS [Template a]
$creadList :: forall a. Read a => ReadS [Template a]
readsPrec :: Int -> ReadS (Template a)
$creadsPrec :: forall a. Read a => Int -> ReadS (Template a)
Read, Template a -> DataType
Template a -> Constr
forall {a}. Data a => Typeable (Template a)
forall a. Data a => Template a -> DataType
forall a. Data a => Template a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b) -> Template a -> Template a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> Template a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> Template a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Template a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Template a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Template a -> m (Template a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Template a -> m (Template a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Template a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Template a -> c (Template a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Template a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Template a))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Template a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Template a -> c (Template a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Template a))
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Template a -> m (Template a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Template a -> m (Template a)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Template a -> m (Template a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Template a -> m (Template a)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Template a -> m (Template a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Template a -> m (Template a)
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Template a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> Template a -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> Template a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> Template a -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Template a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Template a -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Template a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Template a -> r
gmapT :: (forall b. Data b => b -> b) -> Template a -> Template a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> Template a -> Template a
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Template a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Template a))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Template a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Template a))
dataTypeOf :: Template a -> DataType
$cdataTypeOf :: forall a. Data a => Template a -> DataType
toConstr :: Template a -> Constr
$ctoConstr :: forall a. Data a => Template a -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Template a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Template a)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Template a -> c (Template a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Template a -> c (Template a)
Data, Typeable, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Template a) x -> Template a
forall a x. Template a -> Rep (Template a) x
$cto :: forall a x. Rep (Template a) x -> Template a
$cfrom :: forall a x. Template a -> Rep (Template a) x
Generic, Template a -> Template a -> Bool
forall a. Eq a => Template a -> Template a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Template a -> Template a -> Bool
$c/= :: forall a. Eq a => Template a -> Template a -> Bool
== :: Template a -> Template a -> Bool
$c== :: forall a. Eq a => Template a -> Template a -> Bool
Eq, Template a -> Template a -> Ordering
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {a}. Ord a => Eq (Template a)
forall a. Ord a => Template a -> Template a -> Bool
forall a. Ord a => Template a -> Template a -> Ordering
forall a. Ord a => Template a -> Template a -> Template a
min :: Template a -> Template a -> Template a
$cmin :: forall a. Ord a => Template a -> Template a -> Template a
max :: Template a -> Template a -> Template a
$cmax :: forall a. Ord a => Template a -> Template a -> Template a
>= :: Template a -> Template a -> Bool
$c>= :: forall a. Ord a => Template a -> Template a -> Bool
> :: Template a -> Template a -> Bool
$c> :: forall a. Ord a => Template a -> Template a -> Bool
<= :: Template a -> Template a -> Bool
$c<= :: forall a. Ord a => Template a -> Template a -> Bool
< :: Template a -> Template a -> Bool
$c< :: forall a. Ord a => Template a -> Template a -> Bool
compare :: Template a -> Template a -> Ordering
$ccompare :: forall a. Ord a => Template a -> Template a -> Ordering
Ord,
               forall a. Eq a => a -> Template a -> Bool
forall a. Num a => Template a -> a
forall a. Ord a => Template a -> a
forall m. Monoid m => Template m -> m
forall a. Template a -> Bool
forall a. Template a -> Int
forall a. Template a -> [a]
forall a. (a -> a -> a) -> Template a -> a
forall m a. Monoid m => (a -> m) -> Template a -> m
forall b a. (b -> a -> b) -> b -> Template a -> b
forall a b. (a -> b -> b) -> b -> Template a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => Template a -> a
$cproduct :: forall a. Num a => Template a -> a
sum :: forall a. Num a => Template a -> a
$csum :: forall a. Num a => Template a -> a
minimum :: forall a. Ord a => Template a -> a
$cminimum :: forall a. Ord a => Template a -> a
maximum :: forall a. Ord a => Template a -> a
$cmaximum :: forall a. Ord a => Template a -> a
elem :: forall a. Eq a => a -> Template a -> Bool
$celem :: forall a. Eq a => a -> Template a -> Bool
length :: forall a. Template a -> Int
$clength :: forall a. Template a -> Int
null :: forall a. Template a -> Bool
$cnull :: forall a. Template a -> Bool
toList :: forall a. Template a -> [a]
$ctoList :: forall a. Template a -> [a]
foldl1 :: forall a. (a -> a -> a) -> Template a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Template a -> a
foldr1 :: forall a. (a -> a -> a) -> Template a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Template a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> Template a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Template a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Template a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Template a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Template a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Template a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Template a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Template a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> Template a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Template a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Template a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Template a -> m
fold :: forall m. Monoid m => Template m -> m
$cfold :: forall m. Monoid m => Template m -> m
Foldable, Functor Template
Foldable Template
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Template (m a) -> m (Template a)
forall (f :: * -> *) a.
Applicative f =>
Template (f a) -> f (Template a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Template a -> m (Template b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Template a -> f (Template b)
sequence :: forall (m :: * -> *) a. Monad m => Template (m a) -> m (Template a)
$csequence :: forall (m :: * -> *) a. Monad m => Template (m a) -> m (Template a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Template a -> m (Template b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Template a -> m (Template b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
Template (f a) -> f (Template a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
Template (f a) -> f (Template a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Template a -> f (Template b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Template a -> f (Template b)
Traversable, forall a b. a -> Template b -> Template a
forall a b. (a -> b) -> Template a -> Template b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Template b -> Template a
$c<$ :: forall a b. a -> Template b -> Template a
fmap :: forall a b. (a -> b) -> Template a -> Template b
$cfmap :: forall a b. (a -> b) -> Template a -> Template b
Functor)

instance Semigroup a => Semigroup (Template a) where
  Template a
x <> :: Template a -> Template a -> Template a
<> Template a
Empty = Template a
x
  Template a
Empty <> Template a
x = Template a
x
  Template a
x <> Template a
y = forall a. Template a -> Template a -> Template a
Concat Template a
x Template a
y

instance Semigroup a => Monoid (Template a) where
  mappend :: Template a -> Template a -> Template a
mappend = forall a. Semigroup a => a -> a -> a
(<>)
  mempty :: Template a
mempty = forall a. Template a
Empty

data Pipe =
      ToPairs
    | ToUppercase
    | ToLowercase
    | ToLength
    | Reverse
    | FirstItem
    | LastItem
    | Rest
    | AllButLast
    | Chomp
    | ToAlpha
    | ToRoman
    | NoWrap
    | Block Alignment Int Border
    deriving (Int -> Pipe -> ShowS
[Pipe] -> ShowS
Pipe -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Pipe] -> ShowS
$cshowList :: [Pipe] -> ShowS
show :: Pipe -> String
$cshow :: Pipe -> String
showsPrec :: Int -> Pipe -> ShowS
$cshowsPrec :: Int -> Pipe -> ShowS
Show, ReadPrec [Pipe]
ReadPrec Pipe
Int -> ReadS Pipe
ReadS [Pipe]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Pipe]
$creadListPrec :: ReadPrec [Pipe]
readPrec :: ReadPrec Pipe
$creadPrec :: ReadPrec Pipe
readList :: ReadS [Pipe]
$creadList :: ReadS [Pipe]
readsPrec :: Int -> ReadS Pipe
$creadsPrec :: Int -> ReadS Pipe
Read, Typeable Pipe
Pipe -> DataType
Pipe -> Constr
(forall b. Data b => b -> b) -> Pipe -> Pipe
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Pipe -> u
forall u. (forall d. Data d => d -> u) -> Pipe -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Pipe -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Pipe -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Pipe -> m Pipe
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Pipe -> m Pipe
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Pipe
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Pipe -> c Pipe
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Pipe)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Pipe)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Pipe -> m Pipe
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Pipe -> m Pipe
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Pipe -> m Pipe
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Pipe -> m Pipe
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Pipe -> m Pipe
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Pipe -> m Pipe
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Pipe -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Pipe -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> Pipe -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Pipe -> [u]
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Pipe -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Pipe -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Pipe -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Pipe -> r
gmapT :: (forall b. Data b => b -> b) -> Pipe -> Pipe
$cgmapT :: (forall b. Data b => b -> b) -> Pipe -> Pipe
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Pipe)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Pipe)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Pipe)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Pipe)
dataTypeOf :: Pipe -> DataType
$cdataTypeOf :: Pipe -> DataType
toConstr :: Pipe -> Constr
$ctoConstr :: Pipe -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Pipe
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Pipe
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Pipe -> c Pipe
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Pipe -> c Pipe
Data, Typeable, forall x. Rep Pipe x -> Pipe
forall x. Pipe -> Rep Pipe x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Pipe x -> Pipe
$cfrom :: forall x. Pipe -> Rep Pipe x
Generic, Pipe -> Pipe -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Pipe -> Pipe -> Bool
$c/= :: Pipe -> Pipe -> Bool
== :: Pipe -> Pipe -> Bool
$c== :: Pipe -> Pipe -> Bool
Eq, Eq Pipe
Pipe -> Pipe -> Bool
Pipe -> Pipe -> Ordering
Pipe -> Pipe -> Pipe
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Pipe -> Pipe -> Pipe
$cmin :: Pipe -> Pipe -> Pipe
max :: Pipe -> Pipe -> Pipe
$cmax :: Pipe -> Pipe -> Pipe
>= :: Pipe -> Pipe -> Bool
$c>= :: Pipe -> Pipe -> Bool
> :: Pipe -> Pipe -> Bool
$c> :: Pipe -> Pipe -> Bool
<= :: Pipe -> Pipe -> Bool
$c<= :: Pipe -> Pipe -> Bool
< :: Pipe -> Pipe -> Bool
$c< :: Pipe -> Pipe -> Bool
compare :: Pipe -> Pipe -> Ordering
$ccompare :: Pipe -> Pipe -> Ordering
Ord)

data Alignment =
      LeftAligned
    | Centered
    | RightAligned
    deriving (Int -> Alignment -> ShowS
[Alignment] -> ShowS
Alignment -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Alignment] -> ShowS
$cshowList :: [Alignment] -> ShowS
show :: Alignment -> String
$cshow :: Alignment -> String
showsPrec :: Int -> Alignment -> ShowS
$cshowsPrec :: Int -> Alignment -> ShowS
Show, ReadPrec [Alignment]
ReadPrec Alignment
Int -> ReadS Alignment
ReadS [Alignment]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Alignment]
$creadListPrec :: ReadPrec [Alignment]
readPrec :: ReadPrec Alignment
$creadPrec :: ReadPrec Alignment
readList :: ReadS [Alignment]
$creadList :: ReadS [Alignment]
readsPrec :: Int -> ReadS Alignment
$creadsPrec :: Int -> ReadS Alignment
Read, Typeable Alignment
Alignment -> DataType
Alignment -> Constr
(forall b. Data b => b -> b) -> Alignment -> Alignment
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Alignment -> u
forall u. (forall d. Data d => d -> u) -> Alignment -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Alignment -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Alignment -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Alignment -> m Alignment
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Alignment -> m Alignment
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Alignment
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Alignment -> c Alignment
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Alignment)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Alignment)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Alignment -> m Alignment
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Alignment -> m Alignment
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Alignment -> m Alignment
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Alignment -> m Alignment
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Alignment -> m Alignment
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Alignment -> m Alignment
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Alignment -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Alignment -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> Alignment -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Alignment -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Alignment -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Alignment -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Alignment -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Alignment -> r
gmapT :: (forall b. Data b => b -> b) -> Alignment -> Alignment
$cgmapT :: (forall b. Data b => b -> b) -> Alignment -> Alignment
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Alignment)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Alignment)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Alignment)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Alignment)
dataTypeOf :: Alignment -> DataType
$cdataTypeOf :: Alignment -> DataType
toConstr :: Alignment -> Constr
$ctoConstr :: Alignment -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Alignment
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Alignment
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Alignment -> c Alignment
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Alignment -> c Alignment
Data, Typeable, forall x. Rep Alignment x -> Alignment
forall x. Alignment -> Rep Alignment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Alignment x -> Alignment
$cfrom :: forall x. Alignment -> Rep Alignment x
Generic, Alignment -> Alignment -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Alignment -> Alignment -> Bool
$c/= :: Alignment -> Alignment -> Bool
== :: Alignment -> Alignment -> Bool
$c== :: Alignment -> Alignment -> Bool
Eq, Eq Alignment
Alignment -> Alignment -> Bool
Alignment -> Alignment -> Ordering
Alignment -> Alignment -> Alignment
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Alignment -> Alignment -> Alignment
$cmin :: Alignment -> Alignment -> Alignment
max :: Alignment -> Alignment -> Alignment
$cmax :: Alignment -> Alignment -> Alignment
>= :: Alignment -> Alignment -> Bool
$c>= :: Alignment -> Alignment -> Bool
> :: Alignment -> Alignment -> Bool
$c> :: Alignment -> Alignment -> Bool
<= :: Alignment -> Alignment -> Bool
$c<= :: Alignment -> Alignment -> Bool
< :: Alignment -> Alignment -> Bool
$c< :: Alignment -> Alignment -> Bool
compare :: Alignment -> Alignment -> Ordering
$ccompare :: Alignment -> Alignment -> Ordering
Ord)

data Border = Border
     { Border -> Text
borderLeft  :: Text
     , Border -> Text
borderRight :: Text
     }
    deriving (Int -> Border -> ShowS
[Border] -> ShowS
Border -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Border] -> ShowS
$cshowList :: [Border] -> ShowS
show :: Border -> String
$cshow :: Border -> String
showsPrec :: Int -> Border -> ShowS
$cshowsPrec :: Int -> Border -> ShowS
Show, ReadPrec [Border]
ReadPrec Border
Int -> ReadS Border
ReadS [Border]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Border]
$creadListPrec :: ReadPrec [Border]
readPrec :: ReadPrec Border
$creadPrec :: ReadPrec Border
readList :: ReadS [Border]
$creadList :: ReadS [Border]
readsPrec :: Int -> ReadS Border
$creadsPrec :: Int -> ReadS Border
Read, Typeable Border
Border -> DataType
Border -> Constr
(forall b. Data b => b -> b) -> Border -> Border
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Border -> u
forall u. (forall d. Data d => d -> u) -> Border -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Border -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Border -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Border -> m Border
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Border -> m Border
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Border
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Border -> c Border
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Border)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Border)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Border -> m Border
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Border -> m Border
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Border -> m Border
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Border -> m Border
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Border -> m Border
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Border -> m Border
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Border -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Border -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> Border -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Border -> [u]
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Border -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Border -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Border -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Border -> r
gmapT :: (forall b. Data b => b -> b) -> Border -> Border
$cgmapT :: (forall b. Data b => b -> b) -> Border -> Border
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Border)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Border)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Border)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Border)
dataTypeOf :: Border -> DataType
$cdataTypeOf :: Border -> DataType
toConstr :: Border -> Constr
$ctoConstr :: Border -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Border
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Border
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Border -> c Border
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Border -> c Border
Data, Typeable, forall x. Rep Border x -> Border
forall x. Border -> Rep Border x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Border x -> Border
$cfrom :: forall x. Border -> Rep Border x
Generic, Border -> Border -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Border -> Border -> Bool
$c/= :: Border -> Border -> Bool
== :: Border -> Border -> Bool
$c== :: Border -> Border -> Bool
Eq, Eq Border
Border -> Border -> Bool
Border -> Border -> Ordering
Border -> Border -> Border
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Border -> Border -> Border
$cmin :: Border -> Border -> Border
max :: Border -> Border -> Border
$cmax :: Border -> Border -> Border
>= :: Border -> Border -> Bool
$c>= :: Border -> Border -> Bool
> :: Border -> Border -> Bool
$c> :: Border -> Border -> Bool
<= :: Border -> Border -> Bool
$c<= :: Border -> Border -> Bool
< :: Border -> Border -> Bool
$c< :: Border -> Border -> Bool
compare :: Border -> Border -> Ordering
$ccompare :: Border -> Border -> Ordering
Ord)

-- | A variable which may have several parts (@foo.bar.baz@).
data Variable =
  Variable
    { Variable -> [Text]
varParts   :: [Text]
    , Variable -> [Pipe]
varPipes   :: [Pipe]
    }
  deriving (Int -> Variable -> ShowS
[Variable] -> ShowS
Variable -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Variable] -> ShowS
$cshowList :: [Variable] -> ShowS
show :: Variable -> String
$cshow :: Variable -> String
showsPrec :: Int -> Variable -> ShowS
$cshowsPrec :: Int -> Variable -> ShowS
Show, ReadPrec [Variable]
ReadPrec Variable
Int -> ReadS Variable
ReadS [Variable]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Variable]
$creadListPrec :: ReadPrec [Variable]
readPrec :: ReadPrec Variable
$creadPrec :: ReadPrec Variable
readList :: ReadS [Variable]
$creadList :: ReadS [Variable]
readsPrec :: Int -> ReadS Variable
$creadsPrec :: Int -> ReadS Variable
Read, Typeable Variable
Variable -> DataType
Variable -> Constr
(forall b. Data b => b -> b) -> Variable -> Variable
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Variable -> u
forall u. (forall d. Data d => d -> u) -> Variable -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Variable -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Variable -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Variable -> m Variable
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Variable -> m Variable
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Variable
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Variable -> c Variable
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Variable)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Variable)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Variable -> m Variable
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Variable -> m Variable
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Variable -> m Variable
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Variable -> m Variable
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Variable -> m Variable
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Variable -> m Variable
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Variable -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Variable -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> Variable -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Variable -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Variable -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Variable -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Variable -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Variable -> r
gmapT :: (forall b. Data b => b -> b) -> Variable -> Variable
$cgmapT :: (forall b. Data b => b -> b) -> Variable -> Variable
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Variable)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Variable)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Variable)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Variable)
dataTypeOf :: Variable -> DataType
$cdataTypeOf :: Variable -> DataType
toConstr :: Variable -> Constr
$ctoConstr :: Variable -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Variable
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Variable
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Variable -> c Variable
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Variable -> c Variable
Data, Typeable, forall x. Rep Variable x -> Variable
forall x. Variable -> Rep Variable x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Variable x -> Variable
$cfrom :: forall x. Variable -> Rep Variable x
Generic, Variable -> Variable -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Variable -> Variable -> Bool
$c/= :: Variable -> Variable -> Bool
== :: Variable -> Variable -> Bool
$c== :: Variable -> Variable -> Bool
Eq, Eq Variable
Variable -> Variable -> Bool
Variable -> Variable -> Ordering
Variable -> Variable -> Variable
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Variable -> Variable -> Variable
$cmin :: Variable -> Variable -> Variable
max :: Variable -> Variable -> Variable
$cmax :: Variable -> Variable -> Variable
>= :: Variable -> Variable -> Bool
$c>= :: Variable -> Variable -> Bool
> :: Variable -> Variable -> Bool
$c> :: Variable -> Variable -> Bool
<= :: Variable -> Variable -> Bool
$c<= :: Variable -> Variable -> Bool
< :: Variable -> Variable -> Bool
$c< :: Variable -> Variable -> Bool
compare :: Variable -> Variable -> Ordering
$ccompare :: Variable -> Variable -> Ordering
Ord)

instance Semigroup Variable where
  Variable [Text]
xs [Pipe]
fs <> :: Variable -> Variable -> Variable
<> Variable [Text]
ys [Pipe]
gs = [Text] -> [Pipe] -> Variable
Variable ([Text]
xs forall a. Semigroup a => a -> a -> a
<> [Text]
ys) ([Pipe]
fs forall a. Semigroup a => a -> a -> a
<> [Pipe]
gs)

instance Monoid Variable where
  mempty :: Variable
mempty = [Text] -> [Pipe] -> Variable
Variable forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty
  mappend :: Variable -> Variable -> Variable
mappend = forall a. Semigroup a => a -> a -> a
(<>)

type TemplateTarget a =
  (HasChars a, ToText a, FromText a)

-- | A 'Context' defines values for template's variables.
newtype Context a = Context { forall a. Context a -> Map Text (Val a)
unContext :: M.Map Text (Val a) }
  deriving (Int -> Context a -> ShowS
forall a. Show a => Int -> Context a -> ShowS
forall a. Show a => [Context a] -> ShowS
forall a. Show a => Context a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Context a] -> ShowS
$cshowList :: forall a. Show a => [Context a] -> ShowS
show :: Context a -> String
$cshow :: forall a. Show a => Context a -> String
showsPrec :: Int -> Context a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Context a -> ShowS
Show, NonEmpty (Context a) -> Context a
Context a -> Context a -> Context a
forall b. Integral b => b -> Context a -> Context a
forall a. NonEmpty (Context a) -> Context a
forall a. Context a -> Context a -> Context a
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
forall a b. Integral b => b -> Context a -> Context a
stimes :: forall b. Integral b => b -> Context a -> Context a
$cstimes :: forall a b. Integral b => b -> Context a -> Context a
sconcat :: NonEmpty (Context a) -> Context a
$csconcat :: forall a. NonEmpty (Context a) -> Context a
<> :: Context a -> Context a -> Context a
$c<> :: forall a. Context a -> Context a -> Context a
Semigroup, Context a
[Context a] -> Context a
Context a -> Context a -> Context a
forall a. Semigroup (Context a)
forall a. Context a
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall a. [Context a] -> Context a
forall a. Context a -> Context a -> Context a
mconcat :: [Context a] -> Context a
$cmconcat :: forall a. [Context a] -> Context a
mappend :: Context a -> Context a -> Context a
$cmappend :: forall a. Context a -> Context a -> Context a
mempty :: Context a
$cmempty :: forall a. Context a
Monoid, Functor Context
Foldable Context
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Context (m a) -> m (Context a)
forall (f :: * -> *) a.
Applicative f =>
Context (f a) -> f (Context a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Context a -> m (Context b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Context a -> f (Context b)
sequence :: forall (m :: * -> *) a. Monad m => Context (m a) -> m (Context a)
$csequence :: forall (m :: * -> *) a. Monad m => Context (m a) -> m (Context a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Context a -> m (Context b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Context a -> m (Context b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
Context (f a) -> f (Context a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
Context (f a) -> f (Context a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Context a -> f (Context b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Context a -> f (Context b)
Traversable, forall a. Eq a => a -> Context a -> Bool
forall a. Num a => Context a -> a
forall a. Ord a => Context a -> a
forall m. Monoid m => Context m -> m
forall a. Context a -> Bool
forall a. Context a -> Int
forall a. Context a -> [a]
forall a. (a -> a -> a) -> Context a -> a
forall m a. Monoid m => (a -> m) -> Context a -> m
forall b a. (b -> a -> b) -> b -> Context a -> b
forall a b. (a -> b -> b) -> b -> Context a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => Context a -> a
$cproduct :: forall a. Num a => Context a -> a
sum :: forall a. Num a => Context a -> a
$csum :: forall a. Num a => Context a -> a
minimum :: forall a. Ord a => Context a -> a
$cminimum :: forall a. Ord a => Context a -> a
maximum :: forall a. Ord a => Context a -> a
$cmaximum :: forall a. Ord a => Context a -> a
elem :: forall a. Eq a => a -> Context a -> Bool
$celem :: forall a. Eq a => a -> Context a -> Bool
length :: forall a. Context a -> Int
$clength :: forall a. Context a -> Int
null :: forall a. Context a -> Bool
$cnull :: forall a. Context a -> Bool
toList :: forall a. Context a -> [a]
$ctoList :: forall a. Context a -> [a]
foldl1 :: forall a. (a -> a -> a) -> Context a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Context a -> a
foldr1 :: forall a. (a -> a -> a) -> Context a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Context a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> Context a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Context a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Context a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Context a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Context a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Context a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Context a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Context a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> Context a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Context a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Context a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Context a -> m
fold :: forall m. Monoid m => Context m -> m
$cfold :: forall m. Monoid m => Context m -> m
Foldable, forall a b. a -> Context b -> Context a
forall a b. (a -> b) -> Context a -> Context b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Context b -> Context a
$c<$ :: forall a b. a -> Context b -> Context a
fmap :: forall a b. (a -> b) -> Context a -> Context b
$cfmap :: forall a b. (a -> b) -> Context a -> Context b
Functor,
            Context a -> DataType
Context a -> Constr
forall {a}. Data a => Typeable (Context a)
forall a. Data a => Context a -> DataType
forall a. Data a => Context a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b) -> Context a -> Context a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> Context a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> Context a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Context a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Context a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Context a -> m (Context a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Context a -> m (Context a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Context a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Context a -> c (Context a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Context a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Context a))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Context a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Context a -> c (Context a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Context a))
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Context a -> m (Context a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Context a -> m (Context a)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Context a -> m (Context a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Context a -> m (Context a)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Context a -> m (Context a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Context a -> m (Context a)
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Context a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> Context a -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> Context a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> Context a -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Context a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Context a -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Context a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Context a -> r
gmapT :: (forall b. Data b => b -> b) -> Context a -> Context a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> Context a -> Context a
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Context a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Context a))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Context a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Context a))
dataTypeOf :: Context a -> DataType
$cdataTypeOf :: forall a. Data a => Context a -> DataType
toConstr :: Context a -> Constr
$ctoConstr :: forall a. Data a => Context a -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Context a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Context a)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Context a -> c (Context a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Context a -> c (Context a)
Data, Typeable)

-- | A variable value.
data Val a =
    SimpleVal  (Doc a)
  | ListVal    [Val a]
  | MapVal     (Context a)
  | BoolVal    Bool
  | NullVal
  deriving (Int -> Val a -> ShowS
forall a. Show a => Int -> Val a -> ShowS
forall a. Show a => [Val a] -> ShowS
forall a. Show a => Val a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Val a] -> ShowS
$cshowList :: forall a. Show a => [Val a] -> ShowS
show :: Val a -> String
$cshow :: forall a. Show a => Val a -> String
showsPrec :: Int -> Val a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Val a -> ShowS
Show, Functor Val
Foldable Val
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Val (m a) -> m (Val a)
forall (f :: * -> *) a. Applicative f => Val (f a) -> f (Val a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Val a -> m (Val b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Val a -> f (Val b)
sequence :: forall (m :: * -> *) a. Monad m => Val (m a) -> m (Val a)
$csequence :: forall (m :: * -> *) a. Monad m => Val (m a) -> m (Val a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Val a -> m (Val b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Val a -> m (Val b)
sequenceA :: forall (f :: * -> *) a. Applicative f => Val (f a) -> f (Val a)
$csequenceA :: forall (f :: * -> *) a. Applicative f => Val (f a) -> f (Val a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Val a -> f (Val b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Val a -> f (Val b)
Traversable, forall a. Eq a => a -> Val a -> Bool
forall a. Num a => Val a -> a
forall a. Ord a => Val a -> a
forall m. Monoid m => Val m -> m
forall a. Val a -> Bool
forall a. Val a -> Int
forall a. Val a -> [a]
forall a. (a -> a -> a) -> Val a -> a
forall m a. Monoid m => (a -> m) -> Val a -> m
forall b a. (b -> a -> b) -> b -> Val a -> b
forall a b. (a -> b -> b) -> b -> Val a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => Val a -> a
$cproduct :: forall a. Num a => Val a -> a
sum :: forall a. Num a => Val a -> a
$csum :: forall a. Num a => Val a -> a
minimum :: forall a. Ord a => Val a -> a
$cminimum :: forall a. Ord a => Val a -> a
maximum :: forall a. Ord a => Val a -> a
$cmaximum :: forall a. Ord a => Val a -> a
elem :: forall a. Eq a => a -> Val a -> Bool
$celem :: forall a. Eq a => a -> Val a -> Bool
length :: forall a. Val a -> Int
$clength :: forall a. Val a -> Int
null :: forall a. Val a -> Bool
$cnull :: forall a. Val a -> Bool
toList :: forall a. Val a -> [a]
$ctoList :: forall a. Val a -> [a]
foldl1 :: forall a. (a -> a -> a) -> Val a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Val a -> a
foldr1 :: forall a. (a -> a -> a) -> Val a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Val a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> Val a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Val a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Val a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Val a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Val a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Val a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Val a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Val a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> Val a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Val a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Val a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Val a -> m
fold :: forall m. Monoid m => Val m -> m
$cfold :: forall m. Monoid m => Val m -> m
Foldable, forall a b. a -> Val b -> Val a
forall a b. (a -> b) -> Val a -> Val b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Val b -> Val a
$c<$ :: forall a b. a -> Val b -> Val a
fmap :: forall a b. (a -> b) -> Val a -> Val b
$cfmap :: forall a b. (a -> b) -> Val a -> Val b
Functor, Val a -> DataType
Val a -> Constr
forall {a}. Data a => Typeable (Val a)
forall a. Data a => Val a -> DataType
forall a. Data a => Val a -> Constr
forall a. Data a => (forall b. Data b => b -> b) -> Val a -> Val a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> Val a -> u
forall a u. Data a => (forall d. Data d => d -> u) -> Val a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Val a -> r
forall a r r'.
Data a =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Val a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Val a -> m (Val a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Val a -> m (Val a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Val a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Val a -> c (Val a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Val a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Val a))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Val a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Val a -> c (Val a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Val a))
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Val a -> m (Val a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Val a -> m (Val a)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Val a -> m (Val a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Val a -> m (Val a)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Val a -> m (Val a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Val a -> m (Val a)
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Val a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> Val a -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> Val a -> [u]
$cgmapQ :: forall a u. Data a => (forall d. Data d => d -> u) -> Val a -> [u]
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Val a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Val a -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Val a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Val a -> r
gmapT :: (forall b. Data b => b -> b) -> Val a -> Val a
$cgmapT :: forall a. Data a => (forall b. Data b => b -> b) -> Val a -> Val a
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Val a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Val a))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Val a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Val a))
dataTypeOf :: Val a -> DataType
$cdataTypeOf :: forall a. Data a => Val a -> DataType
toConstr :: Val a -> Constr
$ctoConstr :: forall a. Data a => Val a -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Val a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Val a)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Val a -> c (Val a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Val a -> c (Val a)
Data, Typeable)

-- | The 'ToContext' class provides automatic conversion to
-- a 'Context' or 'Val'.
class ToContext a b where
  toContext :: b -> Context a
  toContext b
x = case forall a b. ToContext a b => b -> Val a
toVal b
x of
                  MapVal Context a
c -> Context a
c
                  Val a
_        -> forall a. Monoid a => a
mempty
  toVal     :: b -> Val a

instance ToContext a (Context a) where
  toContext :: Context a -> Context a
toContext = forall a. a -> a
id
  toVal :: Context a -> Val a
toVal     = forall a. Context a -> Val a
MapVal

instance ToContext a (Val a) where
  toVal :: Val a -> Val a
toVal     = forall a. a -> a
id

instance TemplateTarget a => ToContext a a where
  toVal :: a -> Val a
toVal     = forall a. Doc a -> Val a
SimpleVal forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. HasChars a => a -> Doc a
DL.literal

instance ToContext a a => ToContext a (Doc a) where
  toVal :: Doc a -> Val a
toVal     = forall a. Doc a -> Val a
SimpleVal

instance ToContext a b => ToContext a [b] where
  toVal :: [b] -> Val a
toVal     = forall a. [Val a] -> Val a
ListVal forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall a b. ToContext a b => b -> Val a
toVal

instance {-# OVERLAPPING #-} TemplateTarget [a] => ToContext [a] [a] where
  toVal :: [a] -> Val [a]
toVal    = forall a. Doc a -> Val a
SimpleVal forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. HasChars a => a -> Doc a
DL.literal

instance ToContext a b => ToContext a (M.Map Text b) where
  toVal :: Map Text b -> Val a
toVal     = forall a. Context a -> Val a
MapVal forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. ToContext a b => b -> Context a
toContext
  toContext :: Map Text b -> Context a
toContext = forall a. Map Text (Val a) -> Context a
Context forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b k. (a -> b) -> Map k a -> Map k b
M.map forall a b. ToContext a b => b -> Val a
toVal

instance TemplateTarget a => ToContext a Bool where
  toVal :: Bool -> Val a
toVal Bool
True  = forall a. Bool -> Val a
BoolVal Bool
True
  toVal Bool
False = forall a. Bool -> Val a
BoolVal Bool
False

instance TemplateTarget a => ToContext a Value where
  toContext :: Value -> Context a
toContext Value
x = case forall a. FromJSON a => Value -> Result a
fromJSON Value
x of
                  Success Context a
y -> Context a
y
                  Error String
_   -> forall a. Monoid a => a
mempty
  toVal :: Value -> Val a
toVal Value
x = case forall a. FromJSON a => Value -> Result a
fromJSON Value
x of
                  Success Val a
y -> Val a
y
                  Error String
_   -> forall a. Val a
NullVal

-- | The 'FromContext' class provides functions for extracting
-- values from 'Val' and 'Context'.
class FromContext a b where
  fromVal :: Val a -> Maybe b
  lookupContext :: Text -> Context a -> Maybe b
  lookupContext Text
t (Context Map Text (Val a)
m) = forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
t Map Text (Val a)
m forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a b. FromContext a b => Val a -> Maybe b
fromVal

instance TemplateTarget a => FromContext a (Val a) where
  fromVal :: Val a -> Maybe (Val a)
fromVal = forall a. a -> Maybe a
Just

instance TemplateTarget a => FromContext a (Doc a) where
  fromVal :: Val a -> Maybe (Doc a)
fromVal (SimpleVal Doc a
x) = forall a. a -> Maybe a
Just Doc a
x
  fromVal Val a
_             = forall a. Maybe a
Nothing

instance TemplateTarget a => FromContext a a where
  fromVal :: Val a -> Maybe a
fromVal (SimpleVal Doc a
x) = forall a. a -> Maybe a
Just (forall a. HasChars a => Maybe Int -> Doc a -> a
DL.render forall a. Maybe a
Nothing Doc a
x)
  fromVal Val a
_             = forall a. Maybe a
Nothing

instance {-# OVERLAPPING #-} TemplateTarget [a] => FromContext [a] [a] where
  fromVal :: Val [a] -> Maybe [a]
fromVal (SimpleVal Doc [a]
x) = forall a. a -> Maybe a
Just (forall a. HasChars a => Maybe Int -> Doc a -> a
DL.render forall a. Maybe a
Nothing Doc [a]
x)
  fromVal Val [a]
_             = forall a. Maybe a
Nothing

instance FromContext a b => FromContext a [b] where
  fromVal :: Val a -> Maybe [b]
fromVal (ListVal  [Val a]
xs) = forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM forall a b. FromContext a b => Val a -> Maybe b
fromVal [Val a]
xs
  fromVal Val a
x             = forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [forall a b. FromContext a b => Val a -> Maybe b
fromVal Val a
x]

instance TemplateTarget a => FromJSON (Val a) where
  parseJSON :: Value -> Parser (Val a)
parseJSON Value
v =
    case Value
v of
      Array Array
vec   -> forall a. [Val a] -> Val a
ListVal forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM forall a. FromJSON a => Value -> Parser a
parseJSON (forall a. Vector a -> [a]
V.toList Array
vec)
      String Text
t    -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. Doc a -> Val a
SimpleVal forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => a -> Doc a
DL.literal forall a b. (a -> b) -> a -> b
$ forall a. FromText a => Text -> a
fromText Text
t
      Number Scientific
n    -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. Doc a -> Val a
SimpleVal forall a b. (a -> b) -> a -> b
$ forall a. IsString a => String -> a
fromString forall a b. (a -> b) -> a -> b
$
                              case forall r i. (RealFloat r, Integral i) => Scientific -> Either r i
floatingOrInteger Scientific
n of
                                  Left (Double
r :: Double)   -> forall a. Show a => a -> String
show Double
r
                                  Right (Integer
i :: Integer) -> forall a. Show a => a -> String
show Integer
i
      Bool Bool
b      -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. Bool -> Val a
BoolVal Bool
b
      Object Object
_    -> forall a. Context a -> Val a
MapVal forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Map Text (Val a) -> Context a
Context forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromJSON a => Value -> Parser a
parseJSON Value
v
      Value
_           -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Val a
NullVal

instance TemplateTarget a => FromJSON (Context a) where
  parseJSON :: Value -> Parser (Context a)
parseJSON Value
v = do
    Val a
val <- forall a. FromJSON a => Value -> Parser a
parseJSON Value
v
    case Val a
val of
      MapVal Context a
o -> forall (m :: * -> *) a. Monad m => a -> m a
return Context a
o
      Val a
_        -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Expecting MapVal"

instance TemplateTarget a => ToJSON (Context a) where
  toJSON :: Context a -> Value
toJSON (Context Map Text (Val a)
m) = forall a. ToJSON a => a -> Value
toJSON Map Text (Val a)
m

instance TemplateTarget a => ToJSON (Val a) where
  toJSON :: Val a -> Value
toJSON Val a
NullVal = Value
Null
  toJSON (MapVal Context a
m) = forall a. ToJSON a => a -> Value
toJSON Context a
m
  toJSON (ListVal [Val a]
xs) = forall a. ToJSON a => a -> Value
toJSON [Val a]
xs
  toJSON (SimpleVal Doc a
d) = forall a. ToJSON a => a -> Value
toJSON forall a b. (a -> b) -> a -> b
$ forall a. ToText a => a -> Text
toText forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => Maybe Int -> Doc a -> a
DL.render forall a. Maybe a
Nothing Doc a
d
  toJSON (BoolVal Bool
b) = forall a. ToJSON a => a -> Value
toJSON Bool
b

mapDoc :: TemplateTarget a => (Doc a -> Doc a) -> Val a -> Val a
mapDoc :: forall a. TemplateTarget a => (Doc a -> Doc a) -> Val a -> Val a
mapDoc Doc a -> Doc a
f Val a
val =
  case Val a
val of
    SimpleVal Doc a
d        -> forall a. Doc a -> Val a
SimpleVal (Doc a -> Doc a
f Doc a
d)
    MapVal (Context Map Text (Val a)
m) -> forall a. Context a -> Val a
MapVal (forall a. Map Text (Val a) -> Context a
Context forall a b. (a -> b) -> a -> b
$ forall a b k. (a -> b) -> Map k a -> Map k b
M.map (forall a. TemplateTarget a => (Doc a -> Doc a) -> Val a -> Val a
mapDoc Doc a -> Doc a
f) Map Text (Val a)
m)
    ListVal [Val a]
xs         -> forall a. [Val a] -> Val a
ListVal forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (forall a. TemplateTarget a => (Doc a -> Doc a) -> Val a -> Val a
mapDoc Doc a -> Doc a
f) [Val a]
xs
    BoolVal Bool
b          -> forall a. Bool -> Val a
BoolVal Bool
b
    Val a
NullVal            -> forall a. Val a
NullVal

mapText :: TemplateTarget a => (Text -> Text) -> Val a -> Val a
mapText :: forall a. TemplateTarget a => (Text -> Text) -> Val a -> Val a
mapText Text -> Text
f Val a
val =
  forall a. Identity a -> a
runIdentity (forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. FromText a => Text -> a
fromText forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. ToText a => a -> Text
toText) Val a
val)

applyPipe :: TemplateTarget a => Pipe -> Val a -> Val a
applyPipe :: forall a. TemplateTarget a => Pipe -> Val a -> Val a
applyPipe Pipe
ToLength Val a
val = forall a. Doc a -> Val a
SimpleVal forall a b. (a -> b) -> a -> b
$ forall a. IsString a => String -> a
fromString forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show forall a b. (a -> b) -> a -> b
$ Int
len
  where
   len :: Int
len = case Val a
val of
           SimpleVal Doc a
d        -> Text -> Int
T.length forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. ToText a => a -> Text
toText forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => Maybe Int -> Doc a -> a
DL.render forall a. Maybe a
Nothing Doc a
d
           MapVal (Context Map Text (Val a)
m) -> forall k a. Map k a -> Int
M.size Map Text (Val a)
m
           ListVal [Val a]
xs         -> forall (t :: * -> *) a. Foldable t => t a -> Int
length [Val a]
xs
           BoolVal Bool
_          -> Int
0
           Val a
NullVal            -> Int
0
applyPipe Pipe
ToUppercase Val a
val = forall a. TemplateTarget a => (Text -> Text) -> Val a -> Val a
mapText Text -> Text
T.toUpper Val a
val
applyPipe Pipe
ToLowercase Val a
val = forall a. TemplateTarget a => (Text -> Text) -> Val a -> Val a
mapText Text -> Text
T.toLower Val a
val
applyPipe Pipe
ToPairs Val a
val =
  case Val a
val of
    MapVal (Context Map Text (Val a)
m) ->
      forall a. [Val a] -> Val a
ListVal forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall {a}. HasChars a => (Text, Val a) -> Val a
toPair forall a b. (a -> b) -> a -> b
$ forall k a. Map k a -> [(k, a)]
M.toList Map Text (Val a)
m
    ListVal [Val a]
xs         ->
      forall a. [Val a] -> Val a
ListVal forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall {a}. HasChars a => (Text, Val a) -> Val a
toPair forall a b. (a -> b) -> a -> b
$ forall a b. [a] -> [b] -> [(a, b)]
zip (forall a b. (a -> b) -> [a] -> [b]
map (forall a. IsString a => String -> a
fromString forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show) [(Int
1::Int)..]) [Val a]
xs
    Val a
_                  -> Val a
val
 where
  toPair :: (Text, Val a) -> Val a
toPair (Text
k, Val a
v) = forall a. Context a -> Val a
MapVal forall a b. (a -> b) -> a -> b
$ forall a. Map Text (Val a) -> Context a
Context forall a b. (a -> b) -> a -> b
$ forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
                    [ (Text
"key", forall a. Doc a -> Val a
SimpleVal forall a b. (a -> b) -> a -> b
$ forall a. IsString a => String -> a
fromString forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
T.unpack forall a b. (a -> b) -> a -> b
$ Text
k)
                    , (Text
"value", Val a
v) ]
applyPipe Pipe
FirstItem Val a
val =
  case Val a
val of
    ListVal (Val a
x:[Val a]
_) -> Val a
x
    Val a
_             -> Val a
val
applyPipe Pipe
LastItem Val a
val =
  case Val a
val of
    ListVal xs :: [Val a]
xs@(Val a
_:[Val a]
_) -> forall a. [a] -> a
last [Val a]
xs
    Val a
_                -> Val a
val
applyPipe Pipe
Rest Val a
val =
  case Val a
val of
    ListVal (Val a
_:[Val a]
xs) -> forall a. [Val a] -> Val a
ListVal [Val a]
xs
    Val a
_              -> Val a
val
applyPipe Pipe
AllButLast Val a
val =
  case Val a
val of
    ListVal xs :: [Val a]
xs@(Val a
_:[Val a]
_) -> forall a. [Val a] -> Val a
ListVal (forall a. [a] -> [a]
init [Val a]
xs)
    Val a
_                -> Val a
val
applyPipe Pipe
Reverse Val a
val =
  case Val a
val of
    ListVal [Val a]
xs  -> forall a. [Val a] -> Val a
ListVal (forall a. [a] -> [a]
reverse [Val a]
xs)
    SimpleVal{} -> forall a. TemplateTarget a => (Text -> Text) -> Val a -> Val a
mapText Text -> Text
T.reverse Val a
val
    Val a
_           -> Val a
val
applyPipe Pipe
Chomp Val a
val = forall a. TemplateTarget a => (Doc a -> Doc a) -> Val a -> Val a
mapDoc forall a. Doc a -> Doc a
DL.chomp Val a
val
applyPipe Pipe
ToAlpha Val a
val = forall a. TemplateTarget a => (Text -> Text) -> Val a -> Val a
mapText Text -> Text
toAlpha Val a
val
  where toAlpha :: Text -> Text
toAlpha Text
t =
          case forall a. Integral a => Reader a
T.decimal Text
t of
            Right (Int
y,Text
"") -> forall a. IsString a => String -> a
fromString [Int -> Char
chr (Char -> Int
ord Char
'a' forall a. Num a => a -> a -> a
+ (Int
y forall a. Integral a => a -> a -> a
`mod` Int
26) forall a. Num a => a -> a -> a
- Int
1)]
            Either String (Int, Text)
_            -> Text
t
applyPipe Pipe
ToRoman Val a
val = forall a. TemplateTarget a => (Text -> Text) -> Val a -> Val a
mapText Text -> Text
toRoman' Val a
val
  where toRoman' :: Text -> Text
toRoman' Text
t =
         case forall a. Integral a => Reader a
T.decimal Text
t of
           Right (Int
y,Text
"") -> forall a. a -> Maybe a -> a
fromMaybe Text
t (Int -> Maybe Text
toRoman Int
y)
           Either String (Int, Text)
_            -> Text
t
applyPipe Pipe
NoWrap Val a
val = forall a. TemplateTarget a => (Doc a -> Doc a) -> Val a -> Val a
mapDoc forall a. IsString a => Doc a -> Doc a
DL.nowrap Val a
val
applyPipe (Block Alignment
align Int
n Border
border) Val a
val =
  let constructor :: Int -> Doc a -> Doc a
constructor = case Alignment
align of
                      Alignment
LeftAligned  -> forall a. HasChars a => Int -> Doc a -> Doc a
DL.lblock
                      Alignment
Centered     -> forall a. HasChars a => Int -> Doc a -> Doc a
DL.cblock
                      Alignment
RightAligned -> forall a. HasChars a => Int -> Doc a -> Doc a
DL.rblock
      toBorder :: Text -> Doc a
toBorder Text
y = if Text -> Bool
T.null Text
y
                      then forall a. Monoid a => a
mempty
                      else forall a. HasChars a => a -> Doc a
DL.vfill (forall a. FromText a => Text -> a
fromText Text
y)
  in case forall a. Monoid a => Val a -> Val a
nullToSimple Val a
val of
       SimpleVal Doc a
d -> forall a. Doc a -> Val a
SimpleVal forall a b. (a -> b) -> a -> b
$
                        forall {a}. (HasChars a, FromText a) => Text -> Doc a
toBorder (Border -> Text
borderLeft Border
border) forall a. Semigroup a => a -> a -> a
<>
                        Int -> Doc a -> Doc a
constructor Int
n Doc a
d forall a. Semigroup a => a -> a -> a
<>
                        forall {a}. (HasChars a, FromText a) => Text -> Doc a
toBorder (Border -> Text
borderRight Border
border)
       Val a
_           -> Val a
val

nullToSimple :: Monoid a => Val a -> Val a
nullToSimple :: forall a. Monoid a => Val a -> Val a
nullToSimple Val a
NullVal = forall a. Doc a -> Val a
SimpleVal forall a. Monoid a => a
mempty
nullToSimple Val a
x = Val a
x

-- | Convert number 0 < x < 4000 to lowercase roman numeral.
toRoman :: Int -> Maybe Text
toRoman :: Int -> Maybe Text
toRoman Int
x
  | Int
x forall a. Ord a => a -> a -> Bool
>= Int
1000
  , Int
x forall a. Ord a => a -> a -> Bool
< Int
4000  = (Text
"m" forall a. Semigroup a => a -> a -> a
<>) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Maybe Text
toRoman (Int
x forall a. Num a => a -> a -> a
- Int
1000)
  | Int
x forall a. Ord a => a -> a -> Bool
>= Int
900  = (Text
"cm" forall a. Semigroup a => a -> a -> a
<>) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Maybe Text
toRoman (Int
x forall a. Num a => a -> a -> a
- Int
900)
  | Int
x forall a. Ord a => a -> a -> Bool
>= Int
500  = (Text
"d" forall a. Semigroup a => a -> a -> a
<>) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Maybe Text
toRoman (Int
x forall a. Num a => a -> a -> a
- Int
500)
  | Int
x forall a. Ord a => a -> a -> Bool
>= Int
400  = (Text
"cd" forall a. Semigroup a => a -> a -> a
<>) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Maybe Text
toRoman (Int
x forall a. Num a => a -> a -> a
- Int
400)
  | Int
x forall a. Ord a => a -> a -> Bool
>= Int
100  = (Text
"c" forall a. Semigroup a => a -> a -> a
<>) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Maybe Text
toRoman (Int
x forall a. Num a => a -> a -> a
- Int
100)
  | Int
x forall a. Ord a => a -> a -> Bool
>= Int
90   = (Text
"xc" forall a. Semigroup a => a -> a -> a
<>) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Maybe Text
toRoman (Int
x forall a. Num a => a -> a -> a
- Int
90)
  | Int
x forall a. Ord a => a -> a -> Bool
>= Int
50   = (Text
"l" forall a. Semigroup a => a -> a -> a
<>) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Maybe Text
toRoman (Int
x forall a. Num a => a -> a -> a
- Int
50)
  | Int
x forall a. Ord a => a -> a -> Bool
>= Int
40   = (Text
"xl" forall a. Semigroup a => a -> a -> a
<>) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Maybe Text
toRoman (Int
x forall a. Num a => a -> a -> a
- Int
40)
  | Int
x forall a. Ord a => a -> a -> Bool
>= Int
10   = (Text
"x" forall a. Semigroup a => a -> a -> a
<>) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Maybe Text
toRoman (Int
x forall a. Num a => a -> a -> a
- Int
10)
  | Int
x forall a. Eq a => a -> a -> Bool
== Int
9    = forall (m :: * -> *) a. Monad m => a -> m a
return Text
"ix"
  | Int
x forall a. Ord a => a -> a -> Bool
>= Int
5    = (Text
"v" forall a. Semigroup a => a -> a -> a
<>) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Maybe Text
toRoman (Int
x forall a. Num a => a -> a -> a
- Int
5)
  | Int
x forall a. Eq a => a -> a -> Bool
== Int
4    = forall (m :: * -> *) a. Monad m => a -> m a
return Text
"iv"
  | Int
x forall a. Ord a => a -> a -> Bool
>= Int
1    = (Text
"i" forall a. Semigroup a => a -> a -> a
<>) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Maybe Text
toRoman (Int
x forall a. Num a => a -> a -> a
- Int
1)
  | Int
x forall a. Eq a => a -> a -> Bool
== Int
0    = forall (m :: * -> *) a. Monad m => a -> m a
return Text
""
  | Bool
otherwise = forall a. Maybe a
Nothing

applyPipes :: TemplateTarget a => [Pipe] -> Val a -> Val a
applyPipes :: forall a. TemplateTarget a => [Pipe] -> Val a -> Val a
applyPipes [Pipe]
fs Val a
x = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr forall a. TemplateTarget a => Pipe -> Val a -> Val a
applyPipe Val a
x forall a b. (a -> b) -> a -> b
$ forall a. [a] -> [a]
reverse [Pipe]
fs

multiLookup :: TemplateTarget a => [Text] -> Val a -> Val a
multiLookup :: forall a. TemplateTarget a => [Text] -> Val a -> Val a
multiLookup [] Val a
x = Val a
x
multiLookup (Text
t:[Text]
vs) (MapVal (Context Map Text (Val a)
o)) =
  case forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
t Map Text (Val a)
o of
    Maybe (Val a)
Nothing -> forall a. Val a
NullVal
    Just Val a
v' -> forall a. TemplateTarget a => [Text] -> Val a -> Val a
multiLookup [Text]
vs Val a
v'
multiLookup [Text]
_ Val a
_ = forall a. Val a
NullVal

-- The Bool indicates whether it's a true or false value.
data Resolved a = Resolved Bool [Doc a]
   deriving (Int -> Resolved a -> ShowS
forall a. Show a => Int -> Resolved a -> ShowS
forall a. Show a => [Resolved a] -> ShowS
forall a. Show a => Resolved a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Resolved a] -> ShowS
$cshowList :: forall a. Show a => [Resolved a] -> ShowS
show :: Resolved a -> String
$cshow :: forall a. Show a => Resolved a -> String
showsPrec :: Int -> Resolved a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Resolved a -> ShowS
Show, ReadPrec [Resolved a]
ReadPrec (Resolved a)
ReadS [Resolved a]
forall a. Read a => ReadPrec [Resolved a]
forall a. Read a => ReadPrec (Resolved a)
forall a. Read a => Int -> ReadS (Resolved a)
forall a. Read a => ReadS [Resolved a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Resolved a]
$creadListPrec :: forall a. Read a => ReadPrec [Resolved a]
readPrec :: ReadPrec (Resolved a)
$creadPrec :: forall a. Read a => ReadPrec (Resolved a)
readList :: ReadS [Resolved a]
$creadList :: forall a. Read a => ReadS [Resolved a]
readsPrec :: Int -> ReadS (Resolved a)
$creadsPrec :: forall a. Read a => Int -> ReadS (Resolved a)
Read, Resolved a -> DataType
Resolved a -> Constr
forall {a}. Data a => Typeable (Resolved a)
forall a. Data a => Resolved a -> DataType
forall a. Data a => Resolved a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b) -> Resolved a -> Resolved a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> Resolved a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> Resolved a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Resolved a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Resolved a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Resolved a -> m (Resolved a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Resolved a -> m (Resolved a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Resolved a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Resolved a -> c (Resolved a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Resolved a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Resolved a))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Resolved a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Resolved a -> c (Resolved a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Resolved a))
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Resolved a -> m (Resolved a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Resolved a -> m (Resolved a)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Resolved a -> m (Resolved a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Resolved a -> m (Resolved a)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Resolved a -> m (Resolved a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Resolved a -> m (Resolved a)
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Resolved a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> Resolved a -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> Resolved a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> Resolved a -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Resolved a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Resolved a -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Resolved a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Resolved a -> r
gmapT :: (forall b. Data b => b -> b) -> Resolved a -> Resolved a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> Resolved a -> Resolved a
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Resolved a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Resolved a))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Resolved a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Resolved a))
dataTypeOf :: Resolved a -> DataType
$cdataTypeOf :: forall a. Data a => Resolved a -> DataType
toConstr :: Resolved a -> Constr
$ctoConstr :: forall a. Data a => Resolved a -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Resolved a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Resolved a)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Resolved a -> c (Resolved a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Resolved a -> c (Resolved a)
Data, Typeable, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Resolved a) x -> Resolved a
forall a x. Resolved a -> Rep (Resolved a) x
$cto :: forall a x. Rep (Resolved a) x -> Resolved a
$cfrom :: forall a x. Resolved a -> Rep (Resolved a) x
Generic, Resolved a -> Resolved a -> Bool
forall a. Eq a => Resolved a -> Resolved a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Resolved a -> Resolved a -> Bool
$c/= :: forall a. Eq a => Resolved a -> Resolved a -> Bool
== :: Resolved a -> Resolved a -> Bool
$c== :: forall a. Eq a => Resolved a -> Resolved a -> Bool
Eq, Resolved a -> Resolved a -> Bool
Resolved a -> Resolved a -> Ordering
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {a}. Ord a => Eq (Resolved a)
forall a. Ord a => Resolved a -> Resolved a -> Bool
forall a. Ord a => Resolved a -> Resolved a -> Ordering
forall a. Ord a => Resolved a -> Resolved a -> Resolved a
min :: Resolved a -> Resolved a -> Resolved a
$cmin :: forall a. Ord a => Resolved a -> Resolved a -> Resolved a
max :: Resolved a -> Resolved a -> Resolved a
$cmax :: forall a. Ord a => Resolved a -> Resolved a -> Resolved a
>= :: Resolved a -> Resolved a -> Bool
$c>= :: forall a. Ord a => Resolved a -> Resolved a -> Bool
> :: Resolved a -> Resolved a -> Bool
$c> :: forall a. Ord a => Resolved a -> Resolved a -> Bool
<= :: Resolved a -> Resolved a -> Bool
$c<= :: forall a. Ord a => Resolved a -> Resolved a -> Bool
< :: Resolved a -> Resolved a -> Bool
$c< :: forall a. Ord a => Resolved a -> Resolved a -> Bool
compare :: Resolved a -> Resolved a -> Ordering
$ccompare :: forall a. Ord a => Resolved a -> Resolved a -> Ordering
Ord,
             forall a. Eq a => a -> Resolved a -> Bool
forall a. Num a => Resolved a -> a
forall a. Ord a => Resolved a -> a
forall m. Monoid m => Resolved m -> m
forall a. Resolved a -> Bool
forall a. Resolved a -> Int
forall a. Resolved a -> [a]
forall a. (a -> a -> a) -> Resolved a -> a
forall m a. Monoid m => (a -> m) -> Resolved a -> m
forall b a. (b -> a -> b) -> b -> Resolved a -> b
forall a b. (a -> b -> b) -> b -> Resolved a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => Resolved a -> a
$cproduct :: forall a. Num a => Resolved a -> a
sum :: forall a. Num a => Resolved a -> a
$csum :: forall a. Num a => Resolved a -> a
minimum :: forall a. Ord a => Resolved a -> a
$cminimum :: forall a. Ord a => Resolved a -> a
maximum :: forall a. Ord a => Resolved a -> a
$cmaximum :: forall a. Ord a => Resolved a -> a
elem :: forall a. Eq a => a -> Resolved a -> Bool
$celem :: forall a. Eq a => a -> Resolved a -> Bool
length :: forall a. Resolved a -> Int
$clength :: forall a. Resolved a -> Int
null :: forall a. Resolved a -> Bool
$cnull :: forall a. Resolved a -> Bool
toList :: forall a. Resolved a -> [a]
$ctoList :: forall a. Resolved a -> [a]
foldl1 :: forall a. (a -> a -> a) -> Resolved a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Resolved a -> a
foldr1 :: forall a. (a -> a -> a) -> Resolved a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Resolved a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> Resolved a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Resolved a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Resolved a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Resolved a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Resolved a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Resolved a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Resolved a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Resolved a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> Resolved a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Resolved a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Resolved a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Resolved a -> m
fold :: forall m. Monoid m => Resolved m -> m
$cfold :: forall m. Monoid m => Resolved m -> m
Foldable, Functor Resolved
Foldable Resolved
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Resolved (m a) -> m (Resolved a)
forall (f :: * -> *) a.
Applicative f =>
Resolved (f a) -> f (Resolved a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Resolved a -> m (Resolved b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Resolved a -> f (Resolved b)
sequence :: forall (m :: * -> *) a. Monad m => Resolved (m a) -> m (Resolved a)
$csequence :: forall (m :: * -> *) a. Monad m => Resolved (m a) -> m (Resolved a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Resolved a -> m (Resolved b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Resolved a -> m (Resolved b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
Resolved (f a) -> f (Resolved a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
Resolved (f a) -> f (Resolved a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Resolved a -> f (Resolved b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Resolved a -> f (Resolved b)
Traversable, forall a b. a -> Resolved b -> Resolved a
forall a b. (a -> b) -> Resolved a -> Resolved b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Resolved b -> Resolved a
$c<$ :: forall a b. a -> Resolved b -> Resolved a
fmap :: forall a b. (a -> b) -> Resolved a -> Resolved b
$cfmap :: forall a b. (a -> b) -> Resolved a -> Resolved b
Functor)

instance Semigroup (Resolved a) where
  Resolved Bool
b1 [Doc a]
x1 <> :: Resolved a -> Resolved a -> Resolved a
<> Resolved Bool
b2 [Doc a]
x2 = forall a. Bool -> [Doc a] -> Resolved a
Resolved (Bool
b1 Bool -> Bool -> Bool
|| Bool
b2) ([Doc a]
x1 forall a. Semigroup a => a -> a -> a
<> [Doc a]
x2)

instance Monoid (Resolved a) where
  mappend :: Resolved a -> Resolved a -> Resolved a
mappend = forall a. Semigroup a => a -> a -> a
(<>)
  mempty :: Resolved a
mempty = forall a. Bool -> [Doc a] -> Resolved a
Resolved Bool
False []

resolveVariable :: TemplateTarget a
                => Variable -> Context a -> Resolved a
resolveVariable :: forall a. TemplateTarget a => Variable -> Context a -> Resolved a
resolveVariable Variable
v Context a
ctx = forall a. TemplateTarget a => Variable -> Val a -> Resolved a
resolveVariable' Variable
v (forall a. Context a -> Val a
MapVal Context a
ctx)

resolveVariable' :: TemplateTarget a
                 => Variable -> Val a -> Resolved a
resolveVariable' :: forall a. TemplateTarget a => Variable -> Val a -> Resolved a
resolveVariable' Variable
v Val a
val =
  case forall a. TemplateTarget a => [Pipe] -> Val a -> Val a
applyPipes (Variable -> [Pipe]
varPipes Variable
v) forall a b. (a -> b) -> a -> b
$ forall a. TemplateTarget a => [Text] -> Val a -> Val a
multiLookup (Variable -> [Text]
varParts Variable
v) Val a
val of
    ListVal [Val a]
xs    -> forall a. Monoid a => [a] -> a
mconcat forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (forall a. TemplateTarget a => Variable -> Val a -> Resolved a
resolveVariable' forall a. Monoid a => a
mempty) [Val a]
xs
    SimpleVal Doc a
d
      | forall a. Doc a -> Bool
DL.isEmpty Doc a
d -> forall a. Bool -> [Doc a] -> Resolved a
Resolved Bool
False []
      | Bool
otherwise    -> forall a. Bool -> [Doc a] -> Resolved a
Resolved Bool
True [forall a. Doc a -> Doc a
removeFinalNl Doc a
d]
    MapVal Context a
_      -> forall a. Bool -> [Doc a] -> Resolved a
Resolved Bool
True [Doc a
"true"]
    BoolVal Bool
True  -> forall a. Bool -> [Doc a] -> Resolved a
Resolved Bool
True [Doc a
"true"]
    BoolVal Bool
False -> forall a. Bool -> [Doc a] -> Resolved a
Resolved Bool
False [Doc a
"false"]
    Val a
NullVal       -> forall a. Bool -> [Doc a] -> Resolved a
Resolved Bool
False []

removeFinalNl :: Doc a -> Doc a
removeFinalNl :: forall a. Doc a -> Doc a
removeFinalNl Doc a
DL.NewLine        = forall a. Monoid a => a
mempty
removeFinalNl Doc a
DL.CarriageReturn = forall a. Monoid a => a
mempty
removeFinalNl (DL.Concat Doc a
d1 Doc a
d2) = Doc a
d1 forall a. Semigroup a => a -> a -> a
<> forall a. Doc a -> Doc a
removeFinalNl Doc a
d2
removeFinalNl Doc a
x                 = Doc a
x

withVariable :: (Monad m, TemplateTarget a)
             => Variable -> Context a -> (Context a -> m (Doc a))
             -> m [Doc a]
withVariable :: forall (m :: * -> *) a.
(Monad m, TemplateTarget a) =>
Variable -> Context a -> (Context a -> m (Doc a)) -> m [Doc a]
withVariable Variable
var Context a
ctx Context a -> m (Doc a)
f =
  case forall a. TemplateTarget a => [Pipe] -> Val a -> Val a
applyPipes (Variable -> [Pipe]
varPipes Variable
var) forall a b. (a -> b) -> a -> b
$ forall a. TemplateTarget a => [Text] -> Val a -> Val a
multiLookup (Variable -> [Text]
varParts Variable
var) (forall a. Context a -> Val a
MapVal Context a
ctx) of
    Val a
NullVal     -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
    ListVal [Val a]
xs  -> forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (\Val a
iterval -> Context a -> m (Doc a)
f forall a b. (a -> b) -> a -> b
$ Val a -> Context a
setVarVal Val a
iterval) [Val a]
xs
    MapVal Context a
ctx' -> (forall a. a -> [a] -> [a]
:[]) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Context a -> m (Doc a)
f (Val a -> Context a
setVarVal (forall a. Context a -> Val a
MapVal Context a
ctx'))
    Val a
val' -> (forall a. a -> [a] -> [a]
:[]) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Context a -> m (Doc a)
f (Val a -> Context a
setVarVal Val a
val')
 where
  setVarVal :: Val a -> Context a
setVarVal Val a
x =
    forall {a}. Variable -> Val a -> Context a -> Context a
addToContext Variable
var Val a
x forall a b. (a -> b) -> a -> b
$ forall a. Map Text (Val a) -> Context a
Context forall a b. (a -> b) -> a -> b
$ forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Text
"it" Val a
x forall a b. (a -> b) -> a -> b
$ forall a. Context a -> Map Text (Val a)
unContext Context a
ctx
  addToContext :: Variable -> Val a -> Context a -> Context a
addToContext (Variable [] [Pipe]
_) Val a
_ (Context Map Text (Val a)
ctx') = forall a. Map Text (Val a) -> Context a
Context Map Text (Val a)
ctx'
  addToContext (Variable (Text
v:[Text]
vs) [Pipe]
fs) Val a
x (Context Map Text (Val a)
ctx') =
    forall a. Map Text (Val a) -> Context a
Context forall a b. (a -> b) -> a -> b
$ forall k a. Ord k => (a -> a) -> k -> Map k a -> Map k a
M.adjust
              (\Val a
z -> case Val a
z of
                       Val a
_ | forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Text]
vs -> Val a
x
                       MapVal Context a
m    ->
                         forall a. Context a -> Val a
MapVal forall a b. (a -> b) -> a -> b
$ Variable -> Val a -> Context a -> Context a
addToContext ([Text] -> [Pipe] -> Variable
Variable [Text]
vs [Pipe]
fs) Val a
x Context a
m
                       Val a
_ -> Val a
z) Text
v Map Text (Val a)
ctx'

type RenderState = S.State Int

-- | Render a compiled template in a "context" which provides
-- values for the template's variables.
renderTemplate :: (TemplateTarget a, ToContext a b)
               => Template a -> b -> Doc a
renderTemplate :: forall a b.
(TemplateTarget a, ToContext a b) =>
Template a -> b -> Doc a
renderTemplate Template a
t b
x = forall s a. State s a -> s -> a
S.evalState (forall a.
TemplateTarget a =>
Template a -> Context a -> RenderState (Doc a)
renderTemp Template a
t (forall a b. ToContext a b => b -> Context a
toContext b
x)) Int
0

updateColumn :: TemplateTarget a => Doc a -> RenderState (Doc a)
updateColumn :: forall a. TemplateTarget a => Doc a -> RenderState (Doc a)
updateColumn Doc a
x = do
  forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
S.modify forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => Doc a -> Int -> Int
DL.updateColumn Doc a
x
  forall (m :: * -> *) a. Monad m => a -> m a
return Doc a
x

renderTemp :: forall a . TemplateTarget a
           => Template a -> Context a -> RenderState (Doc a)
renderTemp :: forall a.
TemplateTarget a =>
Template a -> Context a -> RenderState (Doc a)
renderTemp (Literal Doc a
t) Context a
_ = forall a. TemplateTarget a => Doc a -> RenderState (Doc a)
updateColumn Doc a
t
renderTemp (Interpolate Variable
v) Context a
ctx =
  case forall a. TemplateTarget a => Variable -> Context a -> Resolved a
resolveVariable Variable
v Context a
ctx of
    Resolved Bool
_ [Doc a]
xs -> forall a. TemplateTarget a => Doc a -> RenderState (Doc a)
updateColumn (forall a. Monoid a => [a] -> a
mconcat [Doc a]
xs)
renderTemp (Conditional Variable
v Template a
ift Template a
elset) Context a
ctx =
  case forall a. TemplateTarget a => Variable -> Context a -> Resolved a
resolveVariable Variable
v Context a
ctx of
    Resolved Bool
False [Doc a]
_ -> forall a.
TemplateTarget a =>
Template a -> Context a -> RenderState (Doc a)
renderTemp Template a
elset Context a
ctx
    Resolved Bool
True [Doc a]
_  -> forall a.
TemplateTarget a =>
Template a -> Context a -> RenderState (Doc a)
renderTemp Template a
ift Context a
ctx
renderTemp (Iterate Variable
v Template a
t Template a
sep) Context a
ctx = do
  [Doc a]
xs <- forall (m :: * -> *) a.
(Monad m, TemplateTarget a) =>
Variable -> Context a -> (Context a -> m (Doc a)) -> m [Doc a]
withVariable Variable
v Context a
ctx (forall a.
TemplateTarget a =>
Template a -> Context a -> RenderState (Doc a)
renderTemp Template a
t)
  Doc a
sep' <- forall a.
TemplateTarget a =>
Template a -> Context a -> RenderState (Doc a)
renderTemp Template a
sep Context a
ctx
  forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> [a] -> [a]
intersperse Doc a
sep' forall a b. (a -> b) -> a -> b
$ [Doc a]
xs
renderTemp (Nested Template a
t) Context a
ctx = do
  Int
n <- forall s (m :: * -> *). MonadState s m => m s
S.get
  forall a. IsString a => Int -> Doc a -> Doc a
DL.nest Int
n forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a.
TemplateTarget a =>
Template a -> Context a -> RenderState (Doc a)
renderTemp Template a
t Context a
ctx
renderTemp (Partial [Pipe]
fs Template a
t) Context a
ctx = do
    Doc a
val' <- forall a.
TemplateTarget a =>
Template a -> Context a -> RenderState (Doc a)
renderTemp Template a
t Context a
ctx
    forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ case forall a. TemplateTarget a => [Pipe] -> Val a -> Val a
applyPipes [Pipe]
fs (forall a. Doc a -> Val a
SimpleVal Doc a
val') of
      SimpleVal Doc a
x -> Doc a
x
      Val a
_           -> forall a. Monoid a => a
mempty
renderTemp (Concat Template a
t1 Template a
t2) Context a
ctx =
  forall a. Monoid a => a -> a -> a
mappend forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a.
TemplateTarget a =>
Template a -> Context a -> RenderState (Doc a)
renderTemp Template a
t1 Context a
ctx forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a.
TemplateTarget a =>
Template a -> Context a -> RenderState (Doc a)
renderTemp Template a
t2 Context a
ctx
renderTemp Template a
Empty Context a
_ = forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty

-- | A 'TemplateMonad' defines a function to retrieve a partial
-- (from the file system, from a database, or using a default
-- value).
class Monad m => TemplateMonad m where
  getPartial  :: FilePath -> m Text

instance TemplateMonad Identity where
  getPartial :: String -> Identity Text
getPartial String
_  = forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty

instance TemplateMonad IO where
  getPartial :: String -> IO Text
getPartial = String -> IO Text
TIO.readFile