fix(parser): accept dotted unit abbreviations and reject malformed quantities #36

Merged
abiwab merged 3 commits from fix/parser-unit-abbreviations into main 2026-09-29 11:16:56 +02:00
Owner

Closes #24

Problem

{1/2 c.à.s} and {1 c.à.c} (the examples in the French reference) did not parse. The failure was silent: the quantity was dropped, the name was truncated to its first word, and distinct ingredients merged into one shopping-list entry.

Changes

  • Parser: a unit is now one or more words; dots and apostrophes are allowed inside a word (c.à.s, c. à s., fl. oz.) but never at its start.
  • Parser: a {...} glued to an ingredient, composite parent, cookware, reference or timer that is not a valid quantity is now a GramParseError pointing at the brace, instead of silently falling back to the bare form. Temperature text quantities are unchanged.
  • i18n: normalizeUnit falls back to a spelling-insensitive key (case, accents, dots, apostrophes, spaces), so c.à.s, c.a.s and càs all resolve to tbsp. Unknown units are still returned as written. A test guards against alias collisions.
  • Tests: parser, i18n, kitchen (shopping list), language server (diagnostic on the brace), plus conformance cases 031, err-012, err-013. No existing golden changed.
  • Docs (separate commit): units section and error handling, FR and EN.

Behavior change

Quantities that were silently ignored before are now errors, hence a minor changeset. All tracked .gram files in the repo still parse.

Verification

bun run build, bun test, bun run conformance, bun run lint, bun run typecheck all pass. Checked the error in gram check, the language server diagnostic and the playground.

Closes #24 ## Problem `{1/2 c.à.s}` and `{1 c.à.c}` (the examples in the French reference) did not parse. The failure was silent: the quantity was dropped, the name was truncated to its first word, and distinct ingredients merged into one shopping-list entry. ## Changes - **Parser**: a unit is now one or more words; dots and apostrophes are allowed inside a word (`c.à.s`, `c. à s.`, `fl. oz.`) but never at its start. - **Parser**: a `{...}` glued to an ingredient, composite parent, cookware, reference or timer that is not a valid quantity is now a `GramParseError` pointing at the brace, instead of silently falling back to the bare form. Temperature text quantities are unchanged. - **i18n**: `normalizeUnit` falls back to a spelling-insensitive key (case, accents, dots, apostrophes, spaces), so `c.à.s`, `c.a.s` and `càs` all resolve to `tbsp`. Unknown units are still returned as written. A test guards against alias collisions. - **Tests**: parser, i18n, kitchen (shopping list), language server (diagnostic on the brace), plus conformance cases `031`, `err-012`, `err-013`. No existing golden changed. - **Docs** (separate commit): units section and error handling, FR and EN. ## Behavior change Quantities that were silently ignored before are now errors, hence a `minor` changeset. All tracked `.gram` files in the repo still parse. ## Verification `bun run build`, `bun test`, `bun run conformance`, `bun run lint`, `bun run typecheck` all pass. Checked the error in `gram check`, the language server diagnostic and the playground.
Merge branch 'main' into fix/parser-unit-abbreviations
All checks were successful
CI / Build, Test & Publish (pull_request) Successful in 2m49s
bd6dc12e71
abiwab merged commit 801d9bea91 into main 2026-09-29 11:16:56 +02:00
abiwab deleted branch fix/parser-unit-abbreviations 2026-09-29 11:16:56 +02:00
Sign in to join this conversation.
No description provided.