Skip to content

akelsh/coda

Build Test

Coda

Coda is a statically typed configuration language that compiles to JSON.

The pitch

JSON is flexible but it is not a programming language. It cannot express logic, reuse, or constraints without external tooling. Coda exists to replace ad-hoc JSON generation with a small, typed language that produces plain JSON as output. The inputs are readable source files and the output is standard JSON that fits into existing tooling.

This project focuses on a simple compiler pipeline, predictable evaluation, and diagnostics that point to exact source spans. It is intentionally minimal and does not aim to be a general-purpose language.

Example

#= minimal example =#

type server
{
    id: int;
    name: string;
    tags: [string];
}

fn make_server(id: int, env: string) -> server
{
    server {
        id = id,
        name = "srv-" + env + "-" + string(id),
        tags = ["coda", env]
    }
}

mutable var servers: [server] = [];
mutable var i = 1;

while i <= 3
{
    servers.push(make_server(i, "prod"));
    i = i + 1;
}

emit { "infrastructure" = servers };
  • type defines a structural type.
  • fn defines a function with an explicit return type.
  • if, while, and return behave as in most expression-based languages.
  • emit produces the JSON output for the program.

A formal writeup of the syntax is in the works.

Architecture

Coda runs a multi-pass pipeline:

  1. Parse: build an unbound AST
  2. Collect: collect top-level symbols
  3. Bind: bind symbol references
  4. Type-check: validate types and constraints
  5. Evaluate: execute and collect emissions

All passes run inside the coda executable. The current implementation is a tree-walking interpreter. The pipeline is explicit, and each pass is a separate component, which makes it easy to reason about correctness and error reporting.

coda-pipeline

Build and run

Use the CMake presets. Debug presets are for local development.

cmake --list-presets
# macOS/Linux (clang)
cmake --preset unixlike-clang-debug
cmake --build --preset unixlike-clang-debug
./out/build/unixlike-clang-debug/src/coda path/to/file.coda
# macOS/Linux (gcc)
cmake --preset unixlike-gcc-debug
cmake --build --preset unixlike-gcc-debug
./out/build/unixlike-gcc-debug/src/coda path/to/file.coda
# Windows (MSVC)
cmake --preset windows-msvc-debug-developer-mode
cmake --build --preset windows-msvc-debug-developer-mode
out\build\windows-msvc-debug-developer-mode\src\coda.exe path\to\file.coda

Output defaults to stdout. Write to a file with -o:

./out/build/unixlike-clang-debug/src/coda path/to/file.coda -o output.json

Show the version:

./out/build/unixlike-clang-debug/src/coda --version

Tests

ctest --preset test-unixlike-clang-debug

The snapshot test executor uses Catch2. Fixtures live in test/fixtures.

Contributing

See CONTRIBUTING.md for local setup, style, and PR guidance.

About

A statically-typed configuration language that generates JSON.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors