asteval

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicLiteralString

func BasicLiteralString(node ast.Node) (string, bool)

func BuildCallSiteIndex

func BuildCallSiteIndex(info *types.Info, files []*ast.File) map[types.Object][]*ast.CallExpr

BuildCallSiteIndex scans all files and builds a map from function types.Object to all call expressions that invoke it.

func FindModificationReceiver

func FindModificationReceiver(expr *ast.CallExpr, typesInfo *types.Info) types.Object

FindModificationReceiver unwraps template.Must and returns the types.Object of the variable receiver for a method call like ts.ParseFS(...) or template.Must(ts.ParseFS(...)). Returns nil if no variable receiver is found.

func IsFuncParam

func IsFuncParam(info *types.Info, files []*ast.File, expr ast.Expr) (paramIdx int, funcObj types.Object, ok bool)

IsFuncParam reports whether the given expression is an identifier that refers to a function parameter. If so, it returns the parameter index (position in the function signature) and the types.Object for the enclosing function.

func IsTemplateMethod

func IsTemplateMethod(typesInfo *types.Info, sel *ast.SelectorExpr) bool

IsTemplateMethod reports whether sel refers to a method on *html/template.Template or *text/template.Template.

func IsTemplatePkgIdent

func IsTemplatePkgIdent(info *types.Info, ident *ast.Ident) bool

IsTemplatePkgIdent reports whether ident refers to the "html/template" or "text/template" package via the type checker.

func RelativeFilePaths

func RelativeFilePaths(wd string, abs ...string) ([]string, error)

func ResolveStringExpr

func ResolveStringExpr(info *types.Info, files []*ast.File, expr ast.Expr) (string, bool)

ResolveStringExpr attempts to statically resolve an AST expression to a string value. It handles string literals, named constants, and simple variable assignments (where the variable is defined once and never reassigned).

func StringLiteralExpression

func StringLiteralExpression(wd string, set *token.FileSet, exp ast.Expr) (string, error)

func StringLiteralExpressionList

func StringLiteralExpressionList(wd string, set *token.FileSet, list []ast.Expr) ([]string, error)

Types

type Forrest

type Forrest template.Template

func NewForrest

func NewForrest(templates *template.Template) *Forrest

func (*Forrest) FindTree

func (f *Forrest) FindTree(name string) (*parse.Tree, bool)

type Template

type Template interface {
	New(name string) Template
	Parse(text string) (Template, error)
	Funcs(funcMap map[string]any) Template
	Option(opt ...string) Template
	Delims(left, right string) Template
	Lookup(name string) Template
	Name() string
	AddParseTree(name string, tree *parse.Tree) (Template, error)
	Tree() *parse.Tree
	FindTree(name string) (*parse.Tree, bool)
	TemplateNames() []string
}

Template abstracts over html/template.Template and text/template.Template so that the correct template package is used based on the user's import.

func EvaluateTemplateSelector

func EvaluateTemplateSelector(ts Template, pkg *types.Package, typesInfo *types.Info, expression ast.Expr, workingDirectory, templatesVariable, rDelim, lDelim string, fileSet *token.FileSet, files []*ast.File, embeddedPaths []string, funcTypeMaps TemplateFunctions, fm map[string]any, meta *TemplateMetadata) (Template, string, string, error)

func NewTemplate

func NewTemplate(pkgPath, name string) Template

NewTemplate creates a Template backed by the appropriate template package either: "text/template" or "html/template".

type TemplateFunctions

type TemplateFunctions map[string]*types.Signature

func DefaultFunctions

func DefaultFunctions(pkg *types.Package) TemplateFunctions

func (TemplateFunctions) FindFunction

func (functions TemplateFunctions) FindFunction(name string) (*types.Signature, bool)

type TemplateMetadata

type TemplateMetadata struct {
	EmbedFilePaths []string
	ParseCalls     []*ast.BasicLit
}

TemplateMetadata accumulates metadata during template evaluation.

Jump to

Keyboard shortcuts

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