Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Binary Expression Tree

godoc reference wercker status Code Climate

Package exp implements a binary expression tree which can be used to evaluate arbitrary binary expressions. You can use this package to build your own expressions however a few expressions are provided out of the box.

Installation

$ go get github.com/alexkappa/exp/...

Usage

import "github.com/alexkappa/exp"

fmt.Printf("%t\n", exp.Or(exp.And(exp.True, exp.Or(exp.True, exp.False)), exp.Not(exp.False)).Eval(nil)) // true

It is also possible to use text to describe expressions. Warning this feature is not battle tested so use with caution.

import "github.com/alexkappa/exp"

x, err := exp.Parse(`(foo >= 100.00)`)
if err != nil {
	// handle error
}
x.Eval(exp.Map{"foo": "150.00"}) // true

Currently only the following operators are supported.

Operator Symbol Data Type
And &&
Or ||
Equal, Eq == string, float64
NotEqual, Neq != string, float64
GreaterThan , Gt > string, float64
GreaterThanEqual , Gte >= string, float64
LessThan , Lt < string, float64
LessThanEqual , Lte <= string, float64

Documentation

API documentation is available at godoc.

About

Binary Expression Tree

Resources

License

Packages

No packages published

Languages

You can’t perform that action at this time.