Skip to content
Binary Expression Tree
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
parse
.codeclimate.yml
.gitignore
LICENSE
README.md
bool.go
bool_test.go
example_test.go
exp.go
exp_test.go
fmt.go
fmt_test.go
network.go
network_test.go
numbers.go
numbers_test.go
strings.go
strings_test.go
time.go
time_test.go
wercker.yml

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.

You can’t perform that action at this time.