All Projects → allegro → opel

allegro / opel

Licence: other
OPEL - asynchronous expression language

Programming Languages

java
68154 projects - #9 most used programming language
kotlin
9241 projects

Projects that are alternatives of or similar to opel

Aioreactive
Async/await reactive tools for Python 3.9+
Stars: ✭ 215 (+270.69%)
Mutual labels:  expression
mpsl
Shader-Like Mathematical Expression JIT Engine for C++ Language
Stars: ✭ 52 (-10.34%)
Mutual labels:  expression
CoNekT
CoNekT (short for Co-expression Network Toolkit) is a platform to browse co-expression data and enable cross-species comparisons.
Stars: ✭ 17 (-70.69%)
Mutual labels:  expression
evaluator
No description or website provided.
Stars: ✭ 35 (-39.66%)
Mutual labels:  expression
ToolGood.Algorithm
Support four arithmetic operations, Excel formulas, and support custom parameters. 支持四则运算、Excel公式语法,并支持自定义参数。
Stars: ✭ 77 (+32.76%)
Mutual labels:  expression
SqlBatis
A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite etc..
Stars: ✭ 34 (-41.38%)
Mutual labels:  expression
Expressionevaluator
A Simple Math and Pseudo C# Expression Evaluator in One C# File. Can also execute small C# like scripts
Stars: ✭ 194 (+234.48%)
Mutual labels:  expression
Remute
C# library to create new immutable object applying lambda expressions to the existing immutable object
Stars: ✭ 57 (-1.72%)
Mutual labels:  expression
SQLBuilder.Core
.NET Standard 2.1、.NET 5、.NET 6 版本SQLBuilder,Expression表达式转换为SQL语句,支持SqlServer、MySql、Oracle、Sqlite、PostgreSql;基于Dapper实现了不同数据库对应的数据仓储Repository;
Stars: ✭ 85 (+46.55%)
Mutual labels:  expression
karnaugh-map-simplifier
Karnaugh map simplification software, used to visually simplify boolean expressions
Stars: ✭ 33 (-43.1%)
Mutual labels:  expression
zExpression
脚本与编译器内部的语法引擎内核,也是一种op内核,zExpression可以轻松实现自己的脚本引擎
Stars: ✭ 39 (-32.76%)
Mutual labels:  expression
texpr
Boolean evaluation and digital calculation expression engine for GO
Stars: ✭ 18 (-68.97%)
Mutual labels:  expression
eval-estree-expression
Safely evaluate JavaScript (estree) expressions, sync and async.
Stars: ✭ 22 (-62.07%)
Mutual labels:  expression
url-regex-safe
Regular expression matching for URL's. Maintained, safe, and browser-friendly version of url-regex. Resolves CVE-2020-7661 for Node.js servers.
Stars: ✭ 59 (+1.72%)
Mutual labels:  expression
formulize
🌘 formula ui generator
Stars: ✭ 82 (+41.38%)
Mutual labels:  expression
Expression Language
The ExpressionLanguage component provides an engine that can compile and evaluate expressions.
Stars: ✭ 2,418 (+4068.97%)
Mutual labels:  expression
rclc
Mathematical expression calculator with big integers, floats, common fractions, and complex numbers support
Stars: ✭ 24 (-58.62%)
Mutual labels:  expression
booleval
Header-only C++17 library for evaluating logical expressions.
Stars: ✭ 54 (-6.9%)
Mutual labels:  expression
FMPN-FER
Official PyTorch Implementation of 'Facial Motion Prior Networks for Facial Expression Recognition', VCIP 2019, Oral
Stars: ✭ 76 (+31.03%)
Mutual labels:  expression
quickExp
a script for controlling expressions quickly in After Effects
Stars: ✭ 24 (-58.62%)
Mutual labels:  expression

Build Codecov GitHub Release Date GitHub license

opel - asynchronous expression language

opel was designed to let you write simple, short asynchronous expressions. It uses Parboiled as a language grammar engine and common Java 8 CompletableFuture.

For example temperature() function asks REST service for temperature in Fahrenheit for given capital city and we want to convert it to Celsius. We can write a simple expression to achievie it.

(temperature('Warsaw') - 32) * 5 / 9

this expression will be transformed to equivalent code:

