A pure MoonBit Common Expression Language core with parsing, checking, and deterministic evaluation.
///|
let env = @moon_cel.TypeEnv::new()
.with_variable("role", @moon_cel.CelType::String)
.with_variable("amount", @moon_cel.CelType::Int)
.with_variable("limit", @moon_cel.CelType::Int)
///|
let program = @moon_cel.compile("role == 'admin' || amount <= limit", env)
///|
let activation = @moon_cel.Activation::new()
.bind("role", @moon_cel.Value::String("reviewer"))
.bind("amount", @moon_cel.Value::Int(75L))
.bind("limit", @moon_cel.Value::Int(100L))
///|
let decision = program.eval(
activation,
limits=@moon_cel.EvalLimits::new(max_cost=1000),
)parse(source : StringView) -> ParsedExpr raise ParseError
check(expr : ParsedExpr, env : TypeEnv) -> CheckResult
compile(source : StringView, env : TypeEnv) -> Program raise CompileError
Program::eval(activation : Activation, limits? : EvalLimits) -> Value raise EvalErrormoon run cmd/main --target native -- parse "1 + 2 * 3" --json
moon run cmd/main --target native -- check "amount <= limit" --types-json '{"amount":"int","limit":"int"}' --json
moon run cmd/main --target native -- eval "role == 'admin' || amount <= limit" --vars-json '{"role":"reviewer","amount":75,"limit":100}' --max-cost 1000 --jsonmoon run examples/access_control --target native| Area | v0.1 status | Notes |
|---|---|---|
| Core scalar literals | Supported | Null, Bool, Int64, UInt64, Double, String, Bytes |
| Lists and maps | Supported | Map keys follow the checked CEL scalar-key subset |
| Selection and indexing | Supported | String-keyed maps provide field-style selection |
| Operators | Supported | Includes lazy &&, ||, in, and ternary |
| Gradual type checking | Supported | dyn propagation and aggregate diagnostics |
| Standard conversions | Supported subset | int, uint, double, string, bytes, type, size |
| String receiver functions | Supported subset | contains, startsWith, endsWith, matches |
| matches regular expressions | Bounded subset | ., *, +, ?, ^, $, escapes; groups/classes/alternation rejected |
| Standard macros | Supported | has, all, exists, exists_one, map, filter |
| Resource limits | Supported | Node cost, recursive depth, collection iterations |
| JSON bridge | Supported | JSON values, type environments, activations, AST and diagnostics |
| Protobuf values/construction | Not supported | Explicit v0.1 exclusion |
| Timestamp and duration | Not supported | Explicit v0.1 exclusion |
| Optional types/extensions | Not supported | Explicit v0.1 exclusion |
| CEL Policy YAML layer | Not supported | This project is the expression core only |
| Full RE2 semantics | Not supported | The bounded portable matcher rejects unsupported syntax |
| Official full conformance suite | Not claimed | Only supported v0.1 cases are adapted and tested |
moon update
moon fmt --check
moon check --target all --deny-warn
moon build --target all --deny-warn
moon test --target all --deny-warn
python scripts/count_effective_moonbit.py --minimum 4000 --maximum 4500
moon info
git diff --exit-code
moon package --list
moon publish --dry-run --frozenpub(all) suberror EvalError {
UnboundVariable(name~ : String, span~ : SourceSpan)
TypeMismatch(expected~ : String, actual~ : String, span~ : SourceSpan)
NoSuchField(field~ : String, span~ : SourceSpan)
NoSuchKey(key~ : String, span~ : SourceSpan)
IndexOutOfBounds(index~ : Int, length~ : Int, span~ : SourceSpan)
DivisionByZero(span~ : SourceSpan)
NumericOverflow(span~ : SourceSpan)
UnknownFunction(name~ : String, span~ : SourceSpan)
InvalidArgument(message~ : String, span~ : SourceSpan)
CostLimitExceeded(limit~ : Int, span~ : SourceSpan)
DepthLimitExceeded(limit~ : Int, span~ : SourceSpan)
IterationLimitExceeded(limit~ : Int, span~ : SourceSpan)
} derive(Eq, Debug)pub(all) suberror ParseError {
ParseError(code~ : String, message~ : String, span~ : SourceSpan)
} derive(Eq, Debug)pub struct CheckedExpr {
parsed : ParsedExpr
root_type : CelType
inferred : Map[Int, CelType]
} derive(Debug)pub(all) struct Diagnostic {
code : String
message : String
severity : Severity
span : SourceSpan
} derive(Eq, Debug)pub(all) enum ExprKind {
Literal(Literal)
Identifier(String)
List(Array[Expr])
Map(Array[MapExprEntry])
Unary(UnaryOp, Expr)
Binary(BinaryOp, Expr, Expr)
Conditional(Expr, Expr, Expr)
Select(Expr, String)
Index(Expr, Expr)
Call(String, Array[Expr])
ReceiverCall(Expr, String, Array[Expr])
} derive(Eq, Debug)fn Program::eval(self : Program, activation : Activation, limits? : EvalLimits) -> Value raise EvalErrorInstall
Download zipA pure MoonBit Common Expression Language core with parsing, checking, and deterministic evaluation.