dexpr

package module
v0.0.0-...-130fe7b Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2017 License: MIT Imports: 10 Imported by: 8

README

dexpr

A Go package for evaluating dynamic expressions

Requirements

Contributing

Build Status Coverage Status Go Report Card

If you want to improve this program make a pull request to the repo on github. Please put any pull requests in a separate branch to ease integration and add a test to prove that it works. If you find a bug, please report it at the project's issues tracker also on github.

Licence

Most of the code is licensed under an MIT licence. Please see the file, LICENCE.md, for details.

Copyright (C) 2016, Lawrence Woodman [email protected]

The parser is based on Go's parser package and licenced under a BSD style licence. Please see the file, GO_LICENSE, for details.

Copyright (c) 2012 The Go Authors. All rights reserved.

Documentation

Overview

Copyright 2009 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the GO_LICENSE file.

This parser is based on go's parser package, but has been customized to parse expressions suitable for dexpr.

The parser accepts a larger language than is syntactically permitted by the Go spec, for simplicity, and for improved robustness in the presence of syntax errors. For instance, in method declarations, the receiver is treated like an ordinary parameter list and thus may contain multiple entries where the spec permits exactly one. Consequently, the corresponding field in the AST (ast.FuncDecl.Recv) field is not restricted to one entry.

Index

Constants

This section is empty.

Variables

View Source
var ErrDivByZero = errors.New("divide by zero")
View Source
var ErrIncompatibleTypes = errors.New("incompatible types")
View Source
var ErrInvalidCompositeType = errors.New("invalid composite type")
View Source
var ErrInvalidIndex = errors.New("index out of range")
View Source
var ErrSyntax = errors.New("syntax error")
View Source
var ErrTypeNotIndexable = errors.New("type does not support indexing")
View Source
var ErrUnderflowOverflow = errors.New("underflow/overflow")

Functions

func Eval

func Eval(
	expr string,
	callFuncs map[string]CallFun,
	vars map[string]*dlit.Literal,
) *dlit.Literal

Eval compiles an expression and evaluates it with the supplied callFuncs and vars. Any errors produced will be encapsulated in the returned Literal.

func EvalBool

func EvalBool(
	expr string,
	callFuncs map[string]CallFun,
	vars map[string]*dlit.Literal,
) (bool, error)

EvalBool compiles an expression and evaluates it with the supplied callFuncs and vars.

Types

type CallFun

type CallFun func([]*dlit.Literal) (*dlit.Literal, error)

type Expr

type Expr struct {
	Expr string
	Node enode
}

func MustNew

func MustNew(expr string, callFuncs map[string]CallFun) *Expr

func New

func New(expr string, callFuncs map[string]CallFun) (*Expr, error)

func (*Expr) Eval

func (expr *Expr) Eval(vars map[string]*dlit.Literal) *dlit.Literal

func (*Expr) EvalBool

func (expr *Expr) EvalBool(vars map[string]*dlit.Literal) (bool, error)

func (*Expr) String

func (expr *Expr) String() string

type FunctionError

type FunctionError struct {
	FnName string
	Err    error
}

func (FunctionError) Error

func (e FunctionError) Error() string

type FunctionNotExistError

type FunctionNotExistError string

func (FunctionNotExistError) Error

func (e FunctionNotExistError) Error() string

type InvalidExprError

type InvalidExprError struct {
	Expr string
	Err  error
}

func (InvalidExprError) Error

func (e InvalidExprError) Error() string

type InvalidOpError

type InvalidOpError token.Token

func (InvalidOpError) Error

func (e InvalidOpError) Error() string

type VarNotExistError

type VarNotExistError string

func (VarNotExistError) Error

func (e VarNotExistError) Error() string

Jump to

Keyboard shortcuts

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