package checker
import "github.com/google/cel-go/checker"
Package checker defines functions to type-checked a parsed expression against a set of identifier and function declarations.
Index ¶
- func Check(parsedExpr *exprpb.ParsedExpr, source common.Source, env *Env) (*exprpb.CheckedExpr, *common.Errors)
- func FormatCheckedType(t *exprpb.Type) string
- func Print(e *exprpb.Expr, checks *exprpb.CheckedExpr) string
- func StandardDeclarations() []*exprpb.Decl
- type Env
- func NewEnv(packager packages.Packager, provider ref.TypeProvider) *Env
- func NewStandardEnv(packager packages.Packager, provider ref.TypeProvider) *Env
- func (e *Env) Add(decls ...*exprpb.Decl) error
- func (e *Env) EnableDynamicAggregateLiterals(enabled bool) *Env
- func (e *Env) LookupFunction(typeName string) *exprpb.Decl
- func (e *Env) LookupIdent(typeName string) *exprpb.Decl
Functions ¶
func Check ¶
func Check(parsedExpr *exprpb.ParsedExpr, source common.Source, env *Env) (*exprpb.CheckedExpr, *common.Errors)
Check performs type checking, giving a typed AST. The input is a ParsedExpr proto and an env which encapsulates type binding of variables, declarations of built-in functions, descriptions of protocol buffers, and a registry for errors. Returns a CheckedExpr proto, which might not be usable if there are errors in the error registry.
func FormatCheckedType ¶
FormatCheckedType converts a type message into a string representation.
func Print ¶
func Print(e *exprpb.Expr, checks *exprpb.CheckedExpr) string
Print returns a string representation of the Expr message, annotated with types from the CheckedExpr. The Expr must be a sub-expression embedded in the CheckedExpr.
func StandardDeclarations ¶
StandardDeclarations returns the Decls for all functions and constants in the evaluator.
Types ¶
type Env ¶
type Env struct {
// contains filtered or unexported fields
}
Env is the environment for type checking. It consists of a Packager, a Type Provider, declarations, and collection of errors encountered during checking.
func NewEnv ¶
func NewEnv(packager packages.Packager, provider ref.TypeProvider) *Env
NewEnv returns a new *Env with the given parameters.
func NewStandardEnv ¶
func NewStandardEnv(packager packages.Packager, provider ref.TypeProvider) *Env
NewStandardEnv returns a new *Env with the given params plus standard declarations.
func (*Env) Add ¶
Add adds new Decl protos to the Env. Returns an error for identifier redeclarations.
func (*Env) EnableDynamicAggregateLiterals ¶
EnableDynamicAggregateLiterals detmerines whether list and map literals may support mixed element types at check-time. This does not preclude the presence of a dynamic list or map somewhere in the CEL evaluation process.
func (*Env) LookupFunction ¶
LookupFunction returns a Decl proto for typeName as a function in env. Returns nil if no such function is found in env.
func (*Env) LookupIdent ¶
LookupIdent returns a Decl proto for typeName as an identifier in the Env. Returns nil if no such identifier is found in the Env.
Source Files ¶
checker.go env.go errors.go mapping.go printer.go standard.go types.go
Directories ¶
Path | Synopsis |
---|---|
checker/decls | Package decls provides helpers for creating variable and function declarations. |
- Version
- v0.4.2
- Published
- Apr 21, 2020
- Platform
- js/wasm
- Imports
- 15 packages
- Last checked
- 3 minutes ago –
Tools for package owners.