Skip to content

Latest commit

 

History

94 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

English|中文

ZLExpress Basic Grammar

一、Background Introduction

ZLExpress is a scripting language that supports business rules, expressions (Boolean combinations), special mathematical formula calculations, syntax analysis, and other features. Simplified code, minimal dependencies, 130k jar package (smaller than QLExpress) suitable for all Java runtime environments

二、Dependency and call instructions

<groupId>io.github.csuwl</groupId>
<artifactId>ZLExpress</artifactId>
<version>1.0.10-RELEASE</version>
ZLExpress zlExpress = new ZLExpress();
Object result = zlExpress.process("ds=543;ds>56;", null, null);
System.out.println(process);

三、Grammar Introduction

1、Operators and Java Object Operations

Java syntax

//support +,-,*,/,<,>,<=,>=,==,!=, Operators such as in, not,&&(and),||(or),like,etc,
// "if", "else", "for", "break", "continue" and other statements, 
// supporting custom functions. Support creating Java objects and calling methods.
n = 10;
sum = 0;
return sum+n;

int sumFunc(int d,int s){
    return d+s;
}

sum = sumFunc(n,m);

if(543 in [748,654,87,543,654,7654]){
    print(date("2024-12-06")," ",date("2024-02-08"));
 }else{
    return false;
}

Object Operations in Java

import java.math.BigInteger;
bigInt = new BigInteger();
bigInt2 = bigInt.add(bigInt);// Call object methods

2、Base type

ZLExpress has base type: int/Int,double/double,string/String,Bool/bool/boolean,Array/array

int i=543;
Int intValue=i;
s = "fdsa";
double dd=654.4532;
arr=[654,76556,,876,9];

3、Define functions in the script

int add(int a, int b){
    return a + b;
};

int sub(int a, int b){
    return a - b;
};

a = 10;
return add(a, 4) + sub(a, 9);

4、High precision support

Specifying high-precision parameter when creating ZLExpress object

ZLExpress zlExpress = new ZLExpress(true);
Object process = zlExpress.process(" id = -43 ; id==-43;", null, null);
assertEquals(process,true);

5、Date comparison

agoDay(today - comparisonDate > someValue): Used to check if a date is more than a certain number of days ago.

recentDay(today - date <= someValue): Used to check if a date falls within the past few days.

dds = now();
dds agoDay 3;// false
dds recentDay 3;// true

dds = "2024-12-01";
dds agoDay 3; // true
dds recentDay 3 // false

6、Custom extension function

Custom extension functions are implemented through SPI mechanism. Create a META-INF.services folder in the resources directory, Then create "com.csuwl.innerfunction.ExtenderCustomFunctionInterface" file, And filled in the file with the class reference name that implements "com.csuwl.innerfunction.ExtenderCustomFunctionInterface".

import com.csuwl.innerfunction.ExtenderCustomFunctionInterface;
import com.csuwl.model.InnerFunctionDefinition;

import java.util.Arrays;
import java.util.List;

/**
 * custom function
 * prettyPrint
 */
public class CustomPrintFunction implements ExtenderCustomFunctionInterface {
    @Override
    public Object visit(List<Object> parameterValue) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("[");
        for (int i = 0; i < parameterValue.size(); i++) {
            stringBuilder.append(parameterValue.get(i));
        }
        stringBuilder.append("]");

        System.out.println(stringBuilder.toString());
        return null;
    }

    @Override
    public List<InnerFunctionDefinition> getInnerFunctionDefinition() {
        return Arrays.asList(new InnerFunctionDefinition("prettyPrint"),new InnerFunctionDefinition("myPrint"));
    }
}

7、How to Contribute

Thank you very much for your interest in the ZLExpress project. We welcome your suggestions, comments (including criticisms) and contributions to the ZLExpress project. Your suggestions, comments and contributions on ZLExpress can be made directly through GitHub's Issues. If you have some bugfix, you can submit a "Pull Request" to the "dev" branch.

8、Next steps

Invite individuals who have the time and capability to compile the ZLExpress syntax code into Java bytecode and execute it during program runtime.

links for us

About

ZLExpress is a scripting language that supports business rules, expressions (Boolean combinations), special mathematical formula calculations, syntax analysis, and other features.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages