Simple expression evaluation engine for Go

Overview

🌶️ chili

Currently in development, Unstable (API may change in future)

Simple expression evaluation engine.

Expression is one liner that evalutes into single value

Features

  • Number accuracy (using github.com/shopspring/decimal pkg)
  • Extensible
  • Simple grammer

Installation

$ go get github.com/5anthosh/chili

Examples

package main

import (
    "fmt"
    "github.com/5anthosh/chili"
)
func main() {
    expression := "val > 50 ? 'Greater than or 50' : 'Smaller than 50'"
    values := map[string]interface{}{
        "val": 60,
    }
    result, err := chili.Eval(expression, values)
    if err != nil {
        panic(err)
    }
    println(fmt.Sprintf("%v result", result))
}
package main

import (
    "fmt"
    "github.com/5anthosh/chili/environment"
    "github.com/5anthosh/chili/evaluator"
    "github.com/5anthosh/chili/parser"
    "github.com/shopspring/decimal"
)

func main() {
    source := "PI*R^2 + abs(45.345)"

    env := environment.New()
    env.SetDefaultFunctions()
    env.SetDefaultVariables()
    env.SetIntVariable("R", 2)

    chiliParser := parser.New(source)
    expression, err := chiliParser.Parse()
    if err != nil {
        panic(err)
    }

    chiliEvaluator := evaluator.New(env)
    value, err := chiliEvaluator.Run(expression)
    if err != nil {
        panic(err)
    }

    println(fmt.Sprintf("%v result", value))
}

License

MIT

You might also like...
EGo lets you build, debug und run Go apps on Intel SGX - as simple as conventional Go programming!

EGo lets you build, debug und run Go apps on Intel SGX - as simple as conventional Go programming!

A super simple Lodash like utility library with essential functions that empowers the development in Go
A super simple Lodash like utility library with essential functions that empowers the development in Go

A simple Utility library for Go Go does not provide many essential built in functions when it comes to the data structure such as slice and map. This

egg - the simple error aggregator

egg - the simple error aggregator egg ingests errors and aggregates them egg has 1st class support for sentry SDKs so you dont have to change any code

Procswap is a simple application that allows you to prioritize processes on a Windows machine.
Procswap is a simple application that allows you to prioritize processes on a Windows machine.

Procswap is a simple application that allows you to prioritize processes on a Windows machine.

Simple unpacking script for Ezuri ELF Crypter
Simple unpacking script for Ezuri ELF Crypter

ezuri_unpack A simple unpacking script for the Ezuri ELF Crypter. Based on the analysis done by Ofer Caspi and Fernando Martinez of AT&T Alien Labs

Lightweight, Simple, Quick, Thread-Safe Golang Stack Implementation

stack Lightweight, Simple, Quick, Thread-Safe Golang Stack Implementation Purpose Provide a fast, thread safe, and generic Golang Stack API with minim

Simple profiling for Go

profile Simple profiling for Go. Easy management of Go's built-in profiling and tracing Based on the widely-used pkg/profile: mostly-compatible API Su

simple i18n support that relies on standard go libraries

The i18n package mainly includes a set of methods for managing the data. Start by creating a en.json file.

A simple thread-safe, fixed size LRU written in Go. Based on dominictarr's Hashlru Algorithm. 🔃

go-hashlru A simple thread-safe, fixed size LRU written in Go. Based on dominictarr's Hashlru Algorithm. 🔃 Uses map[interface{}]interface{} to allow

Releases(v0.0.3)
Owner
Santhosh Kumar
Backend engineer. C, Go, Rust, TypeScript, and Python
Santhosh Kumar
rxscan provides functionality to scan text to variables using regular expression capture group.

rxscan rxscan provides functionality to scan text to variables using regular expression capture group. This library is still experimental, use at your

Ahmy Yulrizka 14 Dec 21, 2020
a decision & trigger framework backed by Google's Common Expression Language used in graphikDB

a decision & trigger framework backed by Google's Common Expression Language used in graphikDB

null 62 Nov 15, 2022
go expression

golang 实现的表达式计算 功能清单 四则运算 +-*/ 实现; 逻辑运算 and or && || 实现; 参数传递; 逻辑运算符 > >= < <= ! 实现; 自定义方法注入; TODO 优雅的错误返回; 自定义方法注入; 使用 go get -u github.com/huangxing

Huang.X 2 Sep 29, 2021
[mirror] star-tex (or *TeX) is a TeX engine in Go.

star-tex star-tex (or *TeX) is a TeX engine in Go. cmd/star-tex star-tex provides a TeX to DVI typesetter. $> star-tex ./testdata/hello.tex out.div $>

null 24 Dec 26, 2022
⚙️ Concept of Golang HTML render engine with frontend components and dynamic behavior

SSC Engine An HTML render engine concept that brings frontend-like components experience to the server side with native html/template on steroids. Sup

Yurii Zinets 543 Nov 25, 2022
A pluggable linear task engine

noscript A pluggable linear task engine. Great for providing flexible configuration pattern to end users or providing scripting-like functionality to

null 0 Oct 23, 2021
JIN the coolest fighting game ever made that uses the M.U.G.E.N engine so heres how you can build it

JIN the coolest fighting game ever made that uses the M.U.G.E.N engine so heres how you can build it

Elijah Davis 1 Jan 24, 2022
Go-generics-simple-doubly-linked-list - A simple doubly linked list implemented using generics (Golang)

Welcome to Go-Generics-Simple-Doubly-Linked-List! Hi, This repository contains a

Behrad Ravanbod 5 Jun 30, 2022
Simple in Pure Go in Browser Interactive Interpreter

GoBook This project is a PoC Don't take it seriously The main point of this project is the use of the library: github.com/brendonmatos/golive Maybe th

Brendon Ferreira 24 Feb 22, 2022
Simple project to demonstrate the loading of eBPF programs via florianl/go-tc.

tc-skeleton Simple project to demonstrate the loading of eBPF programs via florianl/go-tc.

Florian Lehner 32 Dec 23, 2022