All Projects → antonmedv → Expr

antonmedv / Expr

Licence: mit
Expression language for Go

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Expr

eval-estree-expression
Safely evaluate JavaScript (estree) expressions, sync and async.
Stars: ✭ 22 (-98.96%)
Mutual labels:  ast, expression, evaluator, expression-evaluator
Math Engine
Mathematical expression parsing and calculation engine library. 数学表达式解析计算引擎库
Stars: ✭ 123 (-94.21%)
Mutual labels:  expression, engine, ast
booleval
Header-only C++17 library for evaluating logical expressions.
Stars: ✭ 54 (-97.46%)
Mutual labels:  expression, evaluator, expression-evaluator
evaluator
No description or website provided.
Stars: ✭ 35 (-98.35%)
Mutual labels:  expression, evaluator
JitCat
A C++17 library for parsing and executing expressions. Allows easy exposure of variables and functions from C++ through built-in reflection functionality.
Stars: ✭ 16 (-99.25%)
Mutual labels:  expression-evaluator, expression-language
Metric Parser
📜 AST-based advanced mathematical parser written by Typescript.
Stars: ✭ 26 (-98.78%)
Mutual labels:  expression, ast
Tinyrenderer
A brief computer graphics / rendering course
Stars: ✭ 11,776 (+454.69%)
Mutual labels:  engine
Sabisu Rails
Simple and powerful engine for exploring your Rails api application
Stars: ✭ 129 (-93.92%)
Mutual labels:  engine
Openmf Archived
Abandoned C++ version. Contains useful format utils and parsers.
Stars: ✭ 123 (-94.21%)
Mutual labels:  engine
Simplexrpgengine
Modular game engine built with MonoGame, with GMS2-like workflow and advanced level editor
Stars: ✭ 122 (-94.25%)
Mutual labels:  engine
2moons
Open Source Browsergame Framework
Stars: ✭ 133 (-93.74%)
Mutual labels:  engine
Search Engine Optimization
🔍 A helpful checklist/collection of Search Engine Optimization (SEO) tips and techniques.
Stars: ✭ 1,798 (-15.31%)
Mutual labels:  engine
Gplayengine
Cross-platform C++ 2D / 3D game engine.
Stars: ✭ 129 (-93.92%)
Mutual labels:  engine
Phplrt
PHP Language Recognition Tool
Stars: ✭ 127 (-94.02%)
Mutual labels:  ast
Bee.js
javaScript常用工具类
Stars: ✭ 130 (-93.88%)
Mutual labels:  expression
Openage
Free (as in freedom) open source clone of the Age of Empires II engine 🚀
Stars: ✭ 10,712 (+404.57%)
Mutual labels:  engine
Govaluate
Arbitrary expression evaluation for golang
Stars: ✭ 2,130 (+0.33%)
Mutual labels:  expression
Fonline
FOnline Engine is a flexible cross-platform isometric game engine
Stars: ✭ 128 (-93.97%)
Mutual labels:  engine
Pgbouncerhero
A dashboard for your PgBouncers.
Stars: ✭ 129 (-93.92%)
Mutual labels:  engine
Ast I18n
Easily migrate your existing React codebase to use i18n
Stars: ✭ 129 (-93.92%)
Mutual labels:  ast

Expr

Build Status Go Report Card GoDoc

expr logo

Expr package provides an engine that can compile and evaluate expressions. An expression is a one-liner that returns a value (mostly, but not limited to, booleans). It is designed for simplicity, speed and safety.

The purpose of the package is to allow users to use expressions inside configuration for more complex logic. It is a perfect candidate for the foundation of a business rule engine. The idea is to let configure things in a dynamic way without recompile of a program:

# Get the special price if
user.Group in ["good_customers", "collaborator"]

# Promote article to the homepage when
len(article.Comments) > 100 and article.Category not in ["misc"]

# Send an alert when
product.Stock < 15

Features

  • Seamless integration with Go (no need to redefine types)
  • Static typing (example).
    out, err := expr.Compile(`name + age`)
    // err: invalid operation + (mismatched types string and int)
    // | name + age
    // | .....^
  • User-friendly error messages.
  • Reasonable set of basic operators.
  • Builtins all, none, any, one, filter, map.
    all(Tweets, {.Size <= 280})
  • Fast (benchmarks): uses bytecode virtual machine and optimizing compiler.

Install

go get github.com/antonmedv/expr

Documentation

Expr Code Editor

Expr Code Editor

Also, I have an embeddable code editor written in JavaScript which allows editing expressions with syntax highlighting and autocomplete based on your types declaration.

Learn more →

Examples

Play Online

package main

import (
	"fmt"
	"github.com/antonmedv/expr"
)

func main() {
	env := map[string]interface{}{
		"greet":   "Hello, %v!",
		"names":   []string{"world", "you"},
		"sprintf": fmt.Sprintf,
	}

	code := `sprintf(greet, names[0])`

	program, err := expr.Compile(code, expr.Env(env))
	if err != nil {
		panic(err)
	}

	output, err := expr.Run(program, env)
	if err != nil {
		panic(err)
	}

	fmt.Println(output)
}

Play Online

package main

import (
	"fmt"
	"github.com/antonmedv/expr"
)

type Tweet struct {
	Len int
}

type Env struct {
	Tweets []Tweet
}

func main() {
	code := `all(Tweets, {.Len <= 240})`

	program, err := expr.Compile(code, expr.Env(Env{}))
	if err != nil {
		panic(err)
	}

	env := Env{
		Tweets: []Tweet{{42}, {98}, {69}},
	}
	output, err := expr.Run(program, env)
	if err != nil {
		panic(err)
	}

	fmt.Println(output)
}

Contributing

Expr consist of a few packages for parsing source code to AST, type checking AST, compiling to bytecode and VM for running bytecode program.

Also expr provides powerful tool exe for debugging. It has interactive terminal debugger for our bytecode virtual machine.

debugger

Who is using Expr?

  • Aviasales Aviasales are actively using Expr for different parts of the search engine.
  • Argo Argo Rollouts - Progressive Delivery for Kubernetes.
  • Argo Argo Workflows - The workflow engine for Kubernetes.
  • CrowdSec Crowdsec - A security automation tool.
  • FACEIT uses Expr to allow customization of its eSports matchmaking algorithm.
  • Mystery Minds uses Expr to allow easy yet powerful customization of its matching algorithm.
  • qiniu qiniu cloud use Expr in trade systems.
  • Melrōse uses Expr to implement its music programming language which allows for an interactive music composition experience.

Add your company too

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].