Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vrerv/simple-script-engine
Simple Expression Evaluator
https://github.com/vrerv/simple-script-engine
android java jsr-223 scriptengine
Last synced: 6 days ago
JSON representation
Simple Expression Evaluator
- Host: GitHub
- URL: https://github.com/vrerv/simple-script-engine
- Owner: vrerv
- License: mit
- Created: 2024-05-24T04:33:41.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-08-02T02:59:10.000Z (3 months ago)
- Last Synced: 2024-08-02T06:12:10.158Z (3 months ago)
- Topics: android, java, jsr-223, scriptengine
- Language: Java
- Homepage:
- Size: 84 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Simple Script Engine
## Overview
The **Simple Script Engine** is a lightweight and versatile library for evaluating mathematical and logical expressions.
This implements JSR-223 ScriptEngine interface and provides a simple expression language for evaluating expressions.
## Features
- Supports basic arithmetic operations: +, -, *, /, and %.
- Handles logical operations: AND, OR, and comparisons <, >, <=, >=, ==, !=
- Supports parentheses for grouping expressions.
- Adding human friendly operator tokens.| Token | Operation |
|-------|-------------|
| and | Logical AND |
| or | Logical OR |
| = | Equal |
| not | Not Equal |### Android
- The library is compatible with Android.
- Tested on Android 8.0(API level 26) emulator
- On Android, you can just use the SimpleExpressionEvaluator class directly.## Usage
It is required Java 17 or higher.
To add gradle dependency:
```groovy
implementation 'com.github.vrerv:simple-script-engine:0.1.8'
```To evaluate an expression:
```java
public static void main(String[] args) throws ScriptException {ScriptEngine engine = new ScriptEngineManager().getEngineByName("SimpleExpressionEvaluator");
SimpleScriptContext scriptContext = new SimpleScriptContext();
scriptContext.setBindings(new SimpleBindings(Map.of(
"a", 10,
"b", 20
)), ScriptContext.ENGINE_SCOPE);
System.out.println("Result: " + engine.eval("a + b > 10", scriptContext));
}
```