nodes

package
v2.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2024 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

View Source
const (
	VarTypeInt = iota
	VarTypeIdent
)

Variables

This section is empty.

Functions

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

Types

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.john-doe.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
	Parent   Node
	Kwargs   map[string]Expression
}

func (*Call) Position

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

func (*Call) String

func (c *Call) String() string

type Comment

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

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

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 ControlStructure

type ControlStructure interface {
	Node
}

ControlStructure represents a controlStructure block "{% %}"

type ControlStructureBlock

type ControlStructureBlock struct {
	Location         *tokens.Token
	Name             string
	ControlStructure ControlStructure
}

func (ControlStructureBlock) Position

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

func (ControlStructureBlock) String

func (s ControlStructureBlock) String() string

type Data

type Data struct {
	Data                                 *tokens.Token
	Trim                                 Trim
	RemoveFirstLineReturn                bool
	RemoveTrailingWhiteSpaceFromLastLine bool
}

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 Error

type Error struct {
	Location *tokens.Token
	Error    error
}

func (*Error) Position

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

func (*Error) String

func (c *Error) String() string

type Expression

type Expression interface {
	Node
}

Expression represents an evaluable expression part

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 GetAttribute

type GetAttribute struct {
	Location  *tokens.Token
	Node      Node
	Attribute string
	Index     int
}

func (*GetAttribute) Position

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

func (*GetAttribute) String

func (g *GetAttribute) String() string

type GetItem

type GetItem struct {
	Location *tokens.Token
	Node     Node
	Arg      Node
}

func (*GetItem) Position

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

func (*GetItem) String

func (g *GetItem) String() string

type GetSlice

type GetSlice struct {
	Location *tokens.Token
	Node     Node
	Start    Node
	End      Node
}

func (*GetSlice) Position

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

func (*GetSlice) String

func (g *GetSlice) 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
	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

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

All node types implement the Node interface.

type None

type None struct {
	Location *tokens.Token
}

func (*None) Position

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

func (*None) String

func (n *None) String() string

type Output

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

Ouput represents a printable expression node {{ }}

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 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

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

Template is the root node of any 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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL