gram/packages/parser/README.md
abiwab a8f4353a08
All checks were successful
CI / Build & Test (pull_request) Successful in 4m21s
docs: refresh root and package READMEs for v1.5
2026-11-19 12:01:21 +01:00

1.6 KiB

@gram-lang/parser

npm 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 (getAST, GramParseError).
  • src/types.ts: Declares strictly-typed AST node definitions.
  • src/guards.ts: Type guards for AST nodes.
  • src/numbers.ts: Number, mixed fraction, and decimal comma/point parsers.
  • src/schemas.ts: Zod schemas for AST structures.
  • grammar.ohm: The official OhmJS grammar defining the Gram language structure.

📄 License

This project is licensed under the GPL-3.0 License.