Documentation
¶
Overview ¶
Package checker defines functions to type-checked a parsed expression against a set of identifier and function declarations.
Index ¶
- func Check(parsed *ast.AST, source common.Source, env *Env) (*ast.AST, *common.Errors)
- func FormatCELType(t any) string
- func FormatCheckedType(t *exprpb.Type) string
- func Print(e ast.Expr, checked *ast.AST) string
- type AstNodedeprecated
- type CallEstimatedeprecated
- type CatalogSupplier
- type CostEstimatedeprecated
- type CostEstimatordeprecated
- type CostOptiondeprecated
- type Env
- type FunctionEstimatordeprecated
- type Group
- type Option
- type Scopes
- func (s *Scopes) AddIdent(decl *decls.VariableDecl)
- func (s *Scopes) FindFunction(name string) *decls.FunctionDecl
- func (s *Scopes) FindGlobalIdent(name string) *decls.VariableDecl
- func (s *Scopes) FindIdentInScope(name string) *decls.VariableDecl
- func (s *Scopes) FindLocalIdent(name string) *decls.VariableDecl
- func (s *Scopes) Pop() *Scopes
- func (s *Scopes) Push() *Scopes
- func (s *Scopes) PushInherited() *Scopes
- func (s *Scopes) SetFunction(fn *decls.FunctionDecl)
- type SizeEstimatedeprecated
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Check ¶
Check performs type checking, giving a typed AST.
The input is a parsed AST 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 type-checked AST, which might not be usable if there are errors in the error registry.
func FormatCELType ¶ added in v0.32.0
FormatCELType formats a types.Type value to a string representation.
The type formatting is identical to FormatCheckedType.
func FormatCheckedType ¶
FormatCheckedType converts a type message into a string representation.
Types ¶
type AstNode
deprecated
added in
v0.32.0
AstNode represents an AST node for the purpose of cost estimations.
Deprecated: use cost.AstNode
func NewAstNode
deprecated
added in
v0.33.0
type CallEstimate
deprecated
added in
v0.32.0
type CallEstimate = cost.CallEstimate
CallEstimate includes a CostEstimate for the call, and an optional estimate of the result object size.
Deprecated: use cost.CallEstimate
type CatalogSupplier ¶ added in v0.33.0
CatalogSupplier returns a Catalog of symbols.
type CostEstimate
deprecated
added in
v0.32.0
type CostEstimate = cost.CostEstimate
CostEstimate represents an estimated cost range and provides add and multiply operations that do not overflow.
Deprecated: use cost.CostEstimate
func Cost
deprecated
added in
v0.32.0
func Cost(checked *ast.AST, estimator CostEstimator, opts ...CostOption) (CostEstimate, error)
Cost estimates the cost of the parsed and type checked CEL expression.
Deprecated: use cost.Cost
func FixedCostEstimate
deprecated
added in
v0.32.0
func FixedCostEstimate(fixedCost uint64) CostEstimate
FixedCostEstimate returns a cost with a fixed min and max range.
Deprecated: use cost.FixedCostEstimate
func UnknownCostEstimate
deprecated
added in
v0.32.0
func UnknownCostEstimate() CostEstimate
UnknownCostEstimate returns a cost with an unknown impact.
Deprecated: use cost.UnknownCostEstimate
type CostEstimator
deprecated
added in
v0.32.0
type CostOption
deprecated
added in
v0.32.0
type CostOption = cost.CostOption
CostOption configures flags which affect cost computations.
Deprecated: use cost.CostOption
func OverloadCostEstimate
deprecated
added in
v0.32.0
func OverloadCostEstimate(overloadID string, functionCoster FunctionEstimator) CostOption
OverloadCostEstimate binds a FunctionEstimator to a specific function overload ID.
Deprecated: use cost.OverloadCostEstimate
func PresenceTestHasCost
deprecated
added in
v0.32.0
func PresenceTestHasCost(hasCost bool) CostOption
PresenceTestHasCost determines whether presence testing has a cost of one or zero.
Deprecated: use cost.PresenceTestHasCost
type Env ¶
type Env struct {
// contains filtered or unexported fields
}
Env is the environment for type checking.
The Env is comprised of a container, type provider, declarations, and other related objects which can be used to assist with type-checking.
func (*Env) AddFunctions ¶ added in v0.32.0
func (e *Env) AddFunctions(declarations ...*decls.FunctionDecl) error
AddFunctions configures the checker with a list of function declarations.
If there are overlapping declarations, the method will error.
type FunctionEstimator
deprecated
added in
v0.32.0
type FunctionEstimator = cost.FunctionEstimator
FunctionEstimator provides a CallEstimate given the target and arguments for a specific function, overload pair.
Deprecated: use cost.FunctionEstimator
type Group ¶ added in v0.32.0
type Group struct {
// contains filtered or unexported fields
}
Group is a set of Decls that is pushed on or popped off a Scopes as a unit. Contains separate namespaces for identifier and function Decls. (Should be named "Scope" perhaps?)
type Option ¶ added in v0.32.0
type Option func(*options) error
Option is a functional option for configuring the type-checker
func Catalog ¶ added in v0.33.0
func Catalog(cat CatalogSupplier) Option
Catalog configures the checker with a symbol catalog supplier used for error suggestions and refinement.
func CrossTypeNumericComparisons ¶ added in v0.32.0
CrossTypeNumericComparisons toggles type-checker support for numeric comparisons across type See https://github.com/google/cel-spec/wiki/proposal-210 for more details.
func JSONFieldNames ¶ added in v0.32.0
JSONFieldNames enables the use of json names instead of the standard protobuf snake_case field names
func ValidatedDeclarations ¶ added in v0.32.0
ValidatedDeclarations provides a reference to validated declarations which will be inherited as a parent scope without copying.
type Scopes ¶ added in v0.32.0
type Scopes struct {
// contains filtered or unexported fields
}
Scopes represents nested Decl sets where the Scopes value contains a Groups containing all identifiers in scope and an optional parent representing outer scopes. Each Groups value is a mapping of names to Decls in the ident and function namespaces. Lookups are performed such that bindings in inner scopes shadow those in outer scopes.
func (*Scopes) AddIdent ¶ added in v0.32.0
func (s *Scopes) AddIdent(decl *decls.VariableDecl)
AddIdent adds the ident Decl in the current scope. Note: If the name collides with an existing identifier in the scope, the Decl is overwritten.
func (*Scopes) FindFunction ¶ added in v0.32.0
func (s *Scopes) FindFunction(name string) *decls.FunctionDecl
FindFunction finds the first function Decl with a matching name in Scopes. The search is performed from innermost to outermost. Returns nil if no such function in Scopes.
func (*Scopes) FindGlobalIdent ¶ added in v0.32.0
func (s *Scopes) FindGlobalIdent(name string) *decls.VariableDecl
FindGlobalIdent finds an identifier in the global scope, ignoring all local scopes.
func (*Scopes) FindIdentInScope ¶ added in v0.32.0
func (s *Scopes) FindIdentInScope(name string) *decls.VariableDecl
FindIdentInScope finds the first ident Decl with a matching name in the current Scopes value, or nil if one does not exist. Note: The search is only performed on the current scope and does not search outer scopes.
func (*Scopes) FindLocalIdent ¶ added in v0.32.0
func (s *Scopes) FindLocalIdent(name string) *decls.VariableDecl
FindLocalIdent finds a locally scoped variable with a given name, ignoring the root scope.
func (*Scopes) Pop ¶ added in v0.32.0
Pop returns the parent Scopes value for the current scope, or the current scope if the parent is nil.
func (*Scopes) Push ¶ added in v0.32.0
Push creates a new Scopes value which references the current Scope as its parent.
func (*Scopes) PushInherited ¶ added in v0.32.0
PushInherited creates a new Scopes value which references the current Scope as its inherited parent.
func (*Scopes) SetFunction ¶ added in v0.32.0
func (s *Scopes) SetFunction(fn *decls.FunctionDecl)
SetFunction adds the function Decl to the current scope. Note: Any previous entry for a function in the current scope with the same name is overwritten.
type SizeEstimate
deprecated
added in
v0.32.0
type SizeEstimate = cost.SizeEstimate
SizeEstimate represents an estimated size of a variable length string, bytes, map or list.
Deprecated: use cost.SizeEstimate
func FixedSizeEstimate
deprecated
added in
v0.32.0
func FixedSizeEstimate(size uint64) SizeEstimate
FixedSizeEstimate returns a size estimate with a fixed min and max range.
Deprecated: use cost.FixedSizeEstimate
func UnknownSizeEstimate
deprecated
added in
v0.32.0
func UnknownSizeEstimate() SizeEstimate
UnknownSizeEstimate returns a size between 0 and max uint.
Deprecated: use cost.UnknownSizeEstimate