Gram Logo

Gram

Code your recipes.

Build Status NPM Version VS Code Extension Open Source License Made in Europe

An open-source declarative and computational recipe DSL. Built to handle complex culinary logic, Gram compiles your plain-text instructions into structured, calculated, and relational data.

Website • Playground • Documentation


Gram Playground Screenshot

> [!NOTE] > I develop **Gram** on my primary [Forgejo instance](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). Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for more information on how to get involved. --- ## Design Philosophy & Key Features Gram turns plain-text recipes into structured, queryable data while keeping them easy to read and write. * **Plain Text**: Recipes are saved as simple `.gram` text files, so you can track changes with Git and use any text editor. * **Modular Recipes (`@use`)**: Import and compose external base recipes (`@use "./bases/shortcrust.gram" as &crust`) with automatic yield scaling, timeline interleaving, and unified shopping lists. * **Dynamic Calculations**: Declare Baker's percentages, relative quantities (`@water{75% @&flour}`), unit ratios (`@garlic{1 clove / 100g @&beef}`, `~{15min / 500g @&roast}`), compound quantities (`@flour{1 cup + 2 tbsp}`), and automatic unit conversions directly in your recipe. * **Step References & Variables**: Reuse intermediate preparations (`->&dough`) and sub-ingredients (`<@lemons{2}`) without messing up shopping list totals. * **Timers & Run Sheet**: Separate active steps (`~{1h 30min}`, `5'30"`) from background waiting times (`~_{2h}`). Gram computes your schedule backward from service, tells you when to be in the kitchen and what to take out, and stretches range waits (`~_{8-16h}`) to keep your work out of the night. * **Cooking Cues**: Specify temperatures with mode or equipment notes (`^{450°F}(convection)`) and mark sensory target states (`={golden brown}`), surfaced in views and live cooking reminders. * **Developer Tooling**: Includes a Language Server (LSP), a VS Code extension with real-time diagnostics and live preview, a CLI tool, and a TypeScript API. --- ## Quick Syntax Gram reads like natural language but compiles like code. ```gram --- title: Artisanal Bread makes: '2 loaves' description: A simple, highly hydrated dough. --- ## Dough [Mix] @flour{500g}, @water{70% @&flour}, and @salt{10g} in a #bowl(large). ->&dough [Rest] Let the &dough rest for ~_{1h 30min} at ^{room temperature} until ={doubled in size}. ## Baking [Preheat] The #oven to ^{450°F}(convection). [Bake] The &dough for ~{35min} until ={deeply golden}. ``` --- ## Tooling Gram comes with tools to help write, inspect, and compile recipes. ### VS Code Extension & Language Server [**`Gram - Recipe Language` on the VS Code Marketplace**](https://marketplace.visualstudio.com/items?itemName=gram-lang.gram-lang) - **Live Preview & Run Sheet**: Side-by-side recipe rendering and the run sheet of the recipe (days, visits to the kitchen, what to take out), with the serving time, scale, and view settings (mise en place, rests, comments...) one click away. - **Autocomplete & Refactoring**: Contextual suggestions for ingredients from your database, units, and `@use` imports, plus cross-reference rename (`F2`) and hover info for nutrition, scaled quantities, and ratios. - **Diagnostics & Formatting**: Real-time error checking for missing ingredients, unused references, or circular dependencies, and canonical formatting on save. ### CLI (`@gram-lang/cli`) [**View on npmjs**](https://www.npmjs.com/package/@gram-lang/cli) - **`gram check`, `gram format` & `gram build`**: Validate syntax, format `.gram` files canonically, and compile recipes to JSON. - **`gram cook`**: Step-by-step cooking assistant in your terminal with live timers and target-state reminders. - **`gram view`**: Read a recipe in the terminal, in your language, with the same settings as the editor and the playground (`--mise-en-place`, `--rests`, `--comments`...). - **`gram plan`**: Plan a recipe: the days of work, the visits to the kitchen and what to take out, backward from a serving time (`--serve`) within your hours (`--available`), or find the serving times that work (`--find`). - **`gram export` & `gram print`**: Write the recipe or its run sheet (`--view run-sheet`) as HTML, Markdown or text, or in a print layout. - **`gram scale`**: Resize recipes (e.g., `--scale=2` or `--scale flour=300g`) with before/after comparison tables. - **`gram diff`**: Semantic diff to compare quantities, timings, temperatures, or target states between recipe versions. - **`gram shop`**: Generate aggregated shopping lists across multiple recipes (including structured `--format json` output). - **`gram suggest`**: Find recipes based on available ingredients (e.g., `--with "butter, eggs"`). - **`gram import`**: Convert recipes from web URLs, local JSON-LD files, or YouTube videos into `.gram` files via AI. ### Database Tooling (`gram db`) Commands to maintain your `ingredients.yaml` file: - **`gram db sync`**: Scan recipes and add missing ingredients to your database. - **`gram db enrich`**: Fill in missing density and nutrition data from AI suggestions, with an interactive review before anything is written. - **`gram db lint`**: Find duplicates (e.g., `scallion` vs `green onion`) and fix plural inconsistencies. --- ## Documentation The full technical documentation is available online: [**https://gram-lang.org/docs/**](https://gram-lang.org/docs/) The source code for the Astro & Starlight documentation can be found locally in `packages/docs/`. --- ## Project Structure This monorepo is divided into specialized packages under `packages/`: | Package | Version | Description | |---|---|---| | [**`@gram-lang/parser`**](./packages/parser/README.md) | [![npm](https://img.shields.io/npm/v/@gram-lang/parser?color=cb3837&style=flat-square)](https://www.npmjs.com/package/@gram-lang/parser) | The core parser using Ohm.js to generate the AST. | | [**`@gram-lang/modules`**](./packages/modules/README.md) | [![npm](https://img.shields.io/npm/v/@gram-lang/modules?color=cb3837&style=flat-square)](https://www.npmjs.com/package/@gram-lang/modules) | Resolves `@use` imports and composes multi-file recipe ASTs. | | [**`@gram-lang/kitchen`**](./packages/kitchen/README.md) | [![npm](https://img.shields.io/npm/v/@gram-lang/kitchen?color=cb3837&style=flat-square)](https://www.npmjs.com/package/@gram-lang/kitchen) | The compiler logic, transforming the AST into final JSON structures. | | [**`@gram-lang/scheduler`**](./packages/scheduler/README.md) | [![npm](https://img.shields.io/npm/v/@gram-lang/scheduler?color=cb3837&style=flat-square)](https://www.npmjs.com/package/@gram-lang/scheduler) | The scheduling engine: lays a recipe's tasks out on a timeline and places it on the calendar from a serving time and your availability. | | [**`@gram-lang/format`**](./packages/format/README.md) | [![npm](https://img.shields.io/npm/v/@gram-lang/format?color=cb3837&style=flat-square)](https://www.npmjs.com/package/@gram-lang/format) | Canonical `.gram` source code formatter. | | [**`@gram-lang/analyzer`**](./packages/analyzer/README.md) | [![npm](https://img.shields.io/npm/v/@gram-lang/analyzer?color=cb3837&style=flat-square)](https://www.npmjs.com/package/@gram-lang/analyzer) | The physical resolver for mass normalization, yield, and nutrition. | | [**`@gram-lang/renderer`**](./packages/renderer/README.md) | [![npm](https://img.shields.io/npm/v/@gram-lang/renderer?color=cb3837&style=flat-square)](https://www.npmjs.com/package/@gram-lang/renderer) | The display layer: the views of a recipe and its run sheet, in HTML, Markdown, text and print. | | [**`@gram-lang/cli`**](./packages/cli/README.md) | [![npm](https://img.shields.io/npm/v/@gram-lang/cli?color=cb3837&style=flat-square)](https://www.npmjs.com/package/@gram-lang/cli) | The official command-line interface. | | [**`@gram-lang/i18n`**](./packages/i18n/README.md) | [![npm](https://img.shields.io/npm/v/@gram-lang/i18n?color=cb3837&style=flat-square)](https://www.npmjs.com/package/@gram-lang/i18n) | Localization layer for units, categories, and AI prompts. | | [**`vscode-extension`**](./packages/vscode-extension/README.md) | [![VS Code Marketplace](https://vsmarketplacebadges.dev/version-short/gram-lang.gram-lang.svg?style=flat-square&color=007acc)](https://marketplace.visualstudio.com/items?itemName=gram-lang.gram-lang) | The Visual Studio Code extension. | | [**`@gram-lang/language-server`**](./packages/language-server/README.md) | [![npm](https://img.shields.io/npm/v/@gram-lang/language-server?color=cb3837&style=flat-square)](https://www.npmjs.com/package/@gram-lang/language-server) | The LSP providing autocomplete and diagnostics. | | [**`docs`**](./packages/docs/README.md) | - | The documentation website, which includes the web-based Playground IDE. | --- ## Development & CI Gram uses **Forgejo Actions** to maintain the stability of the language and its tooling. On every push and pull request, the CI pipeline automatically runs: - **Linting & Formatting**: Enforced by Biome (`bun run lint`). - **Typechecking**: Across the entire TypeScript monorepo (`bun run typecheck`). - **Unit Tests**: For isolated component logic (`bun test`). - **Conformance Tests**: A custom suite of golden tests (`bun run conformance`) that ensures the parser and compiler produce stable, byte-for-byte identical AST and JSON outputs for any given `.gram` input. --- ## Try it out ### 1. Start a CLI Project Get started with Gram directly in your terminal: ```bash npm install -g @gram-lang/cli gram init # or, with Bun bun add -g @gram-lang/cli gram init ``` The CLI runs on both Node.js (>=22) and Bun — pick whichever you already have installed. ### 2. Run the Docs & Playground locally **Note**: contributing to this monorepo (building every package, running the test suite, the docs dev server) requires `Bun` — see [CONTRIBUTING.md](./CONTRIBUTING.md). ```bash # Install dependencies for all packages bun install # Build packages and start the docs dev server bun run dev ``` ### 3. Use the Parser in your App ```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); ``` --- ## Acknowledgments Gram stands on the shoulders of giants. * **[Cooklang](https://cooklang.org)**: For pioneering the concept of plain-text recipe markup and authoring. Gram was heavily inspired by their concise syntax. * **[Ohm.js](https://ohmjs.org)**: For making parsing accessible and incredibly robust. * **LLM Assistance**: This project was developed with the assistance of AI for rapid prototyping, refactoring, and generating test cases. All logic and architecture were strictly verified by humans. --- ## Community & Support - **Bugs & Feature Requests**: Please use our primary [Forgejo issues](https://git.gram-lang.org/gram-lang/gram/issues). - **Chat & Discussions**: Join us on [Discord](https://discord.gg/nsCBkhjuAR) or visit [r/gramlang](https://www.reddit.com/r/gramlang/) for casual community discussions. --- ## License Distributed under the GPL-3.0 License.