gram/packages/parser
Repository files (latest commit first)
Filename Latest commit message Latest commit date
abiwab 7d67ccadaf
All checks were successful
CI / Build & Test (pull_request) Successful in 9m18s
chore: release v1.6.0
2026-12-01 14:38:56 +01:00
..
scripts feat(parser): ship a plist TextMate grammar for Sublime Text 2026-11-24 16:47:00 +01:00
src fix(parser): read YAML quote escapes in frontmatter values 2026-12-01 13:41:37 +01:00
syntaxes fix(parser): stop highlighting an alias written after a blank in TextMate 2026-11-29 19:49:50 +01:00
tests fix(parser): read YAML quote escapes in frontmatter values 2026-12-01 13:41:37 +01:00
CHANGELOG.md chore: release v1.6.0 2026-12-01 14:38:56 +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): read a colon followed by a blank as punctuation, not an alias 2026-11-27 21:35:27 +01:00
package.json chore: release v1.6.0 2026-12-01 14:38:56 +01:00
README.md docs: rewrite root and package READMEs for v1.6 2026-11-29 22:35:50 +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

Part of the Gram monorepo · Documentation

Ohm.js parser for the Gram recipe DSL. Strictly limited to converting .gram source text into a typed Recipe AST.

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: 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: Ohm.js grammar defining the Gram language syntax.

License

Licensed under the GPL-3.0 license.