| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
This is the Superscript runtime library. Superscript is an expression language that builds upon CEL with enhanced null-safety, host integration, and mobile-optimized features.
The library can be used to evaluate Superscript expressions, with support for:
To build the library, you'll need to install:
To build the library, run:
./build_android.sh(note: for the first run you will need to chmod +x build.sh and wait a bit until the docker images are downloaded)
To verify that the built libraries are properly aligned for Android's 16KB page size requirement:
./test_16kb_build.shOr to verify alignment of existing libraries without rebuilding:
./check_elf_alignment.sh target/android/jniLibs/This will:
The library defines three methods exposed to the host platform, which you can use depending on the type of expression you want to evaluate:
// Evaluates a Superscript expression with provided variables and platform callbacks
string evaluate_with_context(string definition, HostContext context);
// Evaluates a Superscript AST expression with provided variables, platform callbacks
string evaluate_ast_with_context(string definition, HostContext context);
// Evaluates a pure Superscript AST expression
string evaluate_ast(string ast);
// Parses a Superscript expression into an AST
string parse_to_ast(string expression);The HostContext object is a callback interface allowing us to invoke host (iOS/Android) functions from our Rust code. It provides two functions:
The functions pass in the name and the args (if required, serialized as JSON) of the dynamic function/property to invoke, and use a callback to return the result asynchronously.
To use the library in your Android application, you need to:
The library exposes a single function currently: fn evaluate_with_context(definition: String, ctx: HostContext) -> String
This function takes in a JSON containing the variables to be used and the expression to evaluate and returns the result. The JSON is required to be in shape of ExecutionContext, which is defined as:
{
"variables": {
// Map of variables that can be used in the expression
// The key is the variable name, and the value is the variable value wrapped together with a type discriminator
"map" : {
"foo": {"type": "int", "value": 100},
"some_property": {"type": "string", "value": "true"},
"numbers": {
"type" : "list",
"value" : [
{"type": "int", "value": 1},
{"type": "int", "value": 2},
{"type": "int", "value": 3}
]
}
}
},
// Host-exposed functions for computed properties
"computed": {
"daysSince": [{"type": "string", "value": "event_name"}],
"some_property": []
},
// Host-exposed functions for device properties
"device": {
"daysSince": [{"type": "string", "value": "event_name"}],
"batteryLevel": []
},
// The Superscript expression to evaluate
"expression": "device.daysSince(\"app_launch\") > 3.0 && computed.some_property == true"
}The library automatically transforms expressions to be null-safe:
Supported functions are defined in the SUPPORTED_FUNCTIONS constant:
The HostContext provides async callbacks to resolve dynamic properties:
Results are returned as JSON-serialized PassableValue objects.
The library automatically normalizes string values to their appropriate types:
For a detailed explanation of the expression evaluation process, see interpretation-flow.md.
To use the library in your iOS application, you need to:
This should give you a HostContext protocol:
public protocol HostContextProtocol : AnyObject {
func computedProperty(name: String, args: String, callback: ResultCallback)
func deviceProperty(name: String, args: String, callback: ResultCallback)
}And a evaluateWithContext method you can invoke:
public func evaluateWithContext(definition: String, context: HostContext) -> StringWhen updating the library, you need to pay attention to uniffi bindings and ensure they match the signature of the library functions. While it is tempting to migrate the library to use uniffi for the entire library, we still need to use JSON for the input and output since UniFFI does not support recursive enums yet (such as PassableValue). For that, track this issue for updates.
| Back | FazBrowse Home | New Git URL |