apourchet / boolang

Pluggable boolean expression parser in Go.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Boolang

Boolang is a library for parsing your own boolean expressions. It takes care of operation precedence and tokenization, leaving you with only statement evaluation logic to write.

Example

tree, _ := boolang.Parse("(isBoolangAwesome && isBoolangSimple) || !hasLazyEvaluation")
fn := func(l *boolang.Leaf, _ ...interface{}) (bool, error) {
    content := strings.Trim(l.Content, " ")
    if content == "isBoolangAwesome" {
        return true, nil
    } else if content == "isBoolangSimple" {
        return true, nil
    } else if content == "hasLazyEvaluation" {
        return true, nil
    }
    return false, nil
}
result, _ := tree.Eval(fn) // result == true

About

Pluggable boolean expression parser in Go.


Languages

Language:Go 100.0%