repl

package module
v0.0.0-...-e2d7340 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0, BSD-3-Clause Imports: 22 Imported by: 1

Documentation

Overview

Package repl defines a set of utilities for working with command line processing of CEL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseType

func ParseType(t string) (*exprpb.Type, error)

ParseType parses a human readable type string into the protobuf representation. TODO(issue/538): add support for abstract types and validating message types.

func UnparseType

func UnparseType(t *exprpb.Type) string

UnparseType pretty-prints a type for the REPL.

TODO(issue/538): This is slightly different from core CEL's built-in formatter. Should converge if possible.

Types

type Cmder

type Cmder interface {
	// Cmd returns the normalized name for the command.
	Cmd() string
}

Cmder interface provides normalized command name from a repl command. Command specifics are available via checked type casting to the specific command type.

func Parse

func Parse(line string) (Cmder, error)

Parse parses a repl command line into a command object. This provides the normalized command name plus any parsed parameters (e.g. variable names in let statements).

An error is returned if the statement isn't well formed. See the parser pacakage for details on the antlr grammar.

type EvaluationContext

type EvaluationContext struct {
	// contains filtered or unexported fields
}

EvaluationContext context for the repl. Handles maintaining state for multiple let expressions.

type Evaluator

type Evaluator struct {
	// contains filtered or unexported fields
}

Evaluator provides basic environment for evaluating an expression with applied context.

func NewEvaluator

func NewEvaluator() (*Evaluator, error)

NewEvaluator returns an inialized evaluator

func (*Evaluator) AddDeclFn

func (e *Evaluator) AddDeclFn(name string, params []letFunctionParam, typeHint *exprpb.Type) error

AddDeclFn declares a function in the environment but doesn't register an expr with it. This allows planning to succeed, but with no value for the function at runtime.

func (*Evaluator) AddDeclVar

func (e *Evaluator) AddDeclVar(name string, typeHint *exprpb.Type) error

AddDeclVar declares a variable in the environment but doesn't register an expr with it. This allows planning to succeed, but with no value for the variable at runtime.

func (*Evaluator) AddLetFn

func (e *Evaluator) AddLetFn(name string, params []letFunctionParam, resultType *exprpb.Type, expr string) error

AddLetFn adds a let function to the evaluation context.

func (*Evaluator) AddLetVar

func (e *Evaluator) AddLetVar(name string, expr string, typeHint *exprpb.Type) error

AddLetVar adds a let variable to the evaluation context. The expression is planned but evaluated lazily.

func (*Evaluator) AddOption

func (e *Evaluator) AddOption(opt Optioner) error

AddOption adds an option to the basic environment. Options are applied before evaluating any of the let statements. Returns an error if setting the option prevents planning any of the defined let expressions.

func (*Evaluator) Compile

func (e *Evaluator) Compile(expr string) (*cel.Ast, error)

Compile compiles the input expression using the current REPL context.

func (*Evaluator) DelLetFn

func (e *Evaluator) DelLetFn(name string) error

DelLetFn removes a function from the evaluation context. If deleting the function breaks a later expression, this function will return an error without modifying the context.

func (*Evaluator) DelLetVar

func (e *Evaluator) DelLetVar(name string) error

DelLetVar removes a variable from the evaluation context. If deleting the variable breaks a later expression, this function will return an error without modifying the context.

func (*Evaluator) Evaluate

func (e *Evaluator) Evaluate(expr string) (ref.Val, *exprpb.Type, error)

Evaluate sets up a CEL evaluation using the current REPL context.

func (*Evaluator) Parse

func (e *Evaluator) Parse(expr string) (*cel.Ast, error)

Parse parses the input expression using the current REPL context.

func (*Evaluator) Process

func (e *Evaluator) Process(cmd Cmder) (string, bool, error)

Process processes the command provided.

func (*Evaluator) Status

func (e *Evaluator) Status() string

Status returns a stringified view of the current evaluator state.

type Optioner

type Optioner interface {
	// Option returns the cel.EnvOption that should be applied to the
	// environment.
	Option() cel.EnvOption
}

Optioner interface represents an option set on the base CEL environment used by the evaluator.

Directories

Path Synopsis
appengine module
cel-repl> %let x = 42 cel-repl> %let y = {'a': x, 'b': y} Adding let failed: Error updating y = {'a': x, 'b': y} ERROR: <input>:1:15: undeclared reference to 'y' (in container ”)
cel-repl> %let x = 42 cel-repl> %let y = {'a': x, 'b': y} Adding let failed: Error updating y = {'a': x, 'b': y} ERROR: <input>:1:15: undeclared reference to 'y' (in container ”)

Jump to

Keyboard shortcuts

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