Skip to content

zane-lang/zane-cpp

Repository files navigation

zane-cpp

zane-cpp is a small header-only C++20 helper library for writing C++ in a style that feels closer to the Zane language spec. Version 0.1.0 focuses on a tiny, polished surface instead of trying to emulate the whole language.

Spec target

zane-cpp is currently aligned with a1921dd.

The pinned spec checkout lives in third_party/zane-spec/, and docs/design.md documents mappings and tradeoffs relative to that revision.

Under that spec revision, Zane structs are transitively value-only: they may contain primitives and other structs, but they must not contain classes or refs anywhere in their nested field graph. In this repository, zane::ref<T> examples therefore model Zane class-style storage or general C++ storage, not a Zane struct analogue.

What v0.1 implements

  • zane::ref<T> for explicit non-owning, rebindable references
  • zane::abortable<T, E> plus resolve, handle, and then for Zane-inspired bifurcated return flows without exceptions
  • zane::pipe(...) for pipeline-style expression chaining
  • zane::Array<N, T> and zane::array(...) for fixed-size array values
  • zane::unit / zane::void_value for payload-free success values

See docs/design.md for the full spec-to-C++ mapping, tradeoffs, and planned or rejected ideas.

Single-header usage

The distributable header is:

#include <zane-cpp.hpp>

The modular source root used to generate it is:

include-src/zane/prelude.hpp

Minimal example

#include <zane-cpp.hpp>
#include <string_view>

struct ParseError {
    std::string_view message;
};

auto parse_scale(std::string_view text) -> zane::abortable<int, ParseError> {
    if (text == "high") {
        return zane::abortable<int, ParseError>::success(3);
    }
    return zane::abortable<int, ParseError>::abort({"expected \"high\""});
}

int main() {
    auto value = parse_scale("low")
        | zane::pipe([](auto result) {
            return zane::handle(std::move(result), [](const ParseError&) {
                return 0;
            });
        });

    auto refs = zane::array(1, 2, 3);
    return value + refs[0];
}

A runnable example lives at examples/zane_like.cpp.

Development workflow

Build the single header

devbox run -- just build-header

Exact Quom invocation:

devbox run -- python -m quom --include_directory include-src include-src/zane/prelude.hpp include/zane-cpp.hpp

Run tests

devbox run -- just test

The test suite compiles and runs two binaries:

  • one against the modular root header from include-src/
  • one against the generated include/zane-cpp.hpp single header

Run the full check suite

devbox run -- just check

just check rebuilds the single header, runs the tests, and compiles plus runs the example program.

Repository layout

include-src/zane/     modular headers
include/zane-cpp.hpp  generated distributable header
tests/                offline-friendly test harness and coverage
examples/             example programs
docs/design.md        spec-driven design notes and decisions
third_party/zane-spec pinned spec submodule

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Generated from zane-lang/.github