-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | A basic template language for the Simple web framework
--   
--   A basic template language for the Simple web framework. The language
--   supports variable substitution, function invokation, loops and
--   conditionals.
--   
--   <a>Web.Simple.Templates</a> documents how to integrate into an app,
--   while <a>Web.Simple.Templates.Language</a> documents the templating
--   language syntax and semantics.
@package simple-templates
@version 0.9.0.0


-- | Types and helpers to encode the language AST
module Web.Simple.Templates.Types

-- | A funcation that's callable from inside a template
newtype Function
Function :: ([Value] -> Value) -> Function
[call] :: Function -> [Value] -> Value
class ToFunction a
toFunction :: ToFunction a => a -> Function

-- | Like <a>fromJSON</a> but throws an error if there is a parse failure.
fromJSONStrict :: FromJSON a => Value -> a
type FunctionMap = HashMap Identifier Function

-- | A compiled template is a function that takes a <a>FunctionMap</a> and
--   a global aeson <a>Value</a> and renders the template.
newtype Template
Template :: (FunctionMap -> Value -> Text) -> Template
[renderTemplate] :: Template -> FunctionMap -> Value -> Text

-- | A symbol identifier following the format [a-z][a-zA-Z0-9_-]*
type Identifier = Text

-- | <a>AST</a>s encode the various types of expressions in the language.
data AST

-- | A series of sub-ASTs
ASTRoot :: [AST] -> AST

-- | A literal that does not require evaluation
ASTLiteral :: Value -> AST

-- | A function call and list of arguments
ASTFunc :: Identifier -> [AST] -> AST

-- | Variable dereference
ASTVar :: Identifier -> AST

-- | Nested index into an object
ASTIndex :: AST -> [Identifier] -> AST

-- | A literal array (may contain non-literals)
ASTArray :: Vector AST -> AST

-- | If - condition, true branch and optional false branch
ASTIf :: AST -> AST -> Maybe AST -> AST

-- | for([k,]v in expr) body separator
ASTFor :: Maybe Identifier -> Identifier -> AST -> AST -> Maybe AST -> AST

-- | Lift a <a>ToJSON</a> to an <a>ASTLiteral</a>
fromLiteral :: ToJSON a => a -> AST
astListToArray :: [AST] -> AST
instance GHC.Classes.Eq Web.Simple.Templates.Types.AST
instance GHC.Show.Show Web.Simple.Templates.Types.AST
instance GHC.Base.Semigroup Web.Simple.Templates.Types.Template
instance GHC.Base.Monoid Web.Simple.Templates.Types.Template
instance Data.Aeson.Types.FromJSON.FromJSON a => Web.Simple.Templates.Types.ToFunction (a -> Data.Aeson.Types.Internal.Value)
instance (Data.Aeson.Types.FromJSON.FromJSON a1, Data.Aeson.Types.FromJSON.FromJSON a2) => Web.Simple.Templates.Types.ToFunction (a1 -> a2 -> Data.Aeson.Types.Internal.Value)
instance (Data.Aeson.Types.FromJSON.FromJSON a1, Data.Aeson.Types.FromJSON.FromJSON a2, Data.Aeson.Types.FromJSON.FromJSON a3) => Web.Simple.Templates.Types.ToFunction (a1 -> a2 -> a3 -> Data.Aeson.Types.Internal.Value)
instance (Data.Aeson.Types.FromJSON.FromJSON a1, Data.Aeson.Types.FromJSON.FromJSON a2, Data.Aeson.Types.FromJSON.FromJSON a3, Data.Aeson.Types.FromJSON.FromJSON a4) => Web.Simple.Templates.Types.ToFunction (a1 -> a2 -> a3 -> a4 -> Data.Aeson.Types.Internal.Value)
instance (Data.Aeson.Types.FromJSON.FromJSON a1, Data.Aeson.Types.FromJSON.FromJSON a2, Data.Aeson.Types.FromJSON.FromJSON a3, Data.Aeson.Types.FromJSON.FromJSON a4, Data.Aeson.Types.FromJSON.FromJSON a5) => Web.Simple.Templates.Types.ToFunction (a1 -> a2 -> a3 -> a4 -> a5 -> Data.Aeson.Types.Internal.Value)
instance (Data.Aeson.Types.FromJSON.FromJSON a1, Data.Aeson.Types.FromJSON.FromJSON a2, Data.Aeson.Types.FromJSON.FromJSON a3, Data.Aeson.Types.FromJSON.FromJSON a4, Data.Aeson.Types.FromJSON.FromJSON a5, Data.Aeson.Types.FromJSON.FromJSON a6) => Web.Simple.Templates.Types.ToFunction (a1 -> a2 -> a3 -> a4 -> a5 -> a6 -> Data.Aeson.Types.Internal.Value)
instance (Data.Aeson.Types.FromJSON.FromJSON a1, Data.Aeson.Types.FromJSON.FromJSON a2, Data.Aeson.Types.FromJSON.FromJSON a3, Data.Aeson.Types.FromJSON.FromJSON a4, Data.Aeson.Types.FromJSON.FromJSON a5, Data.Aeson.Types.FromJSON.FromJSON a6, Data.Aeson.Types.FromJSON.FromJSON a7) => Web.Simple.Templates.Types.ToFunction (a1 -> a2 -> a3 -> a4 -> a5 -> a6 -> a7 -> Data.Aeson.Types.Internal.Value)
instance (Data.Aeson.Types.FromJSON.FromJSON a1, Data.Aeson.Types.FromJSON.FromJSON a2, Data.Aeson.Types.FromJSON.FromJSON a3, Data.Aeson.Types.FromJSON.FromJSON a4, Data.Aeson.Types.FromJSON.FromJSON a5, Data.Aeson.Types.FromJSON.FromJSON a6, Data.Aeson.Types.FromJSON.FromJSON a7, Data.Aeson.Types.FromJSON.FromJSON a8) => Web.Simple.Templates.Types.ToFunction (a1 -> a2 -> a3 -> a4 -> a5 -> a6 -> a7 -> a8 -> Data.Aeson.Types.Internal.Value)


-- | Language parser
module Web.Simple.Templates.Parser

-- | Reserved words: for, endfor, sep, if, else, endif, true, false
reservedWords :: [Text]

-- | Parse an AST
pAST :: Parser AST
pRaw :: Parser AST
pEscapedDollar :: Parser Text
pEscapedExpr :: Parser AST

-- | Anything that can be evaluated: for, if or value
pExpr :: Parser AST
pIf :: Parser AST
pFor :: Parser AST
pFunc :: Parser AST

-- | A variable, function call, literal, etc
pValue :: Parser AST
pVar :: Parser AST
pIndex :: Parser AST
pIdentifier :: Parser Identifier
pLiteral :: Parser AST
pNull :: Parser AST
pBoolean :: Parser AST
pString :: Parser AST
pNumber :: Parser AST
pArray :: Parser AST


-- | A simple templating system with variable substitution, function
--   invokation, for loops and conditionals. Most callers should use
--   <a>compileTemplate</a> and invoke the template with
--   <a>renderTemplate</a>. E.g.:
--   
--   <pre>
--   let myTemplate = compileTemplate "Hello, $@$!"
--   print $ renderTemplate myTemplate mempty "World"
--   </pre>
module Web.Simple.Templates.Language
compileTemplate :: Text -> Either String Template
evaluate :: AST -> Template
evaluateAST :: FunctionMap -> Value -> AST -> Value
valueToText :: Value -> Text
replaceVar :: Value -> Identifier -> Value -> Value