temperature('Warsaw')
	.thenCombine(CompletableFuture.completedFuture(32), (l, r) -> l - r)
	.thenCombine(CompletableFuture.completedFuture(5), (l, r) -> l * r)
	.thenCombine(CompletableFuture.completedFuture(9), (l, r) -> l / r)

Contents

Our business case

In OpBox which is our solution to build frontend in microservices world we have to prepare site title depending on data returned from data source (REST service). For show product page it may look like:

restService('showProduct') + ' - Allegro.pl - Więcej niż aukcje.'

Why have we created another language?

Allegro is a big platform with huge traffic. We encounter many performance issues so we decided to design everything asynchronously. Whenever it's possible we use CompletableFutures. It's a bit more complicated that way but opel abstraction layer enables our users (non developers) to write simple expressions in easy way.

After checking some expression languages like: SpEL or JEXL we didn't find any libraries supporting required asynchronous behavior.

What opel can't do?

opel aims at very simple expressions. Certainly it won't be enough to make complicated scripts - but we want opel to stay that way.

What can opel do for you?

opel supports:

  • primary math and string operations (i.e. 2+2*2, 'Hello' + 'world !')
  • relational and equality operators (i.e. 2 == 3, 2 > 1 != false)
  • logic operators (i.e. true && false, false || true)
  • simple map element access (i.e. map.field or map['field'])
  • simple list element access (i.e. list[index])
  • object method calls (i.e. 'Hello, World!'.length())
  • if expressions (i.e. if (2 > 3) 'a' else 'b')
  • defining local constant values (i.e. val x = 2+2*2; x * x)
  • defining maps (i.e. val x = {'a': 'b'}; x.a)
  • defining lists (i.e. val x = ['a', 'b']; x[0])
  • defining the functions and lambda expression (i.e. val x = a -> a * a; val y = b -> b + b; x(y(r)))
  • registrable constant values (i.e. 'Hello, ' + WORLD_VALUE)
  • registrable functions (i.e. myFunction('Hello, World!'))
  • registrable implicit conversions (i.e. 2 + '2' or 'Hello, World!'.myMethod())

More can be found in documentation.

Using with Gradle

Basically, all you have to do is to add a compile dependency:

dependencies {
    compile 'pl.allegro.tech:opel:1.1.8'
}

Java usage examples

Evaluate simple expression

Create an instance of OpelEngine and evaluate the expression:

OpelEngine engine = OpelEngineBuilder.create()
        .build();

engine.eval("2 + 3")
        .whenComplete((result, error) -> System.out.println(result));

Evaluate expression with global variable

Create an instance of OpelEngine with global a variable and evaluate the expression:

OpelEngine engine = OpelEngineBuilder.create()
        .withCompletedValue("PI", 3.14)
        .build();

engine.eval("PI * 2")
        .whenComplete((result, error) -> System.out.println(result));

Notice that in opel, all variables are final.

Evaluate expression with context variable

The engine is a heavy object and should be reused to evaluate different expressions. To achieve this, variables can be provided in the context:

OpelEngine engine = OpelEngineBuilder.create()
        .withCompletedValue("PI", 3.14)
        .build();

String expression = "PI * r * r";

EvalContext context = EvalContextBuilder.create()
        .withCompletedValue("r", 3)
        .build();

engine.eval(expression, context)
        .whenComplete((result, error) -> System.out.println(result));

In the engine, you can configure general language for the application. In context, you can provide, for example, request context like authorized username.

Evaluate expression with engine/context function

Functions in opel are implemented by OpelAsyncFunction interface and can be added as regular variable:

OpelAsyncFunction<Object> function = new OpelAsyncFunction<Object>() {
            @Override
            CompletableFuture<Object> apply(List<CompletableFuture<?>> args) {
                Object result = // a call to an external service, to a database or other logic
                return result;
            }
        };

OpelEngine engine = OpelEngineBuilder.create()
        .withCompletedValue("myFun", function)
        .build();

String expression = "myFun(a) * myFun(b)";

EvalContext context = EvalContextBuilder.create()
        .withCompletedValue("a", "john")
        .withCompletedValue("b", "jenny")
        .build();

engine.eval(expression, context)
        .whenComplete((result, error) -> System.out.println(result));

In the same way, we add function to OpelEngine by withCompletedValue method, it can be added to EvalContext.

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].