All projects
mbs-script

mbs-script

live

A small C++ expression language evaluated against JSON context — embedded in MantisBase for access rules, filters, and dynamic field logic.

cppc++20interpreterjsonparsermantisbaseembedded

What it does

mbs-script is a compact expression language implemented in C++20 and evaluated against an nlohmann::json context. It powers MantisBase's declarative rules — collection access control, filters, and computed logic — without pulling in a full JavaScript runtime for simple expressions.

  • @variable lookups from a JSON context object
  • Arithmetic, comparisons, booleans, string concat, and Python-style "x" * n repeat
  • ^ exponentiation, // line comments, array literals, and method calls (.has(), .len(), etc.)
  • Three entry points: test() for parse/semantic validation, eval_val() for full JSON results, eval_true() for boolean truthiness

Why I built it

MantisBase needed a safe, embeddable way to express dynamic rules inline — something lighter than shipping a JS engine for every @request.auth.id check. A purpose-built evaluator keeps rule evaluation fast, predictable, and easy to validate before runtime.

How it works

  • Core: C++20 library (CMake), returns nlohmann::json values with null for invalid operand combinations
  • Context: @name resolves against a caller-supplied JSON object (request data, record fields, auth claims)
  • API: mbs::test(source), mbs::eval_val(source, context), mbs::eval_true(source, context)
  • Integration: embedded directly in MantisBase as its expression evaluator; standalone repo with Catch2 tests and an example binary

What I learned

Designing a tiny language for config-time rules means choosing strict null semantics over silent coercion — invalid mixes like "a" + 1 return JSON null rather than guessing. Separating test() from eval() lets MantisBase validate rule syntax at save time instead of failing at request time.