[Parser] {1 c.à.s} and {1 c.à.c} from the French docs silently drop the quantity and merge distinct ingredients #24

Closed
opened 2026-08-31 21:42:24 +02:00 by Nopitch · 1 comment

Version: @gram-lang/cli 1.2.1 (current npm latest), on macOS.

Summary

The two spoon units shown as examples in the French reference do not parse, and the failure is completely silent: the quantity is discarded, a multi-word name is truncated to its first word, and — because several names truncate to the same first word — distinct ingredients are merged into a single entry. gram check reports the file as valid.

Reproduction

/fr/docs/reference/syntax/ingredients/ gives {1/2 c.à.s} and {1 c.à.c} as examples.

---
title: FR
---

## T

A @sucre a{1/2 c.à.s} B @sucre b{1 c.à.c} C @sucre c{1 c. à s.} D @sucre d{1 c.à.s.} E @sucre e{1 c.a.s} F @sucre f{1 càs}
$ gram check fr.gram --skip-db
1 file valid.

gram build fr.gram --pretty --skip-db yields two ingredients where six were written:

sucre     name='sucre'    qty=(None, None)     <- a, b, c, d and e all collapsed here
sucre-f   name='sucre f'  qty=(1, 'càs')       <- only this one survived

Only càs (no periods) parses. The merging is the part I find most concerning: five ingredients that differ only past their first word become one entry, so a shopping list can silently under-report while the recipe still reads correctly on screen.

Scope

The problem is confined to the unit token inside {}. Periods are fine in ingredient names and in numbers:

@St.Môret{100g}      -> name 'St.Môret',      qty 100 g     ok
@huile d'olive{15g}  -> name "huile d'olive", qty 15 g      ok
@lait 1.5%{200ml}    -> name 'lait 1.5%',     qty 200 ml    ok

and the English reference lists 1.5-2l as a valid quantity. Spaces are not the trigger either — {1 gousse}, {2 cuillères à soupe}, {1 c à s}, {15 ml} all parse. Gram accepts arbitrary strings as units ({1 cas} yields unit: "cas"), so this looks less like a missing @gram-lang/i18n dictionary entry than a character-class restriction on the unit token.

What I would expect, in decreasing order of ambition

  1. Emit a warning when a quantity fails to parse. There is already a taxonomy with MISSING_UNIT and INVALID_UNIT, and ^{200} correctly raises MISSING_UNIT. An ingredient quantity failing silently seems inconsistent with that.
  2. Never truncate a name or merge distinct ingredients as a side effect of a failed quantity parse. Conflating two ingredients is worse than rejecting the file.
  3. Make c.à.s / c.à.c parse as the French documentation shows — or correct that page, whichever you consider right. I am not asking for a specific outcome: if a grammar change counts as a syntax modification under CONTRIBUTING, I will open a Syntax proposal (RFC) instead and leave this issue scoped to points 1 and 2.

The first two matter most.

Separately, and much smaller: a documentation error about &

The same page states:

« Les noms d'@ingrédient peuvent contenir des caractères spéciaux (comme ', &, .), à l'exception des délimiteurs de syntaxe réservés ({, }, :, (, ), <, |). »

' and . do work. & cannot, because it is the reference sigil — and gram handles that correctly. Writing @sel & poivre{2g} produces an ingredient sel plus a typed reference node, with the quantity preserved:

{ "type": "reference", "id": "poivre", "name": "poivre", "qty": 2, "unit": "g" }

and a proper diagnostic with a code and a source location:

"warnings": [{ "code": "UNDEFINED_REFERENCE",
               "message": "Undefined reference '&poivre' — no prior step or section produces this item.",
               "item": "poivre", "loc": { "start": 74, "end": 86 } }]

gram check refuses the file. Nothing is lost and everything is reported — this is the behaviour I would want. The only thing wrong here is the documentation, which should drop & from that list of permitted characters. Mentioning it only because it sits in the same sentence of the same page as the units above.

Where this probably lives

Going by the pipeline in CONTRIBUTING: the parse failure looks like packages/parser (grammar.ohm, unit token character class), while the absence of a diagnostic would be packages/kitchen, described as the stage that emits warnings.


Drafted with AI assistance, verified by hand: every reproduction above was run locally against 1.2.1 and its output pasted verbatim.

