...

Package nodes

import "github.com/noirbizarre/gonja/nodes"
Overview
Index

Overview ▾

Index ▾

Constants
func Inspect(node Node, f func(Node) bool)
func Walk(v Visitor, node Node) error
type BinOperator
    func (op BinOperator) Position() *tokens.Token
    func (op BinOperator) String() string
type BinaryExpression
    func (b *BinaryExpression) Position() *tokens.Token
    func (expr *BinaryExpression) String() string
type BlockSet
    func (bs BlockSet) Exists(name string) bool
    func (bs *BlockSet) Register(name string, w *Wrapper) error
    func (bs *BlockSet) Replace(name string, w *Wrapper) error
type Bool
    func (b *Bool) Position() *tokens.Token
    func (b *Bool) String() string
type Call
    func (c *Call) Position() *tokens.Token
    func (c *Call) String() string
type Comment
    func (c *Comment) Position() *tokens.Token
    func (c *Comment) String() string
type Data
    func (d *Data) Position() *tokens.Token
    func (c *Data) String() string
type Dict
    func (d *Dict) Position() *tokens.Token
    func (d *Dict) String() string
type Expression
type FilterCall
type FilteredExpression
    func (expr *FilteredExpression) Position() *tokens.Token
    func (expr *FilteredExpression) String() string
type Float
    func (f *Float) Position() *tokens.Token
    func (f *Float) String() string
type Getattr
    func (g *Getattr) Position() *tokens.Token
    func (g *Getattr) String() string
type Getitem
    func (g *Getitem) Position() *tokens.Token
    func (g *Getitem) String() string
type Inspector
    func (f Inspector) Visit(node Node) (Visitor, error)
type Integer
    func (i *Integer) Position() *tokens.Token
    func (i *Integer) String() string
type List
    func (l *List) Position() *tokens.Token
    func (l *List) String() string
type Macro
    func (m *Macro) Position() *tokens.Token
    func (m *Macro) String() string
type Name
    func (n *Name) Position() *tokens.Token
    func (n *Name) String() string
type Negation
    func (n *Negation) Position() *tokens.Token
    func (n *Negation) String() string
type Node
type Output
    func (o *Output) Position() *tokens.Token
    func (o *Output) String() string
type Pair
    func (p *Pair) Position() *tokens.Token
    func (p *Pair) String() string
type Statement
type StatementBlock
    func (s StatementBlock) Position() *tokens.Token
    func (s StatementBlock) String() string
type String
    func (s *String) Position() *tokens.Token
    func (s *String) String() string
type Template
    func (tpl *Template) GetBlocks(name string) []*Wrapper
    func (t *Template) Position() *tokens.Token
    func (t *Template) String() string
type TestCall
    func (tc *TestCall) String() string
type TestExpression
    func (expr *TestExpression) Position() *tokens.Token
    func (expr *TestExpression) String() string
type Trim
type Tuple
    func (t *Tuple) Position() *tokens.Token
    func (t *Tuple) String() string
type UnaryExpression
    func (u *UnaryExpression) Position() *tokens.Token
    func (u *UnaryExpression) String() string
type Variable
    func (v *Variable) Position() *tokens.Token
    func (v *Variable) String() string
type VariablePart
    func (vp *VariablePart) String() string
type Visitor
type Wrapper
    func (w Wrapper) Position() *tokens.Token
    func (w Wrapper) String() string

Package files

nodes.go sets.go walk.go

Constants

const (
    VarTypeInt = iota
    VarTypeIdent
)

func Inspect

func Inspect(node Node, f func(Node) bool)

Inspect traverses an AST in depth-first order: It starts by calling f(node); node must not be nil. If f returns true, Inspect invokes f recursively for each of the non-nil children of node, followed by a call of f(nil).

func Walk

func Walk(v Visitor, node Node) error

type BinOperator

type BinOperator struct {
    Token *tokens.Token
}

func (BinOperator) Position

func (op BinOperator) Position() *tokens.Token

func (BinOperator) String

func (op BinOperator) String() string

type BinaryExpression

type BinaryExpression struct {
    Left     Expression
    Right    Expression
    Operator *BinOperator
}

func (*BinaryExpression) Position

func (b *BinaryExpression) Position() *tokens.Token

func (*BinaryExpression) String

func (expr *BinaryExpression) String() string

type BlockSet

type BlockSet map[string]*Wrapper

func (BlockSet) Exists

func (bs BlockSet) Exists(name string) bool

Exists returns true if the given block is already registered

func (*BlockSet) Register

func (bs *BlockSet) Register(name string, w *Wrapper) error

Register registers a new block. If there's already a filter with the same name, Register will panic. You usually want to call this function in the filter's init() function: http://golang.org/doc/effective_go.html#init

See http://www.florian-schlachter.de/post/gonja/ for more about writing filters and tags.

func (*BlockSet) Replace

func (bs *BlockSet) Replace(name string, w *Wrapper) error

Replace replaces an already registered filter with a new implementation. Use this function with caution since it allobs you to change existing filter behaviour.

type Bool

type Bool struct {
    Location *tokens.Token
    Val      bool
}

func (*Bool) Position

func (b *Bool) Position() *tokens.Token

func (*Bool) String

func (b *Bool) String() string

type Call

type Call struct {
    Location *tokens.Token
    Func     Node
    Args     []Expression
    Kwargs   map[string]Expression
}

func (*Call) Position

func (c *Call) Position() *tokens.Token

func (*Call) String

func (c *Call) String() string

type Comment

