gram/packages/parser
Repository files (latest commit first)
Filename Latest commit message Latest commit date
abiwab c1310da3f7
All checks were successful
CI / Build & Test (pull_request) Successful in 5m21s
chore: release v1.4.2
2026-11-17 15:33:12 +01:00
..
scripts refactor: migrate project to ESM, upgrade to TS 6.0, and unify type definitions across packages 2026-06-18 13:11:36 +02:00
src fix(parser): end a preparation at the end of its line 2026-11-16 23:46:13 +01:00
syntaxes fix(parser): highlight multi-line @use import bindings correctly 2026-08-21 23:33:44 +02:00
tests fix(parser): end a preparation at the end of its line 2026-11-16 23:46:13 +01:00
CHANGELOG.md chore: release v1.4.2 2026-11-17 15:33:12 +01:00
expected_JSON.json chore: Replaced GRAM with Gram accross all files 2026-07-05 16:57:42 +02:00
grammar.ohm fix(parser): end a preparation at the end of its line 2026-11-16 23:46:13 +01:00
package.json chore: release v1.4.2 2026-11-17 15:33:12 +01:00
README.md chore: preparing for v1 release 2026-08-06 10:40:53 +02:00
tsconfig.json refactor: Moved source code to new packages folder 2026-01-02 20:16:03 +01:00

@gram-lang/parser

npm version License: GPL v3

A robust, 3-stage parser for the Gram recipe language. It is part of the Gram monorepo and is strictly limited to text-to-AST parsing.


📚 General Documentation

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


🛠️ Installation

npm install @gram-lang/parser
# or
bun add @gram-lang/parser

⚡ Usage

The package exports getAST() to convert Gram source strings into a typed Recipe AST.

import { getAST } from '@gram-lang/parser';

const source = `
## My Recipe
Mix @flour{200g} and @water{100ml}.
`;

try {
    const ast = getAST(source);
    console.log(JSON.stringify(ast, null, 2));
} catch (e) {
    console.error("Parsing error:", e.message);
}

🏗️ Structure

  • src/index.ts: Orchestrates parsing and Ohm Semantics to AST conversions.
  • src/types.ts: Declares strictly-typed AST node definitions.
  • grammar.ohm: The official OhmJS grammar defining the Gram language structure.

📄 License

This project is licensed under the GPL-3.0 License.