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

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

func FormatCheckedType(t *exprpb.Type) string

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

func StandardDeclarations() []*exprpb.Decl

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,
	typeProvider ref.TypeProvider) *Env

NewEnv returns a new *Env with the given parameters.

func NewStandardEnv

func NewStandardEnv(packager packages.Packager,
	typeProvider ref.TypeProvider) *Env

NewStandardEnv returns a new *Env with the given params plus standard declarations.

func (*Env) Add

func (e *Env) Add(decls ...*exprpb.Decl) error

Add adds new Decl protos to the Env. Returns an error for identifier redeclarations.

func (*Env) LookupFunction

func (e *Env) LookupFunction(typeName string) *exprpb.Decl

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

func (e *Env) LookupIdent(typeName string) *exprpb.Decl

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

PathSynopsis
checker/declsPackage decls provides helpers for creating variable and function declarations.
Version
v0.1.0
Published
Feb 5, 2019
Platform
js/wasm
Imports
15 packages
Last checked
1 minute ago

Tools for package owners.