UExL (Universal Expression Language) is an embeddable platform independent expression evaluation engine. It is a simple language that can be used to evaluate expressions in various formats. UExL is designed to be used in applications where the expression to be evaluated is not known at compile time. Or to make the application more flexible by allowing the user to define expressions through the configuration file or database.
, is a . Designed for efficiency and simplicity, UExL offers an intuitive approach to handling and evaluating expressions in various formats.
UExL is not yet released and ready for use. However, whenever it is, you can install it using the following instructions.
To install UExL, run the following command in your terminal:
go get github.com/maniartech/uexl-go
This command downloads and installs the UExL package along with its dependencies.
First, include UExL in your Go project by importing it:
import "github.com/maniartech/uexl-go"
Here’s how you can quickly start using UExL to evaluate an expression:
package main
import (
"fmt"
"github.com/maniartech/uexl-go"
"log"
)
func main() {
// Evaluating a simple expression
result, err := uexl.Eval("10 + 20")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Result: %v\n", result) // Output: Result: 30
// Using pipe operator in expression
result, err = uexl.Eval("10 + 20 |: $1 * 2")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Result: %v\n", result) // Output: Result: 60
}
This basic example demonstrates how to use UExL to evaluate simple arithmetic expressions.
(List the key features of UExL.)
Operators | Type | Associativity |
---|---|---|
( ) |
Parentheses | Left to Right |
. |
Dot | Left to Right |
% |
Modulus | Left to Right |
* / |
Multiplicative | Left to Right |
+ - |
Additive | Left to Right |
<< >> |
Bitwise Shift | Left to Right |
< > <= >= |
Comparison | Left to Right |
== != |
Equality | Left to Right |
& | ^ |
Bitwise | Left to Right |
&& || |
Logical | Left to Right |
|: |
Pipe | Left to Right |
result, err := uexl.Eval("10 + 20 |: $1 * 2") // Returns 60