gram/packages/parser
Repository files (latest commit first)
Filename Latest commit message Latest commit date
abiwab 2b5ae73f33
All checks were successful
CI / Build & Test (pull_request) Successful in 7m22s
chore: release v1.5.2
2026-11-27 23:06:21 +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): keep a colon followed by blanks alone as text, not an empty alias 2026-11-26 18:07:52 +01:00
syntaxes fix(parser): color a temperature's name like a timer's in the TextMate grammar 2026-11-25 11:27:15 +01:00
tests fix(parser): keep a colon followed by blanks alone as text, not an empty alias 2026-11-26 18:07:52 +01:00
CHANGELOG.md chore: release v1.5.2 2026-11-27 23:06:21 +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): keep a colon followed by blanks alone as text, not an empty alias 2026-11-26 18:07:52 +01:00
package.json chore: release v1.5.2 2026-11-27 23:06:21 +01:00
README.md docs: refresh root and package READMEs for v1.5 2026-11-19 12:01:21 +01:00
tsconfig.json refactor: Moved source code to new packages folder 2026-01-02 20:16:03 +01:00

@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.