ginger-0.7.2.0: An implementation of the Jinja2 template language in Haskell

Safe HaskellNone
LanguageHaskell2010

Text.Ginger.AST

Description

Implements Ginger's Abstract Syntax Tree.

Synopsis

Documentation

type VarName = Text Source #

A context variable name.

data Template a Source #

Top-level data structure, representing a fully parsed template.

Instances

Functor Template Source # 

Methods

fmap :: (a -> b) -> Template a -> Template b #

(<$) :: a -> Template b -> Template a #

Annotated Template Source # 

Methods

annotation :: Template p -> p Source #

Show a => Show (Template a) Source # 

Methods

showsPrec :: Int -> Template a -> ShowS #

show :: Template a -> String #

showList :: [Template a] -> ShowS #

Optimizable (Template a) Source # 

Methods

optimize :: Template a -> Template a Source #

data Macro a Source #

A macro definition ( {% macro %} )

Constructors

Macro 

Instances

Functor Macro Source # 

Methods

fmap :: (a -> b) -> Macro a -> Macro b #

(<$) :: a -> Macro b -> Macro a #

Annotated Macro Source # 

Methods

annotation :: Macro p -> p Source #

Show a => Show (Macro a) Source # 

Methods

showsPrec :: Int -> Macro a -> ShowS #

show :: Macro a -> String #

showList :: [Macro a] -> ShowS #

Optimizable (Macro a) Source # 

Methods

optimize :: Macro a -> Macro a Source #

data Block a Source #

A block definition ( {% block %} )

Constructors

Block 

Fields

Instances

Functor Block Source # 

Methods

fmap :: (a -> b) -> Block a -> Block b #

(<$) :: a -> Block b -> Block a #

Annotated Block Source # 

Methods

annotation :: Block p -> p Source #

Show a => Show (Block a) Source # 

Methods

showsPrec :: Int -> Block a -> ShowS #

show :: Block a -> String #

showList :: [Block a] -> ShowS #

Optimizable (Block a) Source # 

Methods

optimize :: Block a -> Block a Source #

data Statement a Source #

Ginger statements.

Constructors

MultiS a [Statement a]

A sequence of multiple statements

ScopedS a (Statement a)

Run wrapped statement in a local scope

IndentS a (Expression a) (Statement a)

Establish an indented context around the wrapped statement

LiteralS a Html

Literal output (anything outside of any tag)

InterpolationS a (Expression a)

{{ expression }}

ExpressionS a (Expression a)

Evaluate expression

IfS a (Expression a) (Statement a) (Statement a)

{% if expression %}statement{% else %}statement{% endif %}

SwitchS a (Expression a) [(Expression a, Statement a)] (Statement a)

{% switch expression %}{% case expression %}statement{% endcase %}...{% default %}statement{% enddefault %}{% endswitch %}

ForS a (Maybe VarName) VarName (Expression a) (Statement a)

{% for index, varname in expression %}statement{% endfor %}

SetVarS a VarName (Expression a)

{% set varname = expr %}

DefMacroS a VarName (Macro a)

{% macro varname %}statements{% endmacro %}

BlockRefS a VarName 
PreprocessedIncludeS a (Template a)

{% include "template" %}

NullS a

The do-nothing statement (NOP)

TryCatchS a (Statement a) [CatchBlock a] (Statement a)

Try catch finally

Instances

data CatchBlock a Source #

A catch block

Instances

Functor CatchBlock Source # 

Methods

fmap :: (a -> b) -> CatchBlock a -> CatchBlock b #

(<$) :: a -> CatchBlock b -> CatchBlock a #

Show a => Show (CatchBlock a) Source # 

data Expression a Source #

Expressions, building blocks for the expression minilanguage.

Constructors

StringLiteralE a Text

String literal expression: "foobar"

NumberLiteralE a Scientific

Numeric literal expression: 123.4

BoolLiteralE a Bool

Boolean literal expression: true

NullLiteralE a

Literal null

VarE a VarName

Variable reference: foobar

ListE a [Expression a]

List construct: [ expr, expr, expr ]

ObjectE a [(Expression a, Expression a)]

Object construct: { expr: expr, expr: expr, ... }

MemberLookupE a (Expression a) (Expression a)

foo[bar] (also dot access)

CallE a (Expression a) [(Maybe Text, Expression a)]

foo(bar=baz, quux)

LambdaE a [Text] (Expression a)

(foo, bar) -> expr

TernaryE a (Expression a) (Expression a) (Expression a)

expr ? expr : expr

DoE a (Statement a)

do { statement; }

class Annotated f where Source #

Minimal complete definition

annotation

Methods

annotation :: f p -> p Source #