gram/packages/compiler
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-06-14 19:54:26 +02:00
..
src refactor(compiler): use functional routing for AST traversal 2026-06-14 14:18:38 +02:00
tests refactor(compiler): use functional routing for AST traversal 2026-06-14 14:18:38 +02:00
CHANGELOG.md feat: release v.0.10.1 - implement Turborepo & updated dependencies 2026-06-14 19:54:26 +02:00
package.json feat: release v.0.10.1 - implement Turborepo & updated dependencies 2026-06-14 19:54:26 +02:00
README.md docs: Fixed mandatory usage of bun instead of npm 2026-06-14 10:58:02 +02:00
tsconfig.json refactor: Moved source code to new packages folder 2026-01-02 20:16:03 +01:00

@gram/compiler

The compiler for the GRAM recipe language. It takes a typed Recipe AST (produced by @gram/parser) and compiles it into a structured, minified recipe JSON (aggregating shopping lists, processing sections, and calculating Gantt-like timings).


📚 General Documentation

For full syntax specifications, grammar details, cheatsheets, and best practices, please refer to the central GRAM Documentation Index.


🛠️ Installation

Install @gram/compiler via bun:

bun install @gram/compiler

⚡ Usage

const { getAST } = require('@gram/parser');
const { compile } = require('@gram/compiler');

const source = `
## My Recipe
[Mix] @flour{200g} and @water{100ml} for ~{5min}.
`;

const ast = getAST(source);
const result = compile(ast);

console.log(result.shopping_list);
console.log(result.metrics.activeTime); // Timing calculations (in minutes)

🏗️ Structure

  • src/core.ts: The main compiler entry point.
  • src/processor.ts: Processes step-by-step block content, local scopes, and timings.
  • src/shopping.ts: Deduplicates and aggregates ingredients into a master shopping list.
  • src/metrics.ts: Computes baseline active preparation times.
  • src/graph.ts: Traverses relative quantities and runs cycle detection (DFS).
  • src/utils.ts: Includes helpers for string slugification, minification, and time unit conversions.

📄 License

This project is licensed under the GPL-3.0 License.