{-# 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 Data.YAML (ToYAML(..), FromYAML(..), Node(..), Scalar(..))
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
[Template a] -> ShowS
Template a -> String
(Int -> Template a -> ShowS)
-> (Template a -> String)
-> ([Template a] -> ShowS)
-> Show (Template a)
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)
Int -> ReadS (Template a)
ReadS [Template a]
(Int -> ReadS (Template a))
-> ReadS [Template a]
-> ReadPrec (Template a)
-> ReadPrec [Template a]
-> Read (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, Typeable (Template a)
DataType
Constr
Typeable (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 (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Template a))
-> (Template a -> Constr)
-> (Template a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (Template a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (Template a)))
-> ((forall b. Data b => b -> b) -> Template a -> Template a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Template a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Template a -> r)
-> (forall u. (forall d. Data d => d -> u) -> Template a -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> Template a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Template a -> m (Template a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Template a -> m (Template a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Template a -> m (Template a))
-> Data (Template a)
Template a -> DataType
Template a -> Constr
(forall d. Data d => c (t d)) -> Maybe (c (Template a))
(forall b. Data b => b -> b) -> Template a -> Template a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Template a -> c (Template a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Template a)
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 u. Int -> (forall d. Data d => d -> u) -> Template a -> u
forall u. (forall d. Data d => d -> u) -> Template a -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Template a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Template a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Template a -> m (Template a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Template a -> m (Template 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))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Template a))
$cEmpty :: Constr
$cConcat :: Constr
$cLiteral :: Constr
$cPartial :: Constr
$cNested :: Constr
$cIterate :: Constr
$cConditional :: Constr
$cInterpolate :: Constr
$tTemplate :: DataType
gmapMo :: (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 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 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 :: 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 d. Data d => d -> u) -> Template a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> Template a -> [u]
gmapQr :: (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 :: (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 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 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 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 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)
$cp1Data :: forall a. Data a => Typeable (Template a)
Data, Typeable, (forall x. Template a -> Rep (Template a) x)
-> (forall x. Rep (Template a) x -> Template a)
-> Generic (Template a)
forall x. Rep (Template a) x -> Template a
forall x. Template a -> Rep (Template a) x
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
(Template a -> Template a -> Bool)
-> (Template a -> Template a -> Bool) -> Eq (Template a)
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, Eq (Template a)
Eq (Template a)
-> (Template a -> Template a -> Ordering)
-> (Template a -> Template a -> Bool)
-> (Template a -> Template a -> Bool)
-> (Template a -> Template a -> Bool)
-> (Template a -> Template a -> Bool)
-> (Template a -> Template a -> Template a)
-> (Template a -> Template a -> Template a)
-> Ord (Template a)
Template a -> Template a -> Bool
Template a -> Template a -> Ordering
Template a -> Template a -> Template a
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
$cp1Ord :: forall a. Ord a => Eq (Template a)
Ord,
               Template a -> Bool
(a -> m) -> Template a -> m
(a -> b -> b) -> b -> Template a -> b
(forall m. Monoid m => Template m -> m)
-> (forall m a. Monoid m => (a -> m) -> Template a -> m)
-> (forall m a. Monoid m => (a -> m) -> Template a -> m)
-> (forall a b. (a -> b -> b) -> b -> Template a -> b)
-> (forall a b. (a -> b -> b) -> b -> Template a -> b)
-> (forall b a. (b -> a -> b) -> b -> Template a -> b)
-> (forall b a. (b -> a -> b) -> b -> Template a -> b)
-> (forall a. (a -> a -> a) -> Template a -> a)
-> (forall a. (a -> a -> a) -> Template a -> a)
-> (forall a. Template a -> [a])
-> (forall a. Template a -> Bool)
-> (forall a. Template a -> Int)
-> (forall a. Eq a => a -> Template a -> Bool)
-> (forall a. Ord a => Template a -> a)
-> (forall a. Ord a => Template a -> a)
-> (forall a. Num a => Template a -> a)
-> (forall a. Num a => Template a -> a)
-> Foldable Template
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 :: Template a -> a
$cproduct :: forall a. Num a => Template a -> a
sum :: Template a -> a
$csum :: forall a. Num a => Template a -> a
minimum :: Template a -> a
$cminimum :: forall a. Ord a => Template a -> a
maximum :: Template a -> a
$cmaximum :: forall a. Ord a => Template a -> a
elem :: a -> Template a -> Bool
$celem :: forall a. Eq a => a -> Template a -> Bool
length :: Template a -> Int
$clength :: forall a. Template a -> Int
null :: Template a -> Bool
$cnull :: forall a. Template a -> Bool
toList :: Template a -> [a]
$ctoList :: forall a. Template a -> [a]
foldl1 :: (a -> a -> a) -> Template a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Template a -> a
foldr1 :: (a -> a -> a) -> Template a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Template a -> a
foldl' :: (b -> a -> b) -> b -> Template a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Template a -> b
foldl :: (b -> a -> b) -> b -> Template a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Template a -> b
foldr' :: (a -> b -> b) -> b -> Template a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Template a -> b
foldr :: (a -> b -> b) -> b -> Template a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Template a -> b
foldMap' :: (a -> m) -> Template a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Template a -> m
foldMap :: (a -> m) -> Template a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Template a -> m
fold :: Template m -> m
$cfold :: forall m. Monoid m => Template m -> m
Foldable, Functor Template
Foldable Template
Functor Template
-> Foldable Template
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> Template a -> f (Template b))
-> (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 (m :: * -> *) a.
    Monad m =>
    Template (m a) -> m (Template a))
-> Traversable Template
(a -> f b) -> Template a -> f (Template b)
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 :: Template (m a) -> m (Template a)
$csequence :: forall (m :: * -> *) a. Monad m => Template (m a) -> m (Template a)
mapM :: (a -> m b) -> Template a -> m (Template b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Template a -> m (Template b)
sequenceA :: Template (f a) -> f (Template a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
Template (f a) -> f (Template a)
traverse :: (a -> f b) -> Template a -> f (Template b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Template a -> f (Template b)
$cp2Traversable :: Foldable Template
$cp1Traversable :: Functor Template
Traversable, a -> Template b -> Template a
(a -> b) -> Template a -> Template b
(forall a b. (a -> b) -> Template a -> Template b)
-> (forall a b. a -> Template b -> Template a) -> Functor Template
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
<$ :: a -> Template b -> Template a
$c<$ :: forall a b. a -> Template b -> Template a
fmap :: (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 = Template a -> Template a -> Template a
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 = Template a -> Template a -> Template a
forall a. Semigroup a => a -> a -> a
(<>)
  mempty :: Template a
mempty = Template a
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
(Int -> Pipe -> ShowS)
-> (Pipe -> String) -> ([Pipe] -> ShowS) -> Show Pipe
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]
(Int -> ReadS Pipe)
-> ReadS [Pipe] -> ReadPrec Pipe -> ReadPrec [Pipe] -> Read 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
DataType
Constr
Typeable Pipe
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Pipe -> c Pipe)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Pipe)
-> (Pipe -> Constr)
-> (Pipe -> DataType)
-> (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))
-> ((forall b. Data b => b -> b) -> Pipe -> Pipe)
-> (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 u. (forall d. Data d => d -> u) -> Pipe -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Pipe -> u)
-> (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 (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Pipe -> m Pipe)
-> Data Pipe
Pipe -> DataType
Pipe -> Constr
(forall b. Data b => b -> b) -> Pipe -> Pipe
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Pipe -> c Pipe
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c 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)
$cBlock :: Constr
$cNoWrap :: Constr
$cToRoman :: Constr
$cToAlpha :: Constr
$cChomp :: Constr
$cAllButLast :: Constr
$cRest :: Constr
$cLastItem :: Constr
$cFirstItem :: Constr
$cReverse :: Constr
$cToLength :: Constr
$cToLowercase :: Constr
$cToUppercase :: Constr
$cToPairs :: Constr
$tPipe :: DataType
gmapMo :: (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 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 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 :: Int -> (forall d. Data d => d -> u) -> Pipe -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Pipe -> u
gmapQ :: (forall d. Data d => d -> u) -> Pipe -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Pipe -> [u]
gmapQr :: (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 :: (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 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 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 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 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
$cp1Data :: Typeable Pipe
Data, Typeable, (forall x. Pipe -> Rep Pipe x)
-> (forall x. Rep Pipe x -> Pipe) -> Generic Pipe
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
(Pipe -> Pipe -> Bool) -> (Pipe -> Pipe -> Bool) -> Eq Pipe
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
Eq Pipe
-> (Pipe -> Pipe -> Ordering)
-> (Pipe -> Pipe -> Bool)
-> (Pipe -> Pipe -> Bool)
-> (Pipe -> Pipe -> Bool)
-> (Pipe -> Pipe -> Bool)
-> (Pipe -> Pipe -> Pipe)
-> (Pipe -> Pipe -> Pipe)
-> Ord 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
$cp1Ord :: Eq Pipe
Ord)

data Alignment =
      LeftAligned
    | Centered
    | RightAligned
    deriving (Int -> Alignment -> ShowS
[Alignment] -> ShowS
Alignment -> String
(Int -> Alignment -> ShowS)
-> (Alignment -> String)
-> ([Alignment] -> ShowS)
-> Show Alignment
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]
(Int -> ReadS Alignment)
-> ReadS [Alignment]
-> ReadPrec Alignment
-> ReadPrec [Alignment]
-> Read 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
DataType
Constr
Typeable Alignment
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Alignment -> c Alignment)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Alignment)
-> (Alignment -> Constr)
-> (Alignment -> DataType)
-> (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))
-> ((forall b. Data b => b -> b) -> Alignment -> Alignment)
-> (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 u. (forall d. Data d => d -> u) -> Alignment -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> Alignment -> u)
-> (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 (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Alignment -> m Alignment)
-> Data Alignment
Alignment -> DataType
Alignment -> Constr
(forall b. Data b => b -> b) -> Alignment -> Alignment
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Alignment -> c Alignment
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c 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)
$cRightAligned :: Constr
$cCentered :: Constr
$cLeftAligned :: Constr
$tAlignment :: DataType
gmapMo :: (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 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 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 :: Int -> (forall d. Data d => d -> u) -> Alignment -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Alignment -> u
gmapQ :: (forall d. Data d => d -> u) -> Alignment -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Alignment -> [u]
gmapQr :: (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 :: (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 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 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 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 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
$cp1Data :: Typeable Alignment
Data, Typeable, (forall x. Alignment -> Rep Alignment x)
-> (forall x. Rep Alignment x -> Alignment) -> Generic Alignment
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
(Alignment -> Alignment -> Bool)
-> (Alignment -> Alignment -> Bool) -> Eq Alignment
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
Eq Alignment
-> (Alignment -> Alignment -> Ordering)
-> (Alignment -> Alignment -> Bool)
-> (Alignment -> Alignment -> Bool)
-> (Alignment -> Alignment -> Bool)
-> (Alignment -> Alignment -> Bool)
-> (Alignment -> Alignment -> Alignment)
-> (Alignment -> Alignment -> Alignment)
-> Ord 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
$cp1Ord :: Eq Alignment
Ord)

data Border = Border
     { Border -> Text
borderLeft  :: Text
     , Border -> Text
borderRight :: Text
     }
    deriving (Int -> Border -> ShowS
[Border] -> ShowS
Border -> String
(Int -> Border -> ShowS)
-> (Border -> String) -> ([Border] -> ShowS) -> Show Border
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]
(Int -> ReadS Border)
-> ReadS [Border]
-> ReadPrec Border
-> ReadPrec [Border]
-> Read 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
DataType
Constr
Typeable Border
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Border -> c Border)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Border)
-> (Border -> Constr)
-> (Border -> DataType)
-> (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))
-> ((forall b. Data b => b -> b) -> Border -> Border)
-> (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 u. (forall d. Data d => d -> u) -> Border -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Border -> u)
-> (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 (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Border -> m Border)
-> Data Border
Border -> DataType
Border -> Constr
(forall b. Data b => b -> b) -> Border -> Border
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Border -> c Border
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c 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)
$cBorder :: Constr
$tBorder :: DataType
gmapMo :: (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 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 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 :: Int -> (forall d. Data d => d -> u) -> Border -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Border -> u
gmapQ :: (forall d. Data d => d -> u) -> Border -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Border -> [u]
gmapQr :: (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 :: (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 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 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 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 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
$cp1Data :: Typeable Border
Data, Typeable, (forall x. Border -> Rep Border x)
-> (forall x. Rep Border x -> Border) -> Generic Border
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
(Border -> Border -> Bool)
-> (Border -> Border -> Bool) -> Eq Border
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
Eq Border
-> (Border -> Border -> Ordering)
-> (Border -> Border -> Bool)
-> (Border -> Border -> Bool)
-> (Border -> Border -> Bool)
-> (Border -> Border -> Bool)
-> (Border -> Border -> Border)
-> (Border -> Border -> Border)
-> Ord 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
$cp1Ord :: Eq Border
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
(Int -> Variable -> ShowS)
-> (Variable -> String) -> ([Variable] -> ShowS) -> Show Variable
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]
(Int -> ReadS Variable)
-> ReadS [Variable]
-> ReadPrec Variable
-> ReadPrec [Variable]
-> Read 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
DataType
Constr
Typeable Variable
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Variable -> c Variable)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Variable)
-> (Variable -> Constr)
-> (Variable -> DataType)
-> (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))
-> ((forall b. Data b => b -> b) -> Variable -> Variable)
-> (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 u. (forall d. Data d => d -> u) -> Variable -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Variable -> u)
-> (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 (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Variable -> m Variable)
-> Data Variable
Variable -> DataType
Variable -> Constr
(forall b. Data b => b -> b) -> Variable -> Variable
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Variable -> c Variable
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c 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)
$cVariable :: Constr
$tVariable :: DataType
gmapMo :: (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 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 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 :: Int -> (forall d. Data d => d -> u) -> Variable -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Variable -> u
gmapQ :: (forall d. Data d => d -> u) -> Variable -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Variable -> [u]
gmapQr :: (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 :: (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 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 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 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 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
$cp1Data :: Typeable Variable
Data, Typeable, (forall x. Variable -> Rep Variable x)
-> (forall x. Rep Variable x -> Variable) -> Generic Variable
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
(Variable -> Variable -> Bool)
-> (Variable -> Variable -> Bool) -> Eq Variable
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
Eq Variable
-> (Variable -> Variable -> Ordering)
-> (Variable -> Variable -> Bool)
-> (Variable -> Variable -> Bool)
-> (Variable -> Variable -> Bool)
-> (Variable -> Variable -> Bool)
-> (Variable -> Variable -> Variable)
-> (Variable -> Variable -> Variable)
-> Ord 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
$cp1Ord :: Eq Variable
Ord)

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

instance Monoid Variable where
  mempty :: Variable
mempty = [Text] -> [Pipe] -> Variable
Variable [Text]
forall a. Monoid a => a
mempty [Pipe]
forall a. Monoid a => a
mempty
  mappend :: Variable -> Variable -> Variable
mappend = Variable -> Variable -> Variable
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 { Context a -> Map Text (Val a)
unContext :: M.Map Text (Val a) }
  deriving (Int -> Context a -> ShowS
[Context a] -> ShowS
Context a -> String
(Int -> Context a -> ShowS)
-> (Context a -> String)
-> ([Context a] -> ShowS)
-> Show (Context a)
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, b -> Context a -> Context a
NonEmpty (Context a) -> Context a
Context a -> Context a -> Context a
(Context a -> Context a -> Context a)
-> (NonEmpty (Context a) -> Context a)
-> (forall b. Integral b => b -> Context a -> Context a)
-> Semigroup (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 :: 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, Semigroup (Context a)
Context a
Semigroup (Context a)
-> Context a
-> (Context a -> Context a -> Context a)
-> ([Context a] -> Context a)
-> Monoid (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
$cp1Monoid :: forall a. Semigroup (Context a)
Monoid, Functor Context
Foldable Context
Functor Context
-> Foldable Context
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> Context a -> f (Context b))
-> (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 (m :: * -> *) a.
    Monad m =>
    Context (m a) -> m (Context a))
-> Traversable Context
(a -> f b) -> Context a -> f (Context b)
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 :: Context (m a) -> m (Context a)
$csequence :: forall (m :: * -> *) a. Monad m => Context (m a) -> m (Context a)
mapM :: (a -> m b) -> Context a -> m (Context b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Context a -> m (Context b)
sequenceA :: Context (f a) -> f (Context a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
Context (f a) -> f (Context a)
traverse :: (a -> f b) -> Context a -> f (Context b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Context a -> f (Context b)
$cp2Traversable :: Foldable Context
$cp1Traversable :: Functor Context
Traversable, Context a -> Bool
(a -> m) -> Context a -> m
(a -> b -> b) -> b -> Context a -> b
(forall m. Monoid m => Context m -> m)
-> (forall m a. Monoid m => (a -> m) -> Context a -> m)
-> (forall m a. Monoid m => (a -> m) -> Context a -> m)
-> (forall a b. (a -> b -> b) -> b -> Context a -> b)
-> (forall a b. (a -> b -> b) -> b -> Context a -> b)
-> (forall b a. (b -> a -> b) -> b -> Context a -> b)
-> (forall b a. (b -> a -> b) -> b -> Context a -> b)
-> (forall a. (a -> a -> a) -> Context a -> a)
-> (forall a. (a -> a -> a) -> Context a -> a)
-> (forall a. Context a -> [a])
-> (forall a. Context a -> Bool)
-> (forall a. Context a -> Int)
-> (forall a. Eq a => a -> Context a -> Bool)
-> (forall a. Ord a => Context a -> a)
-> (forall a. Ord a => Context a -> a)
-> (forall a. Num a => Context a -> a)
-> (forall a. Num a => Context a -> a)
-> Foldable Context
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 :: Context a -> a
$cproduct :: forall a. Num a => Context a -> a
sum :: Context a -> a
$csum :: forall a. Num a => Context a -> a
minimum :: Context a -> a
$cminimum :: forall a. Ord a => Context a -> a
maximum :: Context a -> a
$cmaximum :: forall a. Ord a => Context a -> a
elem :: a -> Context a -> Bool
$celem :: forall a. Eq a => a -> Context a -> Bool
length :: Context a -> Int
$clength :: forall a. Context a -> Int
null :: Context a -> Bool
$cnull :: forall a. Context a -> Bool
toList :: Context a -> [a]
$ctoList :: forall a. Context a -> [a]
foldl1 :: (a -> a -> a) -> Context a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Context a -> a
foldr1 :: (a -> a -> a) -> Context a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Context a -> a
foldl' :: (b -> a -> b) -> b -> Context a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Context a -> b
foldl :: (b -> a -> b) -> b -> Context a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Context a -> b
foldr' :: (a -> b -> b) -> b -> Context a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Context a -> b
foldr :: (a -> b -> b) -> b -> Context a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Context a -> b
foldMap' :: (a -> m) -> Context a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Context a -> m
foldMap :: (a -> m) -> Context a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Context a -> m
fold :: Context m -> m
$cfold :: forall m. Monoid m => Context m -> m
Foldable, a -> Context b -> Context a
(a -> b) -> Context a -> Context b
(forall a b. (a -> b) -> Context a -> Context b)
-> (forall a b. a -> Context b -> Context a) -> Functor Context
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
<$ :: a -> Context b -> Context a
$c<$ :: forall a b. a -> Context b -> Context a
fmap :: (a -> b) -> Context a -> Context b
$cfmap :: forall a b. (a -> b) -> Context a -> Context b
Functor,
            Typeable (Context a)
DataType
Constr
Typeable (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 (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Context a))
-> (Context a -> Constr)
-> (Context a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (Context a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (Context a)))
-> ((forall b. Data b => b -> b) -> Context a -> Context a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Context a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Context a -> r)
-> (forall u. (forall d. Data d => d -> u) -> Context a -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> Context a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Context a -> m (Context a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Context a -> m (Context a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Context a -> m (Context a))
-> Data (Context a)
Context a -> DataType
Context a -> Constr
(forall d. Data d => c (t d)) -> Maybe (c (Context a))
(forall b. Data b => b -> b) -> Context a -> Context a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Context a -> c (Context a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Context a)
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 u. Int -> (forall d. Data d => d -> u) -> Context a -> u
forall u. (forall d. Data d => d -> u) -> Context a -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Context a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Context a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Context a -> m (Context a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Context a -> m (Context 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))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Context a))
$cContext :: Constr
$tContext :: DataType
gmapMo :: (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 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 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 :: 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 d. Data d => d -> u) -> Context a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> Context a -> [u]
gmapQr :: (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 :: (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 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 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 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 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)
$cp1Data :: forall a. Data a => Typeable (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
[Val a] -> ShowS
Val a -> String
(Int -> Val a -> ShowS)
-> (Val a -> String) -> ([Val a] -> ShowS) -> Show (Val a)
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
Functor Val
-> Foldable Val
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> Val a -> f (Val b))
-> (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 (m :: * -> *) a. Monad m => Val (m a) -> m (Val a))
-> Traversable Val
(a -> f b) -> Val a -> f (Val b)
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 :: Val (m a) -> m (Val a)
$csequence :: forall (m :: * -> *) a. Monad m => Val (m a) -> m (Val a)
mapM :: (a -> m b) -> Val a -> m (Val b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Val a -> m (Val b)
sequenceA :: Val (f a) -> f (Val a)
$csequenceA :: forall (f :: * -> *) a. Applicative f => Val (f a) -> f (Val a)
traverse :: (a -> f b) -> Val a -> f (Val b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Val a -> f (Val b)
$cp2Traversable :: Foldable Val
$cp1Traversable :: Functor Val
Traversable, Val a -> Bool
(a -> m) -> Val a -> m
(a -> b -> b) -> b -> Val a -> b
(forall m. Monoid m => Val m -> m)
-> (forall m a. Monoid m => (a -> m) -> Val a -> m)
-> (forall m a. Monoid m => (a -> m) -> Val a -> m)
-> (forall a b. (a -> b -> b) -> b -> Val a -> b)
-> (forall a b. (a -> b -> b) -> b -> Val a -> b)
-> (forall b a. (b -> a -> b) -> b -> Val a -> b)
-> (forall b a. (b -> a -> b) -> b -> Val a -> b)
-> (forall a. (a -> a -> a) -> Val a -> a)
-> (forall a. (a -> a -> a) -> Val a -> a)
-> (forall a. Val a -> [a])
-> (forall a. Val a -> Bool)
-> (forall a. Val a -> Int)
-> (forall a. Eq a => a -> Val a -> Bool)
-> (forall a. Ord a => Val a -> a)
-> (forall a. Ord a => Val a -> a)
-> (forall a. Num a => Val a -> a)
-> (forall a. Num a => Val a -> a)
-> Foldable Val
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 :: Val a -> a
$cproduct :: forall a. Num a => Val a -> a
sum :: Val a -> a
$csum :: forall a. Num a => Val a -> a
minimum :: Val a -> a
$cminimum :: forall a. Ord a => Val a -> a
maximum :: Val a -> a
$cmaximum :: forall a. Ord a => Val a -> a
elem :: a -> Val a -> Bool
$celem :: forall a. Eq a => a -> Val a -> Bool
length :: Val a -> Int
$clength :: forall a. Val a -> Int
null :: Val a -> Bool
$cnull :: forall a. Val a -> Bool
toList :: Val a -> [a]
$ctoList :: forall a. Val a -> [a]
foldl1 :: (a -> a -> a) -> Val a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Val a -> a
foldr1 :: (a -> a -> a) -> Val a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Val a -> a
foldl' :: (b -> a -> b) -> b -> Val a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Val a -> b
foldl :: (b -> a -> b) -> b -> Val a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Val a -> b
foldr' :: (a -> b -> b) -> b -> Val a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Val a -> b
foldr :: (a -> b -> b) -> b -> Val a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Val a -> b
foldMap' :: (a -> m) -> Val a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Val a -> m
foldMap :: (a -> m) -> Val a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Val a -> m
fold :: Val m -> m
$cfold :: forall m. Monoid m => Val m -> m
Foldable, a -> Val b -> Val a
(a -> b) -> Val a -> Val b
(forall a b. (a -> b) -> Val a -> Val b)
-> (forall a b. a -> Val b -> Val a) -> Functor Val
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
<$ :: a -> Val b -> Val a
$c<$ :: forall a b. a -> Val b -> Val a
fmap :: (a -> b) -> Val a -> Val b
$cfmap :: forall a b. (a -> b) -> Val a -> Val b
Functor, Typeable (Val a)
DataType
Constr
Typeable (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 (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Val a))
-> (Val a -> Constr)
-> (Val a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (Val a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Val a)))
-> ((forall b. Data b => b -> b) -> Val a -> Val a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Val a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Val a -> r)
-> (forall u. (forall d. Data d => d -> u) -> Val a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Val a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Val a -> m (Val a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Val a -> m (Val a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Val a -> m (Val a))
-> Data (Val a)
Val a -> DataType
Val a -> Constr
(forall d. Data d => c (t d)) -> Maybe (c (Val a))
(forall b. Data b => b -> b) -> Val a -> Val a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Val a -> c (Val a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Val a)
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 u. Int -> (forall d. Data d => d -> u) -> Val a -> u
forall u. (forall d. Data d => d -> u) -> Val a -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Val a -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Val a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Val a -> m (Val a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Val a -> m (Val 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))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Val a))
$cNullVal :: Constr
$cBoolVal :: Constr
$cMapVal :: Constr
$cListVal :: Constr
$cSimpleVal :: Constr
$tVal :: DataType
gmapMo :: (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 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 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 :: 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 d. Data d => d -> u) -> Val a -> [u]
$cgmapQ :: forall a u. Data a => (forall d. Data d => d -> u) -> Val a -> [u]
gmapQr :: (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 :: (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 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 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 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 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)
$cp1Data :: forall a. Data a => Typeable (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 b -> Val a
forall a b. ToContext a b => b -> Val a
toVal b
x of
                  MapVal Context a
c -> Context a
c
                  Val a
_        -> Context a
forall a. Monoid a => a
mempty
  toVal     :: b -> Val a

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

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

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

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

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

instance {-# OVERLAPPING #-} TemplateTarget [a] => ToContext [a] [a] where
  toVal :: [a] -> Val [a]
toVal    = Doc [a] -> Val [a]
forall a. Doc a -> Val a
SimpleVal (Doc [a] -> Val [a]) -> ([a] -> Doc [a]) -> [a] -> Val [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> Doc [a]
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     = Context a -> Val a
forall a. Context a -> Val a
MapVal (Context a -> Val a)
-> (Map Text b -> Context a) -> Map Text b -> Val a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map Text b -> Context a
forall a b. ToContext a b => b -> Context a
toContext
  toContext :: Map Text b -> Context a
toContext = Map Text (Val a) -> Context a
forall a. Map Text (Val a) -> Context a
Context (Map Text (Val a) -> Context a)
-> (Map Text b -> Map Text (Val a)) -> Map Text b -> Context a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (b -> Val a) -> Map Text b -> Map Text (Val a)
forall a b k. (a -> b) -> Map k a -> Map k b
M.map b -> Val a
forall a b. ToContext a b => b -> Val a
toVal

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

instance TemplateTarget a => ToContext a Value where
  toContext :: Value -> Context a
toContext Value
x = case Value -> Result (Context a)
forall a. FromJSON a => Value -> Result a
fromJSON Value
x of
                  Success Context a
y -> Context a
y
                  Error String
_   -> Context a
forall a. Monoid a => a
mempty
  toVal :: Value -> Val a
toVal Value
x = case Value -> Result (Val a)
forall a. FromJSON a => Value -> Result a
fromJSON Value
x of
                  Success Val a
y -> Val a
y
                  Error String
_   -> Val a
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) = Text -> Map Text (Val a) -> Maybe (Val a)
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
t Map Text (Val a)
m Maybe (Val a) -> (Val a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Val a -> Maybe 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 = Val a -> Maybe (Val a)
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) = Doc a -> Maybe (Doc a)
forall a. a -> Maybe a
Just Doc a
x
  fromVal Val a
_             = Maybe (Doc a)
forall a. Maybe a
Nothing

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

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

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

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

instance TemplateTarget a => FromYAML (Val a) where
  parseYAML :: Node Pos -> Parser (Val a)
parseYAML Node Pos
v =
    case Node Pos
v of
      Mapping Pos
_ Tag
_ Mapping Pos
m -> Context a -> Val a
forall a. Context a -> Val a
MapVal (Context a -> Val a)
-> ([(Text, Val a)] -> Context a) -> [(Text, Val a)] -> Val a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map Text (Val a) -> Context a
forall a. Map Text (Val a) -> Context a
Context (Map Text (Val a) -> Context a)
-> ([(Text, Val a)] -> Map Text (Val a))
-> [(Text, Val a)]
-> Context a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Text, Val a)] -> Map Text (Val a)
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList ([(Text, Val a)] -> Val a)
-> Parser [(Text, Val a)] -> Parser (Val a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
                           ((Node Pos, Node Pos) -> Parser (Text, Val a))
-> [(Node Pos, Node Pos)] -> Parser [(Text, Val a)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (\(Node Pos
key, Node Pos
val) -> do
                                  Val a
val' <- Node Pos -> Parser (Val a)
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
val
                                  Text
key' <- Node Pos -> Parser Text
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
key
                                  (Text, Val a) -> Parser (Text, Val a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
key', Val a
val')) (Mapping Pos -> [(Node Pos, Node Pos)]
forall k a. Map k a -> [(k, a)]
M.toList Mapping Pos
m)
      Sequence Pos
_ Tag
_ [Node Pos]
xs -> [Val a] -> Val a
forall a. [Val a] -> Val a
ListVal ([Val a] -> Val a) -> Parser [Val a] -> Parser (Val a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Node Pos -> Parser (Val a)) -> [Node Pos] -> Parser [Val a]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Node Pos -> Parser (Val a)
forall a. FromYAML a => Node Pos -> Parser a
parseYAML [Node Pos]
xs
      Scalar Pos
_ (SStr Text
t) -> Val a -> Parser (Val a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Val a -> Parser (Val a)) -> Val a -> Parser (Val a)
forall a b. (a -> b) -> a -> b
$ Doc a -> Val a
forall a. Doc a -> Val a
SimpleVal (Doc a -> Val a) -> Doc a -> Val a
forall a b. (a -> b) -> a -> b
$ String -> Doc a
forall a. IsString a => String -> a
fromString (String -> Doc a) -> (Text -> String) -> Text -> Doc a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
forall a. FromText a => Text -> a
fromText (Text -> Doc a) -> Text -> Doc a
forall a b. (a -> b) -> a -> b
$ Text
t
      Scalar Pos
_ (SFloat Double
n) -> Val a -> Parser (Val a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Val a -> Parser (Val a)) -> Val a -> Parser (Val a)
forall a b. (a -> b) -> a -> b
$ Doc a -> Val a
forall a. Doc a -> Val a
SimpleVal (Doc a -> Val a) -> Doc a -> Val a
forall a b. (a -> b) -> a -> b
$ String -> Doc a
forall a. IsString a => String -> a
fromString (String -> Doc a) -> (Double -> String) -> Double -> Doc a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> String
forall a. Show a => a -> String
show (Double -> Doc a) -> Double -> Doc a
forall a b. (a -> b) -> a -> b
$ Double
n
      Scalar Pos
_ (SInt Integer
n) -> Val a -> Parser (Val a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Val a -> Parser (Val a)) -> Val a -> Parser (Val a)
forall a b. (a -> b) -> a -> b
$ Doc a -> Val a
forall a. Doc a -> Val a
SimpleVal (Doc a -> Val a) -> Doc a -> Val a
forall a b. (a -> b) -> a -> b
$ String -> Doc a
forall a. IsString a => String -> a
fromString (String -> Doc a) -> (Integer -> String) -> Integer -> Doc a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> String
forall a. Show a => a -> String
show (Integer -> Doc a) -> Integer -> Doc a
forall a b. (a -> b) -> a -> b
$ Integer
n
      Scalar Pos
_ (SBool Bool
b) -> Val a -> Parser (Val a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Val a -> Parser (Val a)) -> Val a -> Parser (Val a)
forall a b. (a -> b) -> a -> b
$ Bool -> Val a
forall a. Bool -> Val a
BoolVal Bool
b
      Node Pos
_           -> Val a -> Parser (Val a)
forall (m :: * -> *) a. Monad m => a -> m a
return Val a
forall a. Val a
NullVal

instance TemplateTarget a => FromYAML (Context a) where
  parseYAML :: Node Pos -> Parser (Context a)
parseYAML Node Pos
v = do
    Val a
val <- Node Pos -> Parser (Val a)
forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
v
    case Val a
val of
      MapVal Context a
o -> Context a -> Parser (Context a)
forall (m :: * -> *) a. Monad m => a -> m a
return Context a
o
      Val a
_        -> String -> Parser (Context 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) = Map Text (Val a) -> Value
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) = Context a -> Value
forall a. ToJSON a => a -> Value
toJSON Context a
m
  toJSON (ListVal [Val a]
xs) = [Val a] -> Value
forall a. ToJSON a => a -> Value
toJSON [Val a]
xs
  toJSON (SimpleVal Doc a
d) = Text -> Value
forall a. ToJSON a => a -> Value
toJSON (Text -> Value) -> Text -> Value
forall a b. (a -> b) -> a -> b
$ a -> Text
forall a. ToText a => a -> Text
toText (a -> Text) -> a -> Text
forall a b. (a -> b) -> a -> b
$ Maybe Int -> Doc a -> a
forall a. HasChars a => Maybe Int -> Doc a -> a
DL.render Maybe Int
forall a. Maybe a
Nothing Doc a
d
  toJSON (BoolVal Bool
b) = Bool -> Value
forall a. ToJSON a => a -> Value
toJSON Bool
b

instance TemplateTarget a => ToYAML (Context a) where
  toYAML :: Context a -> Node ()
toYAML (Context Map Text (Val a)
m) = Map Text (Val a) -> Node ()
forall a. ToYAML a => a -> Node ()
toYAML Map Text (Val a)
m

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

mapDoc :: TemplateTarget a => (Doc a -> Doc a) -> Val a -> Val a
mapDoc :: (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        -> Doc a -> Val a
forall a. Doc a -> Val a
SimpleVal (Doc a -> Doc a
f Doc a
d)
    MapVal (Context Map Text (Val a)
m) -> Context a -> Val a
forall a. Context a -> Val a
MapVal (Map Text (Val a) -> Context a
forall a. Map Text (Val a) -> Context a
Context (Map Text (Val a) -> Context a) -> Map Text (Val a) -> Context a
forall a b. (a -> b) -> a -> b
$ (Val a -> Val a) -> Map Text (Val a) -> Map Text (Val a)
forall a b k. (a -> b) -> Map k a -> Map k b
M.map ((Doc a -> Doc a) -> Val a -> Val a
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         -> [Val a] -> Val a
forall a. [Val a] -> Val a
ListVal ([Val a] -> Val a) -> [Val a] -> Val a
forall a b. (a -> b) -> a -> b
$ (Val a -> Val a) -> [Val a] -> [Val a]
forall a b. (a -> b) -> [a] -> [b]
map ((Doc a -> Doc a) -> Val a -> Val a
forall a. TemplateTarget a => (Doc a -> Doc a) -> Val a -> Val a
mapDoc Doc a -> Doc a
f) [Val a]
xs
    BoolVal Bool
b          -> Bool -> Val a
forall a. Bool -> Val a
BoolVal Bool
b
    Val a
NullVal            -> Val a
forall a. Val a
NullVal

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

applyPipe :: TemplateTarget a => Pipe -> Val a -> Val a
applyPipe :: Pipe -> Val a -> Val a
applyPipe Pipe
ToLength Val a
val = Doc a -> Val a
forall a. Doc a -> Val a
SimpleVal (Doc a -> Val a) -> Doc a -> Val a
forall a b. (a -> b) -> a -> b
$ String -> Doc a
forall a. IsString a => String -> a
fromString (String -> Doc a) -> (Int -> String) -> Int -> Doc a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String
forall a. Show a => a -> String
show (Int -> Doc a) -> Int -> Doc a
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 (Text -> Int) -> (a -> Text) -> a -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Text
forall a. ToText a => a -> Text
toText (a -> Int) -> a -> Int
forall a b. (a -> b) -> a -> b
$ Maybe Int -> Doc a -> a
forall a. HasChars a => Maybe Int -> Doc a -> a
DL.render Maybe Int
forall a. Maybe a
Nothing Doc a
d
           MapVal (Context Map Text (Val a)
m) -> Map Text (Val a) -> Int
forall k a. Map k a -> Int
M.size Map Text (Val a)
m
           ListVal [Val a]
xs         -> [Val a] -> Int
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 = (Text -> Text) -> Val a -> Val a
forall a. TemplateTarget a => (Text -> Text) -> Val a -> Val a
mapText Text -> Text
T.toUpper Val a
val
applyPipe Pipe
ToLowercase Val a
val = (Text -> Text) -> Val a -> Val a
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) ->
      [Val a] -> Val a
forall a. [Val a] -> Val a
ListVal ([Val a] -> Val a) -> [Val a] -> Val a
forall a b. (a -> b) -> a -> b
$ ((Text, Val a) -> Val a) -> [(Text, Val a)] -> [Val a]
forall a b. (a -> b) -> [a] -> [b]
map (Text, Val a) -> Val a
forall a. HasChars a => (Text, Val a) -> Val a
toPair ([(Text, Val a)] -> [Val a]) -> [(Text, Val a)] -> [Val a]
forall a b. (a -> b) -> a -> b
$ Map Text (Val a) -> [(Text, Val a)]
forall k a. Map k a -> [(k, a)]
M.toList Map Text (Val a)
m
    ListVal [Val a]
xs         ->
      [Val a] -> Val a
forall a. [Val a] -> Val a
ListVal ([Val a] -> Val a) -> [Val a] -> Val a
forall a b. (a -> b) -> a -> b
$ ((Text, Val a) -> Val a) -> [(Text, Val a)] -> [Val a]
forall a b. (a -> b) -> [a] -> [b]
map (Text, Val a) -> Val a
forall a. HasChars a => (Text, Val a) -> Val a
toPair ([(Text, Val a)] -> [Val a]) -> [(Text, Val a)] -> [Val a]
forall a b. (a -> b) -> a -> b
$ [Text] -> [Val a] -> [(Text, Val a)]
forall a b. [a] -> [b] -> [(a, b)]
zip ((Int -> Text) -> [Int] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (String -> Text
forall a. IsString a => String -> a
fromString (String -> Text) -> (Int -> String) -> Int -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String
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) = Context a -> Val a
forall a. Context a -> Val a
MapVal (Context a -> Val a) -> Context a -> Val a
forall a b. (a -> b) -> a -> b
$ Map Text (Val a) -> Context a
forall a. Map Text (Val a) -> Context a
Context (Map Text (Val a) -> Context a) -> Map Text (Val a) -> Context a
forall a b. (a -> b) -> a -> b
$ [(Text, Val a)] -> Map Text (Val a)
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
                    [ (Text
"key", Doc a -> Val a
forall a. Doc a -> Val a
SimpleVal (Doc a -> Val a) -> Doc a -> Val a
forall a b. (a -> b) -> a -> b
$ String -> Doc a
forall a. IsString a => String -> a
fromString (String -> Doc a) -> (Text -> String) -> Text -> Doc a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
T.unpack (Text -> Doc a) -> Text -> Doc a
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]
_) -> [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) -> [Val a] -> Val a
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]
_) -> [Val a] -> Val a
forall a. [Val a] -> Val a
ListVal ([Val a] -> [Val a]
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  -> [Val a] -> Val a
forall a. [Val a] -> Val a
ListVal ([Val a] -> [Val a]
forall a. [a] -> [a]
reverse [Val a]
xs)
    SimpleVal{} -> (Text -> Text) -> Val a -> Val a
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 = (Doc a -> Doc a) -> Val a -> Val a
forall a. TemplateTarget a => (Doc a -> Doc a) -> Val a -> Val a
mapDoc Doc a -> Doc a
forall a. Doc a -> Doc a
DL.chomp Val a
val
applyPipe Pipe
ToAlpha Val a
val = (Text -> Text) -> Val a -> Val a
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 Reader Int
forall a. Integral a => Reader a
T.decimal Text
t of
            Right (Int
y,Text
"") -> String -> Text
forall a. IsString a => String -> a
fromString [Int -> Char
chr (Char -> Int
ord Char
'a' Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (Int
y Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` Int
26) Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)]
            Either String (Int, Text)
_            -> Text
t
applyPipe Pipe
ToRoman Val a
val = (Text -> Text) -> Val a -> Val a
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 Reader Int
forall a. Integral a => Reader a
T.decimal Text
t of
           Right (Int
y,Text
"") -> Text -> Maybe Text -> 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 = (Doc a -> Doc a) -> Val a -> Val a
forall a. TemplateTarget a => (Doc a -> Doc a) -> Val a -> Val a
mapDoc Doc a -> Doc a
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  -> Int -> Doc a -> Doc a
forall a. HasChars a => Int -> Doc a -> Doc a
DL.lblock
                      Alignment
Centered     -> Int -> Doc a -> Doc a
forall a. HasChars a => Int -> Doc a -> Doc a
DL.cblock
                      Alignment
RightAligned -> Int -> Doc a -> Doc a
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 Doc a
forall a. Monoid a => a
mempty
                      else a -> Doc a
forall a. HasChars a => a -> Doc a
DL.vfill (Text -> a
forall a. FromText a => Text -> a
fromText Text
y)
  in case Val a -> Val a
forall a. Monoid a => Val a -> Val a
nullToSimple Val a
val of
       SimpleVal Doc a
d -> Doc a -> Val a
forall a. Doc a -> Val a
SimpleVal (Doc a -> Val a) -> Doc a -> Val a
forall a b. (a -> b) -> a -> b
$
                        Text -> Doc a
forall a. (HasChars a, FromText a) => Text -> Doc a
toBorder (Border -> Text
borderLeft Border
border) Doc a -> Doc a -> Doc a
forall a. Semigroup a => a -> a -> a
<>
                        Int -> Doc a -> Doc a
constructor Int
n Doc a
d Doc a -> Doc a -> Doc a
forall a. Semigroup a => a -> a -> a
<>
                        Text -> Doc 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 :: Val a -> Val a
nullToSimple Val a
NullVal = Doc a -> Val a
forall a. Doc a -> Val a
SimpleVal Doc a
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 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
1000
  , Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
4000  = (Text
"m" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>) (Text -> Text) -> Maybe Text -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Maybe Text
toRoman (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1000)
  | Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
900  = (Text
"cm" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>) (Text -> Text) -> Maybe Text -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Maybe Text
toRoman (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
900)
  | Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
500  = (Text
"d" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>) (Text -> Text) -> Maybe Text -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Maybe Text
toRoman (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
500)
  | Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
400  = (Text
"cd" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>) (Text -> Text) -> Maybe Text -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Maybe Text
toRoman (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
400)
  | Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
100  = (Text
"c" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>) (Text -> Text) -> Maybe Text -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Maybe Text
toRoman (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
100)
  | Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
90   = (Text
"xc" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>) (Text -> Text) -> Maybe Text -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Maybe Text
toRoman (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
90)
  | Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
50   = (Text
"l" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>) (Text -> Text) -> Maybe Text -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Maybe Text
toRoman (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
50)
  | Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
40   = (Text
"xl" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>) (Text -> Text) -> Maybe Text -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Maybe Text
toRoman (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
40)
  | Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
10   = (Text
"x" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>) (Text -> Text) -> Maybe Text -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Maybe Text
toRoman (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
10)
  | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
9    = Text -> Maybe Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"ix"
  | Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
5    = (Text
"v" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>) (Text -> Text) -> Maybe Text -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Maybe Text
toRoman (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
5)
  | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
4    = Text -> Maybe Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"iv"
  | Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
1    = (Text
"i" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>) (Text -> Text) -> Maybe Text -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Maybe Text
toRoman (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
  | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0    = Text -> Maybe Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
""
  | Bool
otherwise = Maybe Text
forall a. Maybe a
Nothing

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

multiLookup :: TemplateTarget a => [Text] -> Val a -> Val a
multiLookup :: [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 Text -> Map Text (Val a) -> Maybe (Val a)
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 -> Val a
forall a. Val a
NullVal
    Just Val a
v' -> [Text] -> Val a -> Val a
forall a. TemplateTarget a => [Text] -> Val a -> Val a
multiLookup [Text]
vs Val a
v'
multiLookup [Text]
_ Val a
_ = 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
[Resolved a] -> ShowS
Resolved a -> String
(Int -> Resolved a -> ShowS)
-> (Resolved a -> String)
-> ([Resolved a] -> ShowS)
-> Show (Resolved a)
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)
Int -> ReadS (Resolved a)
ReadS [Resolved a]
(Int -> ReadS (Resolved a))
-> ReadS [Resolved a]
-> ReadPrec (Resolved a)
-> ReadPrec [Resolved a]
-> Read (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, Typeable (Resolved a)
DataType
Constr
Typeable (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 (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Resolved a))
-> (Resolved a -> Constr)
-> (Resolved a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (Resolved a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (Resolved a)))
-> ((forall b. Data b => b -> b) -> Resolved a -> Resolved a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Resolved a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Resolved a -> r)
-> (forall u. (forall d. Data d => d -> u) -> Resolved a -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> Resolved a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Resolved a -> m (Resolved a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Resolved a -> m (Resolved a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Resolved a -> m (Resolved a))
-> Data (Resolved a)
Resolved a -> DataType
Resolved a -> Constr
(forall d. Data d => c (t d)) -> Maybe (c (Resolved a))
(forall b. Data b => b -> b) -> Resolved a -> Resolved a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Resolved a -> c (Resolved a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Resolved a)
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 u. Int -> (forall d. Data d => d -> u) -> Resolved a -> u
forall u. (forall d. Data d => d -> u) -> Resolved a -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Resolved a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Resolved a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Resolved a -> m (Resolved a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Resolved a -> m (Resolved 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))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Resolved a))
$cResolved :: Constr
$tResolved :: DataType
gmapMo :: (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 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 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 :: 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 d. Data d => d -> u) -> Resolved a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> Resolved a -> [u]
gmapQr :: (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 :: (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 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 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 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 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)
$cp1Data :: forall a. Data a => Typeable (Resolved a)
Data, Typeable, (forall x. Resolved a -> Rep (Resolved a) x)
-> (forall x. Rep (Resolved a) x -> Resolved a)
-> Generic (Resolved a)
forall x. Rep (Resolved a) x -> Resolved a
forall x. Resolved a -> Rep (Resolved a) x
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
(Resolved a -> Resolved a -> Bool)
-> (Resolved a -> Resolved a -> Bool) -> Eq (Resolved a)
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, Eq (Resolved a)
Eq (Resolved a)
-> (Resolved a -> Resolved a -> Ordering)
-> (Resolved a -> Resolved a -> Bool)
-> (Resolved a -> Resolved a -> Bool)
-> (Resolved a -> Resolved a -> Bool)
-> (Resolved a -> Resolved a -> Bool)
-> (Resolved a -> Resolved a -> Resolved a)
-> (Resolved a -> Resolved a -> Resolved a)
-> Ord (Resolved a)
Resolved a -> Resolved a -> Bool
Resolved a -> Resolved a -> Ordering
Resolved a -> Resolved a -> Resolved a
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
$cp1Ord :: forall a. Ord a => Eq (Resolved a)
Ord,
             Resolved a -> Bool
(a -> m) -> Resolved a -> m
(a -> b -> b) -> b -> Resolved a -> b
(forall m. Monoid m => Resolved m -> m)
-> (forall m a. Monoid m => (a -> m) -> Resolved a -> m)
-> (forall m a. Monoid m => (a -> m) -> Resolved a -> m)
-> (forall a b. (a -> b -> b) -> b -> Resolved a -> b)
-> (forall a b. (a -> b -> b) -> b -> Resolved a -> b)
-> (forall b a. (b -> a -> b) -> b -> Resolved a -> b)
-> (forall b a. (b -> a -> b) -> b -> Resolved a -> b)
-> (forall a. (a -> a -> a) -> Resolved a -> a)
-> (forall a. (a -> a -> a) -> Resolved a -> a)
-> (forall a. Resolved a -> [a])
-> (forall a. Resolved a -> Bool)
-> (forall a. Resolved a -> Int)
-> (forall a. Eq a => a -> Resolved a -> Bool)
-> (forall a. Ord a => Resolved a -> a)
-> (forall a. Ord a => Resolved a -> a)
-> (forall a. Num a => Resolved a -> a)
-> (forall a. Num a => Resolved a -> a)
-> Foldable Resolved
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 :: Resolved a -> a
$cproduct :: forall a. Num a => Resolved a -> a
sum :: Resolved a -> a
$csum :: forall a. Num a => Resolved a -> a
minimum :: Resolved a -> a
$cminimum :: forall a. Ord a => Resolved a -> a
maximum :: Resolved a -> a
$cmaximum :: forall a. Ord a => Resolved a -> a
elem :: a -> Resolved a -> Bool
$celem :: forall a. Eq a => a -> Resolved a -> Bool
length :: Resolved a -> Int
$clength :: forall a. Resolved a -> Int
null :: Resolved a -> Bool
$cnull :: forall a. Resolved a -> Bool
toList :: Resolved a -> [a]
$ctoList :: forall a. Resolved a -> [a]
foldl1 :: (a -> a -> a) -> Resolved a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Resolved a -> a
foldr1 :: (a -> a -> a) -> Resolved a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Resolved a -> a
foldl' :: (b -> a -> b) -> b -> Resolved a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Resolved a -> b
foldl :: (b -> a -> b) -> b -> Resolved a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Resolved a -> b
foldr' :: (a -> b -> b) -> b -> Resolved a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Resolved a -> b
foldr :: (a -> b -> b) -> b -> Resolved a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Resolved a -> b
foldMap' :: (a -> m) -> Resolved a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Resolved a -> m
foldMap :: (a -> m) -> Resolved a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Resolved a -> m
fold :: Resolved m -> m
$cfold :: forall m. Monoid m => Resolved m -> m
Foldable, Functor Resolved
Foldable Resolved
Functor Resolved
-> Foldable Resolved
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> Resolved a -> f (Resolved b))
-> (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 (m :: * -> *) a.
    Monad m =>
    Resolved (m a) -> m (Resolved a))
-> Traversable Resolved
(a -> f b) -> Resolved a -> f (Resolved b)
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 :: Resolved (m a) -> m (Resolved a)
$csequence :: forall (m :: * -> *) a. Monad m => Resolved (m a) -> m (Resolved a)
mapM :: (a -> m b) -> Resolved a -> m (Resolved b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Resolved a -> m (Resolved b)
sequenceA :: Resolved (f a) -> f (Resolved a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
Resolved (f a) -> f (Resolved a)
traverse :: (a -> f b) -> Resolved a -> f (Resolved b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Resolved a -> f (Resolved b)
$cp2Traversable :: Foldable Resolved
$cp1Traversable :: Functor Resolved
Traversable, a -> Resolved b -> Resolved a
(a -> b) -> Resolved a -> Resolved b
(forall a b. (a -> b) -> Resolved a -> Resolved b)
-> (forall a b. a -> Resolved b -> Resolved a) -> Functor Resolved
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
<$ :: a -> Resolved b -> Resolved a
$c<$ :: forall a b. a -> Resolved b -> Resolved a
fmap :: (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 = Bool -> [Doc a] -> Resolved a
forall a. Bool -> [Doc a] -> Resolved a
Resolved (Bool
b1 Bool -> Bool -> Bool
|| Bool
b2) ([Doc a]
x1 [Doc a] -> [Doc a] -> [Doc a]
forall a. Semigroup a => a -> a -> a
<> [Doc a]
x2)

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

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

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

removeFinalNl :: Doc a -> Doc a
removeFinalNl :: Doc a -> Doc a
removeFinalNl Doc a
DL.NewLine        = Doc a
forall a. Monoid a => a
mempty
removeFinalNl Doc a
DL.CarriageReturn = Doc a
forall a. Monoid a => a
mempty
removeFinalNl (DL.Concat Doc a
d1 Doc a
d2) = Doc a
d1 Doc a -> Doc a -> Doc a
forall a. Semigroup a => a -> a -> a
<> Doc a -> Doc 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 :: Variable -> Context a -> (Context a -> m (Doc a)) -> m [Doc a]
withVariable Variable
var Context a
ctx Context a -> m (Doc a)
f =
  case [Pipe] -> Val a -> Val a
forall a. TemplateTarget a => [Pipe] -> Val a -> Val a
applyPipes (Variable -> [Pipe]
varPipes Variable
var) (Val a -> Val a) -> Val a -> Val a
forall a b. (a -> b) -> a -> b
$ [Text] -> Val a -> Val a
forall a. TemplateTarget a => [Text] -> Val a -> Val a
multiLookup (Variable -> [Text]
varParts Variable
var) (Context a -> Val a
forall a. Context a -> Val a
MapVal Context a
ctx) of
    Val a
NullVal     -> [Doc a] -> m [Doc a]
forall (m :: * -> *) a. Monad m => a -> m a
return [Doc a]
forall a. Monoid a => a
mempty
    ListVal [Val a]
xs  -> (Val a -> m (Doc a)) -> [Val a] -> m [Doc a]
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 (Context a -> m (Doc a)) -> Context a -> m (Doc a)
forall a b. (a -> b) -> a -> b
$ Val a -> Context a
setVarVal Val a
iterval) [Val a]
xs
    MapVal Context a
ctx' -> (Doc a -> [Doc a] -> [Doc a]
forall a. a -> [a] -> [a]
:[]) (Doc a -> [Doc a]) -> m (Doc a) -> m [Doc a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Context a -> m (Doc a)
f (Val a -> Context a
setVarVal (Context a -> Val a
forall a. Context a -> Val a
MapVal Context a
ctx'))
    Val a
val' -> (Doc a -> [Doc a] -> [Doc a]
forall a. a -> [a] -> [a]
:[]) (Doc a -> [Doc a]) -> m (Doc a) -> m [Doc 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 =
    Variable -> Val a -> Context a -> Context a
forall a. Variable -> Val a -> Context a -> Context a
addToContext Variable
var Val a
x (Context a -> Context a) -> Context a -> Context a
forall a b. (a -> b) -> a -> b
$ Map Text (Val a) -> Context a
forall a. Map Text (Val a) -> Context a
Context (Map Text (Val a) -> Context a) -> Map Text (Val a) -> Context a
forall a b. (a -> b) -> a -> b
$ Text -> Val a -> Map Text (Val a) -> Map Text (Val a)
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Text
"it" Val a
x (Map Text (Val a) -> Map Text (Val a))
-> Map Text (Val a) -> Map Text (Val a)
forall a b. (a -> b) -> a -> b
$ Context a -> Map Text (Val a)
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') = Map Text (Val a) -> Context a
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') =
    Map Text (Val a) -> Context a
forall a. Map Text (Val a) -> Context a
Context (Map Text (Val a) -> Context a) -> Map Text (Val a) -> Context a
forall a b. (a -> b) -> a -> b
$ (Val a -> Val a) -> Text -> Map Text (Val a) -> Map Text (Val a)
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
_ | [Text] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Text]
vs -> Val a
x
                       MapVal Context a
m    ->
                         Context a -> Val a
forall a. Context a -> Val a
MapVal (Context a -> Val a) -> Context a -> Val a
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 :: Template a -> b -> Doc a
renderTemplate Template a
t b
x = State Int (Doc a) -> Int -> Doc a
forall s a. State s a -> s -> a
S.evalState (Template a -> Context a -> State Int (Doc a)
forall a.
TemplateTarget a =>
Template a -> Context a -> RenderState (Doc a)
renderTemp Template a
t (b -> Context a
forall a b. ToContext a b => b -> Context a
toContext b
x)) Int
0

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

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