158 lines
12 KiB
Markdown
158 lines
12 KiB
Markdown
<div align="center">
|
|
<img src="gram-logo.png" width="130" alt="Gram Logo" />
|
|
<h1>Gram</h1>
|
|
<p><strong>Code your recipes.</strong></p>
|
|
<p>
|
|
<a href="https://git.gram-lang.org/gram-lang/gram/actions"><img src="https://git.gram-lang.org/gram-lang/gram/actions/workflows/ci.yml/badge.svg?style=flat-square" alt="Build Status" /></a>
|
|
<a href="https://www.npmjs.com/package/@gram-lang/cli"><img src="https://img.shields.io/npm/v/@gram-lang/cli?color=cb3837&logo=npm&style=flat-square" alt="npm Version" /></a>
|
|
<a href="https://marketplace.visualstudio.com/items?itemName=gram-lang.gram-lang"><img src="https://vsmarketplacebadges.dev/version-short/gram-lang.gram-lang.svg?style=flat-square&color=007acc" alt="VS Code Extension" /></a>
|
|
<a href="https://open-vsx.org/extension/gram-lang/gram-lang"><img src="https://img.shields.io/open-vsx/v/gram-lang/gram-lang?label=Open%20VSX&color=a60ee5&style=flat-square" alt="Open VSX Extension" /></a>
|
|
<a href="./LICENSE"><img src="https://img.shields.io/badge/License-GPL_v3-blue?style=flat-square" alt="License" /></a>
|
|
<img src="https://img.shields.io/badge/Made%20in-EU-003399?labelColor=003399&logo=europeanunion&logoColor=FFFFFF&style=flat-square" alt="Made in EU" />
|
|
</p>
|
|
<p>
|
|
An open-source recipe DSL (GPL-3.0) for developers who cook, and for anyone building recipe tooling. Gram compiles plain-text <code>.gram</code> files into strict, deterministic JSON, backed by a CLI, a Language Server (LSP), and editor integrations.
|
|
</p>
|
|
<p>
|
|
<a href="https://gram-lang.org">Website</a> • <a href="https://gram-lang.org/play">Playground</a> • <a href="https://gram-lang.org/docs/">Documentation</a>
|
|
</p>
|
|
<br/>
|
|
<img src="demo.gif" alt="Gram demo: mass standardization, @use imports, and backward ALAP scheduling" style="border-radius: 8px;" />
|
|
</div>
|
|
<br/>
|
|
|
|
> [!NOTE]
|
|
> **Gram** is an independent open-source project. Primary development happens on [Forgejo](https://git.gram-lang.org/gram-lang/gram), with read-only automatic mirrors on [GitHub](https://github.com/gram-lang/gram) and [Codeberg](https://codeberg.org/gram-lang/gram).
|
|
>
|
|
> Issues and pull requests are handled on [Forgejo](https://git.gram-lang.org/gram-lang/gram). See [CONTRIBUTING.md](./CONTRIBUTING.md) if you want to get involved.
|
|
|
|
## Quick example
|
|
|
|
Gram works for simple everyday recipes and shines on technical cooking: baking, pastry, fermentation, shared base recipes, or multi-day prep.
|
|
|
|
```gram
|
|
## Dough ->&dough
|
|
|
|
[Mix] @*bread flour{500g}, @water{70% @&bread flour}, and @salt{2% @&bread flour}.
|
|
|
|
[Ferment] Cold retard for ~_{12-24h} at ^{4°C}.
|
|
|
|
## Bake
|
|
|
|
[Bake] The &dough at ^{250°C}(stone) for ~{6min} until ={blistered}.
|
|
```
|
|
|
|
From those 6 lines, Gram resolves `350g` of water and `10g` of salt from baker's percentages, recalculates every quantity whenever the flour weight changes, separates active work from the `12-24h` cold retard to plan two kitchen visits backward from dinner, estimates nutrition from your local ingredient database, and outputs structured JSON.
|
|
|
|
You can edit live recipes in the browser with no install at [gram-lang.org/play](https://gram-lang.org/play).
|
|
|
|
## What Gram does
|
|
|
|
- **Plain text you own**: recipes live as readable `.gram` files in Git (ingredients, cookware, temperatures, and target states like `={blistered}`), with no cloud, no account, and no proprietary database.
|
|
- **Baker's math and unit ratios**: declare relative percentages (`@water{70% @&flour}`), unit ratios (`@garlic{1 clove / 100g @&beef}`, `~{15min / 500g @&roast}`), and compound quantities (`@flour{1 cup + 2 tbsp}`).
|
|
- **Modular recipes and references**: import base recipes with `@use "./bases/shortcrust.gram" as &crust` (with automatic yield scaling and unified shopping lists), pass intermediate preparations between steps (`->&dough`), and split composite ingredients (`<@lemons{2}`) without double-counting them.
|
|
- **Backward (ALAP) scheduling and run sheets**: separate active steps (`~{35min}`) from passive waits (`~_{12-24h}`). Gram schedules backward from your serving time, stretches range waits to keep active work out of the night, and produces a day-by-day run sheet telling you when to be in the kitchen and what to take out.
|
|
- **100% deterministic, offline core**: parsing, compiling, scaling, scheduling, nutrition analysis, and rendering run locally with no network calls and no AI. Optional AI-assisted commands (`gram import`, `gram db enrich`, `gram db lint`) live only in the CLI and use your own API key.
|
|
|
|
## Tooling
|
|
|
|
### Editors and language server
|
|
|
|
- **VS Code & Open VSX** ([VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=gram-lang.gram-lang) · [Open VSX](https://open-vsx.org/extension/gram-lang/gram-lang) for VSCodium, Cursor, Windsurf, Positron): real-time diagnostics, autocomplete (ingredients from your YAML database, units, `@use` paths), hover info (nutrition, scaled weights, ratios), rename (`F2`), format on save, and side-by-side Live Preview and Run Sheet views.
|
|
- **Neovim, Helix and Zed**: syntax highlighting and queries via [`tree-sitter-gram`](https://git.gram-lang.org/gram-lang/tree-sitter-gram), plus the dedicated [`zed-gram`](https://git.gram-lang.org/gram-lang/zed-gram) extension for Zed.
|
|
- **Standalone LSP** ([`@gram-lang/language-server`](./packages/language-server/README.md)): standard Language Server Protocol server usable from any editor. See the [editors guide](https://gram-lang.org/docs/reference/tooling/editors/) for setup instructions.
|
|
|
|
### CLI (`@gram-lang/cli`)
|
|
|
|
Available on [npm](https://www.npmjs.com/package/@gram-lang/cli), running on Node.js (>=22) or Bun:
|
|
|
|
- `gram check`, `gram format`, `gram build`: validate syntax, format `.gram` files canonically, and compile recipes to JSON.
|
|
- `gram view`, `gram export`, `gram print`: render a recipe or its run sheet (`--view run-sheet`) in the terminal, or export to HTML, Markdown, plain text, and print layout.
|
|
- `gram plan`: schedule a recipe backward from a serving time (`--serve`) within your available hours (`--available`), or find serving times that work (`--find`).
|
|
- `gram cook`: step-by-step terminal cooking mode with live timers and target-state reminders.
|
|
- `gram scale`, `gram diff`, `gram shop`, `gram suggest`: resize recipes, diff versions semantically, aggregate shopping lists across files, and filter recipes by ingredients on hand.
|
|
- `gram db sync` and `gram db validate`: scan recipes for missing entries in `ingredients.yaml` and validate the database offline.
|
|
- `gram import`, `gram db enrich`, and `gram db lint` *(optional, BYOK)*: convert web URLs, JSON-LD files, or YouTube videos into `.gram` files, suggest missing density and nutrition data, or catch duplicates and plural mismatches in `ingredients.yaml` with interactive review before writing.
|
|
|
|
## Try it out
|
|
|
|
### Start a CLI project
|
|
|
|
```bash
|
|
npm install -g @gram-lang/cli
|
|
gram init
|
|
# or with Bun
|
|
bun add -g @gram-lang/cli
|
|
gram init
|
|
```
|
|
|
|
### Use the compiler in JavaScript / TypeScript
|
|
|
|
```javascript
|
|
import { getAST } from '@gram-lang/parser';
|
|
import { compile } from '@gram-lang/kitchen';
|
|
|
|
const ast = getAST('## My Recipe\n\n[Mix] @flour{200g} and @water{100g}.');
|
|
const result = compile(ast);
|
|
|
|
console.log(result.shopping_list);
|
|
```
|
|
|
|
### Run the docs and playground locally
|
|
|
|
Contributing to the monorepo requires [Bun](https://bun.sh) (see [CONTRIBUTING.md](./CONTRIBUTING.md)):
|
|
|
|
```bash
|
|
bun install
|
|
bun run dev
|
|
```
|
|
|
|
## Documentation
|
|
|
|
The full language specification, guides, and CLI reference are at [gram-lang.org/docs/](https://gram-lang.org/docs/) (source in `packages/docs/`).
|
|
|
|
## Project structure
|
|
|
|
| Package | Version | Description |
|
|
|---|---|---|
|
|
| [**`@gram-lang/parser`**](./packages/parser/README.md) | [](https://www.npmjs.com/package/@gram-lang/parser) | Ohm.js parser generating the typed recipe AST. |
|
|
| [**`@gram-lang/modules`**](./packages/modules/README.md) | [](https://www.npmjs.com/package/@gram-lang/modules) | Resolves `@use` imports and composes multi-file recipe ASTs. |
|
|
| [**`@gram-lang/kitchen`**](./packages/kitchen/README.md) | [](https://www.npmjs.com/package/@gram-lang/kitchen) | Compiler turning the AST into compiled recipe JSON. |
|
|
| [**`@gram-lang/scheduler`**](./packages/scheduler/README.md) | [](https://www.npmjs.com/package/@gram-lang/scheduler) | Scheduling engine: backward ALAP timeline, availability projection, and run sheet grouping. |
|
|
| [**`@gram-lang/format`**](./packages/format/README.md) | [](https://www.npmjs.com/package/@gram-lang/format) | Canonical `.gram` source formatter. |
|
|
| [**`@gram-lang/analyzer`**](./packages/analyzer/README.md) | [](https://www.npmjs.com/package/@gram-lang/analyzer) | Mass standardization, yield metrics, nutrition estimation, and semantic recipe diffing. |
|
|
| [**`@gram-lang/renderer`**](./packages/renderer/README.md) | [](https://www.npmjs.com/package/@gram-lang/renderer) | Display layer: recipe and run sheet views in HTML, Markdown, plain text, and print. |
|
|
| [**`@gram-lang/cli`**](./packages/cli/README.md) | [](https://www.npmjs.com/package/@gram-lang/cli) | Command-line interface (`gram`). |
|
|
| [**`@gram-lang/i18n`**](./packages/i18n/README.md) | [](https://www.npmjs.com/package/@gram-lang/i18n) | Unit normalization, duration parsing, and EN/FR localization. |
|
|
| [**`@gram-lang/language-server`**](./packages/language-server/README.md) | [](https://www.npmjs.com/package/@gram-lang/language-server) | Language Server Protocol implementation. |
|
|
| [**`vscode-extension`**](./packages/vscode-extension/README.md) | [](https://marketplace.visualstudio.com/items?itemName=gram-lang.gram-lang) | Visual Studio Code extension. |
|
|
| [**`docs`**](./packages/docs/README.md) | - | Astro/Starlight documentation site and browser playground. |
|
|
|
|
## Development, testing and roadmap
|
|
|
|
Every push and pull request runs through **Forgejo Actions**:
|
|
|
|
- **Linting and formatting**: Biome (`bun run lint`).
|
|
- **Typechecking**: across the monorepo (`bun run typecheck`).
|
|
- **Unit tests**: per-package suites (`bun test`).
|
|
- **Conformance suite**: language-agnostic golden tests (`bun run conformance`) pinning AST, compiled JSON, and analyzed JSON outputs.
|
|
- **Deterministic fuzzer**: property-based fuzzing across the parser, compiler, analyzer, linter, and formatter (`bun run fuzz`).
|
|
|
|
### TypeScript today, Rust next
|
|
|
|
Gram started in TypeScript, and keeping a single implementation while the language still evolves makes iteration fast and lets the full compiler run natively in the browser playground. A Rust port of the core (`parser`, `kitchen`, `analyzer`, `i18n`) is planned once the spec settles: the language-agnostic conformance suite and `tree-sitter-gram` are already in place so the transition can happen without breaking JSON contracts or npm packages.
|
|
|
|
## Acknowledgments
|
|
|
|
- **[Cooklang](https://cooklang.org)**: for pioneering plain-text recipe markup and inspiring Gram's initial syntax.
|
|
- **[Ohm.js](https://ohmjs.org)**: for a readable PEG grammar that is pleasant to iterate on.
|
|
- **AI coding tools**: Used throughout development to build and maintain the codebase, checked by the conformance suite, fuzzer, and CI tests.
|
|
|
|
## Community and support
|
|
|
|
- **Bugs and feature requests**: open an issue on [Forgejo](https://git.gram-lang.org/gram-lang/gram/issues).
|
|
- **Discussions**: there is a [Discord server](https://discord.gg/nsCBkhjuAR) and [r/gramlang](https://www.reddit.com/r/gramlang/) for questions, recipes, and feedback.
|
|
|
|
## License
|
|
|
|
Gram is licensed under the [GPL-3.0](./LICENSE) license. Recipes you write in `.gram` belong entirely to you.
|