Turns .gram source text into a plain-object Abstract Syntax Tree (AST). This is the only stage of the pipeline that can fail on malformed input — every other package trusts that if it received an AST, it’s structurally valid.
Plain character offset into input where the failure occurred.
expected
Description of what the parser expected at that offset.
offset and expected are the portable, structured parts of the failure — useful for editor integrations (squiggly underlines, quick-fixes) that don’t want to parse ohm’s prose.
Every node has a type: ASTNodeType discriminant and an optional loc: { start, end } (character offsets into the source, present on most but not all node types — see the interfaces below).
interface RecipeAST { type: ASTNodeType.Recipe; meta: Meta; // Parsed frontmatter (title, date, tags, densities, ...) imports: ImportDecl[]; // @use directives, always present (empty array with none) — never mixed into children children: (SectionAST | StepAST | CommentAST)[]; // Sections, or top-level steps/comments}interface ImportDecl { type: ASTNodeType.ImportDecl; specifier: string; // e.g. "./bases/pate.gram" bindings: ImportBinding[]; retroPlanning?: RetroPlanningAST | null; // e.g. from `@use "..." as &levain ~{-2d}`}interface ImportBinding { exported: string; // name as exported by the module ("default" for the unbraced `as &name` form) local: string; // name bound in the host recipe loc?: Location;}
See Module Imports for the @use syntax itself, and @gram-lang/modules for resolving and composing an import graph into a single AST.
interface SectionAST { type: ASTNodeType.Section; title: string | null; retroPlanning?: RetroPlanningAST | null; intermediateDecl?: IntermediateDecl | null; children: (StepAST | CommentAST)[]; loc?: Location;}interface RetroPlanningAST { raw: string; // e.g. "-2h", exactly as written sign: 1 | -1; value: number | null; // null if no number could be extracted (e.g. free text) unit: string | null; // null if no unit token was found; otherwise the raw token // as written (kitchen resolves/validates it against d/h/min) loc?: Location; // since 1.5.0: the anchor itself, braces included (`~{-2h}`)}
For ## Puff Pastry ~{-2h}, retroPlanning is { raw: "-2h", sign: -1, value: 2, unit: "h" }. Free text like ~{the day before} still parses (the parser never throws on this — see Times & Scheduling for why), but produces { raw: "the day before", sign: 1, value: null, unit: null }; it’s @gram-lang/kitchen that flags this as invalid (MISSING_UNIT) when compiling.
The remaining node interfaces (CookwareAST, ReferenceAST, TimerAST, TemperatureAST, CheckpointAST, CommentAST, AlternativeAST, IntermediateDecl, TextQuantityAST) follow the same pattern — see packages/parser/src/types.ts for the exhaustive list.