Safe Haskell | Trustworthy |
---|---|
Language | Haskell2010 |
Types and helpers to encode the language AST
Synopsis
- newtype Function = Function {}
- class ToFunction a where
- toFunction :: a -> Function
- fromJSONStrict :: FromJSON a => Value -> a
- type FunctionMap = HashMap Identifier Function
- newtype Template = Template {
- renderTemplate :: FunctionMap -> Value -> Text
- type Identifier = Text
- data AST
- = ASTRoot [AST]
- | ASTLiteral Value
- | ASTFunc Identifier [AST]
- | ASTVar Identifier
- | ASTIndex AST [Identifier]
- | ASTArray (Vector AST)
- | ASTIf AST AST (Maybe AST)
- | ASTFor (Maybe Identifier) Identifier AST AST (Maybe AST)
- fromLiteral :: ToJSON a => a -> AST
- astListToArray :: [AST] -> AST
Documentation
A funcation that's callable from inside a template
class ToFunction a where Source #
toFunction :: a -> Function Source #
Instances
fromJSONStrict :: FromJSON a => Value -> a Source #
Like fromJSON
but throws an error if there is a parse failure.
type FunctionMap = HashMap Identifier Function Source #
A compiled template is a function that takes a FunctionMap
and a global
aeson Value
and renders the template.
Template | |
|
type Identifier = Text Source #
A symbol identifier following the format [a-z][a-zA-Z0-9_-]*
AST
s encode the various types of expressions in the language.
ASTRoot [AST] | A series of sub-ASTs |
ASTLiteral Value | A literal that does not require evaluation |
ASTFunc Identifier [AST] | A function call and list of arguments |
ASTVar Identifier | Variable dereference |
ASTIndex AST [Identifier] | Nested index into an object |
ASTArray (Vector AST) | A literal array (may contain non-literals) |
ASTIf AST AST (Maybe AST) | If - condition, true branch and optional false branch |
ASTFor (Maybe Identifier) Identifier AST AST (Maybe AST) | for([k,]v in expr) body separator |
fromLiteral :: ToJSON a => a -> AST Source #
Lift a ToJSON
to an ASTLiteral
astListToArray :: [AST] -> AST Source #