Documentation ¶
Overview ¶
Package evaluator is used to evaluate (execute) an abstract syntax tree.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrorLocation ¶
ErrorLocation returns the location in the template where the evaluation error e occurred. ok will be true if e actually was an evaluation error.
func IsEvaluationError ¶
IsEvaluationError returns whether e is an evaluation error that occurred in the evaluator.
Types ¶
type ArgumentResolver ¶
type ArgumentResolver interface { // Resolve inspects the type t and returns a value for it. If no actual value can be produced, nil may be returned // as the value. The returned value must be convertible to the type t. Resolve(t reflect.Type) (interface{}, error) }
An ArgumentResolver resolves additional arguments of methods or functions that should be called. For example, a method could expect the arguments "x int, y *FooBar", but the method call only specifies the first argument: "a.b(123)". In that case, the second *FooBar argument can be automatically resolved by the argument resolver.
type ArgumentResolverFunc ¶
An ArgumentResolverFunc is an adapter type that allows ordinary functions to be used as argument resolvers. If f is a function with the appropriate signature, ArgumentResolverFunc(f) is an argument resolver that calls f.
type Evaluator ¶
type Evaluator struct {
// contains filtered or unexported fields
}
Evaluator evaluates an abstract syntax tree node and returns its result.
type LiteralStringer ¶
A LiteralStringer converts a literal string in a template to a value suitable for output. For example, it can wrap the string in a renderer.SafeString so that all literal strings are output as-is. It may also escape strings before wrapping them.
type LiteralStringerFunc ¶
A LiteralStringerFunc is an adapter type that allows ordinary functions to be used as literal stringers. If f is a function with the appropriate signature, LiteralStringerFunc(f) is a literal stringer that calls f.
func (LiteralStringerFunc) String ¶
func (f LiteralStringerFunc) String(s string) (interface{}, error)
type Opt ¶
type Opt func(ev *Evaluator)
Opt is the type of a function that configures an option of ev.
func WithArgumentResolver ¶
func WithArgumentResolver(r ArgumentResolver) Opt
WithArgumentResolver configures an evaluator to use r to automatically resolve additional arguments of method or function calls in a template. The default is to not resolve any arguments.
WithArgumentResolver may be used multiple times to configure additional resolvers. The first resolver to return a value other than nil wins.
func WithLiteralStringer ¶
func WithLiteralStringer(l LiteralStringer) Opt
WithLiteralStringer configures an evaluator to use l to convert literal strings in a template to values suitable for output. The default is to return strings as-is, without escaping.