-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Oleksandr Lobunets
committed
Dec 16, 2014
1 parent
3b2162d
commit a8a54a6
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
conditions | ||
========== | ||
|
||
This package offers a parser of a simple conditions specification language | ||
(reduced set of arithmetic/logical operations). It was created for Flow-Based Programming components that | ||
require configuration to perform some operations on the data received from multiple input ports. | ||
|
||
Example: | ||
``` | ||
import "github.com/oleksandr/conditions" | ||
// Our condition to check | ||
s := "($0 > 0.45) AND ($1 == \"ON\" OR $2 == \"ACTIVE\") AND $3 == false" | ||
// Parse the condition language and get expression | ||
p := NewParser(strings.NewReader(s)) | ||
expr, err := p.Parse() | ||
if err != nil { | ||
// ... | ||
} | ||
// Evaluate expression passing data for $vars | ||
r, err := Evaluate(expr, 0.12, "OFF", "ACTIVE", true) | ||
if err != nil { | ||
// ... | ||
} | ||
// r is false | ||
``` |