A Comment node represents a single {# #} comment.

type Comment struct {
    Start *tokens.Token // Opening token
    Text  string        // Comment text
    End   *tokens.Token // Closing token
    Trim  *Trim
}

func (*Comment) Position

func (c *Comment) Position() *tokens.Token

func (*Comment) String

func (c *Comment) String() string

func (c *Comment) End() token.Pos { return token.Pos(int(c.Slash) + len(c.Text)) }

type Data

type Data struct {
    Data *tokens.Token // data token
}

func (*Data) Position

func (d *Data) Position() *tokens.Token

func (*Data) String

func (c *Data) String() string

func (c *Comment) End() token.Pos { return token.Pos(int(c.Slash) + len(c.Text)) }

type Dict

type Dict struct {
    Token *tokens.Token
    Pairs []*Pair
}

func (*Dict) Position

func (d *Dict) Position() *tokens.Token

func (*Dict) String

func (d *Dict) String() string

type Expression

Expression represents an evaluable expression part

type Expression interface {
    Node
}

type FilterCall

type FilterCall struct {
    Token *tokens.Token

    Name   string
    Args   []Expression
    Kwargs map[string]Expression
}

type FilteredExpression

type FilteredExpression struct {
    Expression Expression
    Filters    []*FilterCall
}

func (*FilteredExpression) Position

func (expr *FilteredExpression) Position() *tokens.Token

func (*FilteredExpression) String

func (expr *FilteredExpression) String() string

type Float

type Float struct {
    Location *tokens.Token
    Val      float64
}

func (*Float) Position

func (f *Float) Position() *tokens.Token

func (*Float) String

func (f *Float) String() string

type Getattr

type Getattr struct {
    Location *tokens.Token
    Node     Node
    Attr     string
    Index    int
}

func (*Getattr) Position

func (g *Getattr) Position() *tokens.Token

func (*Getattr) String

func (g *Getattr) String() string

type Getitem

type Getitem struct {
    Location *tokens.Token
    Node     Node
    Arg      string
    Index    int
}

func (*Getitem) Position

func (g *Getitem) Position() *tokens.Token

func (*Getitem) String

func (g *Getitem) String() string

type Inspector

type Inspector func(Node) bool

func (Inspector) Visit

func (f Inspector) Visit(node Node) (Visitor, error)

type Integer

type Integer struct {
    Location *tokens.Token
    Val      int
}

func (*Integer) Position

func (i *Integer) Position() *tokens.Token

func (*Integer) String

func (i *Integer) String() string

type List

type List struct {
    Location *tokens.Token
    Val      []Expression
}

func (*List) Position

func (l *List) Position() *tokens.Token

func (*List) String

func (l *List) String() string

type Macro

type Macro struct {
    Location *tokens.Token
    Name     string
    Args     []string
    Kwargs   []*Pair
    Wrapper  *Wrapper
}

func (*Macro) Position

func (m *Macro) Position() *tokens.Token

func (*Macro) String

func (m *Macro) String() string

type Name

type Name struct {
    Name *tokens.Token
}

func (*Name) Position

func (n *Name) Position() *tokens.Token

func (*Name) String

func (n *Name) String() string

type Negation

type Negation struct {
    Term     Expression
    Operator *tokens.Token
}

func (*Negation) Position

func (n *Negation) Position() *tokens.Token

func (*Negation) String

func (n *Negation) String() string

type Node

All node types implement the Node interface.

type Node interface {
    fmt.Stringer
    Position() *tokens.Token
}

type Output

Ouput represents a printable expression node {{ }}

type Output struct {
    Start      *tokens.Token
    Expression Expression
    End        *tokens.Token
    Trim       *Trim
}

func (*Output) Position

func (o *Output) Position() *tokens.Token

func (*Output) String

func (o *Output) String() string

type Pair

type Pair struct {
    Key   Expression
    Value Expression
}

func (*Pair) Position

func (p *Pair) Position() *tokens.Token

func (*Pair) String

func (p *Pair) String() string

type Statement

Statement represents a statement block "{% %}"

type Statement interface {
    Node
}

type StatementBlock

type StatementBlock struct {
    Location *tokens.Token
    Name     string
    Stmt     Statement
    Trim     *Trim
    LStrip   bool
}

func (StatementBlock) Position

func (s StatementBlock) Position() *tokens.Token

func (StatementBlock) String

func (s StatementBlock) String() string

type String

type String struct {
    Location *tokens.Token
    Val      string
}

func (*String) Position

func (s *String) Position() *tokens.Token

func (*String) String

func (s *String) String() string

type Template

Template is the root node of any template

type Template struct {
    Name   string
    Nodes  []Node
    Blocks BlockSet
    Macros map[string]*Macro
    Parent *Template
}

func (*Template) GetBlocks

func (tpl *Template) GetBlocks(name string) []*Wrapper

func (*Template) Position

func (t *Template) Position() *tokens.Token

func (*Template) String

func (t *Template) String() string

type TestCall

type TestCall struct {
    Token *tokens.Token

    Name   string
    Args   []Expression
    Kwargs map[string]Expression
}

func (*TestCall) String

func (tc *TestCall) String() string

type TestExpression

type TestExpression struct {
    Expression Expression
    Test       *TestCall
}

func (*TestExpression) Position

func (expr *TestExpression) Position() *tokens.Token

func (*TestExpression) String

func (expr *TestExpression) String() string

type Trim

type Trim struct {
    Left  bool
    Right bool
}

type Tuple

type Tuple struct {
    Location *tokens.Token
    Val      []Expression
}

func (*Tuple) Position

func (t *Tuple) Position() *tokens.Token

func (*Tuple) String

func (t *Tuple) String() string

type UnaryExpression

type UnaryExpression struct {
    Negative bool
    Term     Expression
    Operator *tokens.Token
}

func (*UnaryExpression) Position

func (u *UnaryExpression) Position() *tokens.Token

func (*UnaryExpression) String

func (u *UnaryExpression) String() string

type Variable

type Variable struct {
    Location *tokens.Token

    Parts []*VariablePart
}

func (*Variable) Position

func (v *Variable) Position() *tokens.Token

func (*Variable) String

func (v *Variable) String() string

type VariablePart

type VariablePart struct {
    Type int
    S    string
    I    int

    IsFunctionCall bool
    // callingArgs    []functionCallArgument // needed for a function call, represents all argument nodes (Node supports nested function calls)
    Args   []Expression
    Kwargs map[string]Expression
}

func (*VariablePart) String

func (vp *VariablePart) String() string

type Visitor

type Visitor interface {
    Visit(node Node) (Visitor, error)
}

type Wrapper

type Wrapper struct {
    Location *tokens.Token
    Nodes    []Node
    EndTag   string
    Trim     *Trim
    LStrip   bool
}

func (Wrapper) Position

func (w Wrapper) Position() *tokens.Token

func (Wrapper) String

func (w Wrapper) String() string