[Parser] {1 c.à.s} and {1 c.à.c} from the French docs silently drop the quantity and merge distinct ingredients #24
Labels
No labels
bug
discussion
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
research
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gram-lang/gram#24
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Version:
@gram-lang/cli1.2.1 (current npmlatest), 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 checkreports the file asvalid.Reproduction
/fr/docs/reference/syntax/ingredients/gives{1/2 c.à.s}and{1 c.à.c}as examples.gram build fr.gram --pretty --skip-dbyields two ingredients where six were written: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:and the English reference lists
1.5-2las 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}yieldsunit: "cas"), so this looks less like a missing@gram-lang/i18ndictionary entry than a character-class restriction on the unit token.What I would expect, in decreasing order of ambition
MISSING_UNITandINVALID_UNIT, and^{200}correctly raisesMISSING_UNIT. An ingredient quantity failing silently seems inconsistent with that.c.à.s/c.à.cparse 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:
'and.do work.&cannot, because it is the reference sigil — and gram handles that correctly. Writing@sel & poivre{2g}produces an ingredientselplus a typed reference node, with the quantity preserved:and a proper diagnostic with a code and a source location:
gram checkrefuses 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 bepackages/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.
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 :)