**Version:** `@gram-lang/cli` 1.2.1 (current npm `latest`), on macOS. ## Summary The two spoon units shown as examples in the French reference do not parse, and the failure is completely silent: the quantity is discarded, a multi-word name is truncated to its first word, and — because several names truncate to the same first word — distinct ingredients are merged into a single entry. `gram check` reports the file as `valid`. ## Reproduction `/fr/docs/reference/syntax/ingredients/` gives `{1/2 c.à.s}` and `{1 c.à.c}` as examples. ```gram --- title: FR --- ## T A @sucre a{1/2 c.à.s} B @sucre b{1 c.à.c} C @sucre c{1 c. à s.} D @sucre d{1 c.à.s.} E @sucre e{1 c.a.s} F @sucre f{1 càs} ``` ``` $ gram check fr.gram --skip-db 1 file valid. ``` `gram build fr.gram --pretty --skip-db` yields **two** ingredients where six were written: ``` sucre name='sucre' qty=(None, None) <- a, b, c, d and e all collapsed here sucre-f name='sucre f' qty=(1, 'càs') <- only this one survived ``` Only `càs` (no periods) parses. The merging is the part I find most concerning: five ingredients that differ only past their first word become one entry, so a shopping list can silently under-report while the recipe still reads correctly on screen. ## Scope The problem is confined to the **unit token** inside `{}`. Periods are fine in ingredient names and in numbers: ``` @St.Môret{100g} -> name 'St.Môret', qty 100 g ok @huile d'olive{15g} -> name "huile d'olive", qty 15 g ok @lait 1.5%{200ml} -> name 'lait 1.5%', qty 200 ml ok ``` and the English reference lists `1.5-2l` as a valid quantity. Spaces are not the trigger either — `{1 gousse}`, `{2 cuillères à soupe}`, `{1 c à s}`, `{15 ml}` all parse. Gram accepts arbitrary strings as units (`{1 cas}` yields `unit: "cas"`), so this looks less like a missing `@gram-lang/i18n` dictionary entry than a character-class restriction on the unit token. ## What I would expect, in decreasing order of ambition 1. **Emit a warning when a quantity fails to parse.** There is already a taxonomy with `MISSING_UNIT` and `INVALID_UNIT`, and `^{200}` correctly raises `MISSING_UNIT`. An ingredient quantity failing silently seems inconsistent with that. 2. **Never truncate a name or merge distinct ingredients** as a side effect of a failed quantity parse. Conflating two ingredients is worse than rejecting the file. 3. Make `c.à.s` / `c.à.c` parse as the French documentation shows — **or** correct that page, whichever you consider right. I am not asking for a specific outcome: if a grammar change counts as a syntax modification under CONTRIBUTING, I will open a Syntax proposal (RFC) instead and leave this issue scoped to points 1 and 2. The first two matter most. ## Separately, and much smaller: a documentation error about `&` The same page states: > « Les noms d'`@ingrédient` peuvent contenir des caractères spéciaux (comme `'`, `&`, `.`), à l'exception des délimiteurs de syntaxe réservés (`{`, `}`, `:`, `(`, `)`, `<`, `|`). » `'` and `.` do work. `&` cannot, because it is the reference sigil — and gram handles that correctly. Writing `@sel & poivre{2g}` produces an ingredient `sel` plus a typed reference node, with the quantity preserved: ```json { "type": "reference", "id": "poivre", "name": "poivre", "qty": 2, "unit": "g" } ``` and a proper diagnostic with a code and a source location: ```json "warnings": [{ "code": "UNDEFINED_REFERENCE", "message": "Undefined reference '&poivre' — no prior step or section produces this item.", "item": "poivre", "loc": { "start": 74, "end": 86 } }] ``` `gram check` refuses the file. **Nothing is lost and everything is reported** — this is the behaviour I would want. The only thing wrong here is the documentation, which should drop `&` from that list of permitted characters. Mentioning it only because it sits in the same sentence of the same page as the units above. ## Where this probably lives Going by the pipeline in CONTRIBUTING: the parse failure looks like `packages/parser` (`grammar.ohm`, unit token character class), while the absence of a diagnostic would be `packages/kitchen`, described as the stage that emits warnings. --- *Drafted with AI assistance, verified by hand: every reproduction above was run locally against 1.2.1 and its output pasted verbatim.*
abiwab self-assigned this 2026-09-28 22:15:27 +02:00
Owner

Thanks for the detailed report, the repro made this easy to track down. Confirmed, and fixed in #36: the dotted spellings (c.à.s, c.à.c…) now parse, and a quantity that can't be read is now an error instead of being silently dropped.

It'll be in the next release :)

Thanks for the detailed report, the repro made this easy to track down. Confirmed, and fixed in #36: the dotted spellings (c.à.s, c.à.c…) now parse, and a quantity that can't be read is now an error instead of being silently dropped. It'll be in the next release :)
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gram-lang/gram#24
No description provided.