checker

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package checker defines functions to type-checked a parsed expression against a set of identifier and function declarations.

Index

Constants

This section is empty.

Variables

This section is empty.

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.

Directories

Path Synopsis
Package decls provides helpers for creating variable and function declarations.
Package decls provides helpers for creating variable and function declarations.

Jump to

Keyboard shortcuts

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