API Stability Notice

Macroforge is under active development. The API is not yet stable and may change between versions. Some documentation sections may be outdated.

Declarative Macros

Declarative macros let you define compile-time code transformations entirely in TypeScript, using pattern-matching syntax inspired by Rust’s macro_rules!. No Rust toolchain is involved — the macro lives in the same .ts file that uses it.

import { macroRules } from "macroforge/rules";

const $double = macroRules`
  ($x:Expr) => ($x) * 2
`;

const four = $double(2); // → (2) * 2

They run as a pre-pass, before attribute and derive macros, so a declarative macro can expand into code that later macros then process.

Full documentation

This page is a conceptual overview. The complete reference lives in its own section: