Skip to content

Hermetic .NET Starlark interpreter with extensible host APIs, powered by Lokad.Parsing and a focused conformance suite

License

Notifications You must be signed in to change notification settings

Lokad/Starklark

Repository files navigation

Lokad.Starlark

Lokad.Starlark is a .NET implementation of the Starlark language with a hermetic core runtime and a host extension model. The interpreter targets net8.0 and net10.0, uses Lokad.Parsing for the parser, and ships with a portable conformance suite derived from the Bazel Starlark tests.

Planned NuGet package name: Lokad.Starlark (unpublished for now).

Usage

using Lokad.Starlark;
using Lokad.Starlark.Runtime;

var interpreter = new StarlarkInterpreter();
var environment = new StarlarkEnvironment();

environment.AddFunction(
    "add",
    (args, kwargs) =>
    {
        var left = (StarlarkInt)args[0];
        var right = (StarlarkInt)args[1];
        return new StarlarkInt(left.Value + right.Value);
    },
    isBuiltin: true);

interpreter.ExecuteModule(
    "result = add(2, 3)",
    environment);

Conformance Tests

Conformance scripts live under tests/Lokad.Starlark.Tests/TestData/Conformance, split into go, java, and rust subsets. Each file contains multiple cases separated by ---, and error expectations are annotated with ### (regex) on the failing statement.

Run the full suite with:

dotnet test --tl:off --nologo -v minimal

CLI Demo

The CLI is a local demo utility (not packaged in the NuGet) with two modes: a hermetic REPL and a script runner. It injects a print helper to demonstrate host extensibility. The exec command runs inline source for quick experiments and fuzzing.

Start the REPL:

dotnet run --project tools/Lokad.Starlark.Cli -- repl

Run a script file:

dotnet run --project tools/Lokad.Starlark.Cli -- run path\to\script.star

Run inline source:

dotnet run --project tools/Lokad.Starlark.Cli -- exec "print(1 + 2)"

About

Hermetic .NET Starlark interpreter with extensible host APIs, powered by Lokad.Parsing and a focused conformance suite

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published