simplifier

package
v0.0.0-...-bb0b385 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2017 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsUsingDot

func IsUsingDot(tree *parse.Tree) bool

IsUsingDot tells if a template tree consumes a dot value.

func PrintsAnything

func PrintsAnything(tree *parse.Tree) bool

PrintsAnything tells if a template tree prints anything.

func Simplify

func Simplify(tree *parse.Tree)

Simplify browse the tree nodes to reduce its complexity.

func Transform

func Transform(some interface{}, data interface{}, funcs map[string]interface{})

Transform fully simplify a template. it accepts *text.Template or *html.Template, it panics if the value type is unexpected.

func Unhole

func Unhole(tree *parse.Tree, state *State, funcs map[string]interface{})

Unhole process the tree until no more type holes subsist in the tree. a type hole being an interface{} value found inside a property path. Exemple: there is a call such a.b.c.d if b is an interface{} value, there is no way to statically type check the subsequent c.d path, it can only be done at runtime via reflection. This process will solve that problem by identifying such situation and isolate type checkable and type uncheckable parts. so such node {{a.b.c.d}} will become {{browsePropertyPath a.b "c.d"}}. Where browsePropertyPath is a new identifier (func of funcmap). Note1: the case may occur with variable/identifier nodes too, lets imagine {{$z := a}}{{$z.b.c.d}} Note2: this will work only after simplify occured

func Unshadow

func Unshadow(tree *parse.Tree)

Unshadow process the tree until no more variable is shadowed.

Types

type State

type State struct {
	// contains filtered or unexported fields
}

State ...

func TransformTree

func TransformTree(tree *parse.Tree, data interface{}, funcs map[string]interface{}) *State

TransformTree fully simplify a template Tree.

func TypeCheck

func TypeCheck(tree *parse.Tree, data interface{}, funcs map[string]interface{}) *State

TypeCheck browses the tree to identify variable types.

func (*State) Add

func (s *State) Add()

Add a new scope level.

func (*State) AddVar

func (s *State) AddVar(name string, r reflect.Type)

AddVar in the current scope level.

func (*State) BrowsePathType

func (s *State) BrowsePathType(path []string, val reflect.Type) reflect.Type

BrowsePathType ...

func (*State) Current

func (s *State) Current() map[string]reflect.Type

Current scope vars.

func (*State) Dot

func (s *State) Dot() reflect.Type

Dot is the current scope dot.

func (*State) Enter

func (s *State) Enter()

Enter into a scope level.

func (*State) FindVar

func (s *State) FindVar(name string) reflect.Type

FindVar starting from current scope level to the root.

func (*State) GetVar

func (s *State) GetVar(name string) reflect.Type

GetVar get a variable in current scope.

func (*State) HasVar

func (s *State) HasVar(name string) bool

HasVar tells if current level contains given variable name.

func (*State) IsMethodPath

func (s *State) IsMethodPath(path []string, val reflect.Type) bool

IsMethodPath ...

func (*State) Leave

func (s *State) Leave()

Leave a scope level.

func (*State) Len

func (s *State) Len() int

Len returns the number of scopes.

func (*State) Level

func (s *State) Level() int

Level returns the current scope level.

func (*State) ReflectPath

func (s *State) ReflectPath(path []string, val reflect.Type) reflect.Type

ReflectPath ...

func (*State) Root

func (s *State) Root() map[string]reflect.Type

Root scope vars.

func (*State) RootDot

func (s *State) RootDot() reflect.Type

RootDot is the root scope dot.

Jump to

Keyboard shortcuts

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