Repository navigation
Description
What
Support range quantities as numbers everywhere in CookCLI: @garlic{2-3%cloves}, @chilli flakes{1/2-1%tsp}, ~{25-30%minutes}. Ranges are now part of the Cooklang spec (proposal 0011, accepted). The en dash and em dash also work as separators ({2–3}).
Tracks #597 (ranges stay unchanged when a recipe is scaled). Close #597 when this lands.
Why
The shared PARSER (crates/core/src/parser.rs:20-21) uses Extensions::empty(), so today {2-3%cloves} parses as Text("2-3"). Ranges don't scale, don't add up on shopping lists and get no countdown in the web UI. The language server uses Extensions::all(), so the editor and the rest of CookCLI disagree.
The cooklang-rs change for this (cooklang/cooklang-rs#169, released in 0.23.0) parses ranges with no extensions. RANGE_VALUES becomes a documented no-op. The same change:
- reads ranges on
.shopping-listfree-hand items and? name{…}selection lines, and writes them back as1-2%unit; - warns on
{3-2}, and treats a zero denominator at either end ({1-1/0}) as an error.
Most of CookCLI is already ready: the formatters, serde output, recipe.scale(...) and upstream try_add all handle Value::Range.
What changes on its own after the bump
From reading the code; not run.
- Scaling:
recipe read, the web recipe page, shopping lists and reports all callrecipe.scale(...), which scales both ends. - JSON/YAML: a range serialises as
{"type":"range","value":{"start":…,"end":…}}, distinct from text. -f cooklang: already writesstart-end(crates/format/src/cooklang_source.rs:321-330).- Shopping list totals: through
IngredientList(range + range end to end, number + range on both ends). - Web ingredient lists: built server-side through
GroupedQuantity::merge(src/web/builders.rs). They inherit range support.
Work
Bump cooklang-rs to the release with ranges in core.feat: range quantities scale and add up (cooklang 0.23.0, spec 0011) #865 (cooklang 0.23.0).feat: range quantities scale and add up (cooklang 0.23.0, spec 0011) #865.doctor: stop addingExtensions::RANGE_VALUESintextual_timer_warnings, and drop the comments that explain it.docs/doctor.mdwas still accurate. The parser's reversed-range warning ({3-2}) already shows incook doctor validate, with its hint.- Display:
crates/format/src/number.rs:206-216format_valuerendersa - b. The spec says to show the unit once (2–3 cloves), and an en dash is allowed for display.- Pick one separator for human, Markdown, LaTeX, Typst and the web (
templates/shopping_list.html:644-661formatCooklangValue). - Writers (
-f cooklang,.shopping-list) keep the plain-.
- Web timers:
src/web/builders.rs:355-366timer_duration_secondsreturnsNonefor anything butNumber, so a range timer gets nodata-secondsand no countdown (templates/recipe.html:405,static/js/timers.js:244).- The spec says to show the range and default the countdown to the lower end. Offering the upper end (e.g. "+5 min") is optional.
- schema.org:
crates/format/src/schema.rs:352-361averages a range fortimeRequired. Decide between the lower end and keeping the average, and fix the comment that says ranges only come from scaling. - Recipe references with a range amount:
@./sauce{1-2}is refused asNotANumber(crates/core/src/shopping_list/mod.rs:1162-1184,src/util/recipe_info.rs:98). Decide what it means (lower end? error?). - Menus:
src/util/menu.rs:253-282scaled_quantityre-parses throughPARSER, so menu ranges start scaling after the bump. Check the menu page and cooking mode. .shopping-listround trip (web server):- New selection lines are written with upstream
Display(optional_selections,crates/core/src/shopping_list/mod.rs:912-918), which rounds each end to 3 decimals. Since feat: range quantities scale and add up (cooklang 0.23.0, spec 0011) #865,@?chilli flakes{1/3-1/2%tsp}is recorded as0.333-0.5%tsp(it was the text1/3-1/2%tsp, unscaled). Plain numbers already were (1/3→0.333). PreferQuantity::to_cooklang. - Check that
add_optional_selectionsand the free-hand paths (FreeHandItem::spec,store.rs:123;mod.rs:518-546) read ranges back as ranges.
- New selection lines are written with upstream
- Typed free-hand lines:
cooklang-ingredient-parser'sAmountis a single number.add_typed(store.rs:406) never merges ranges, andedit_textreduces a range item to its name, soedited_item(crates/core/src/shopping_list/typed.rs:98) keeps the old quantity.- Needs range support in the ingredient-parser crate (cooklang-rs) or a documented limit.
- Pantry:
- Recipe matching (
crates/core/src/pantry/mod.rs:587-633,:731) compares names only. When it compares amounts, the spec says to compare a range against its upper end. - Shopping-list pantry subtraction (upstream
subtract_pantry) only subtracts numbers, so a range keeps its full amount. That may need a cooklang-rs change.
- Recipe matching (
cooklang-reports: it re-parsed quantities from text, splitting ranges on ASCIIFixed in fix: use parsed quantities instead of re-reading them from text cooklang-reports#29 and Update parser v0.1.1: changed defaults #30, released in 0.11.0: parsed quantities are used as they are. feat: range quantities scale and add up (cooklang 0.23.0, spec 0011) #865 bumps it and fixes the comment in-.report.rs.
Tests that will change
Done in #865, along with the new range scaling, JSON and shopping list total tests. Still to add: a .shopping-list range round trip and a web range timer test.
crates/core/src/doctor.rs:1494-1530: range timers without warnings. Keep the test, remove the reliance on the private flag.crates/core/src/doctor.rs:1612-1628: expects@beans{1-1/0%cans}to be text. Per the spec it is now a parse error.tests/schema_output_test.rs:266-277: expects notimeRequiredfor~{10-20%minutes}.crates/format/src/number.rs:360-377: pins the1/2 - 2 1/4display.- New tests:
- range scaling in
recipe read(every format, including-f cooklang); - shopping list range totals (number + range, range + range);
.shopping-listrange round trip, including a line read with an en dash;- range JSON output;
- a range timer countdown in the web UI (
seed/Shared/Pizza Dough.cook:25has~{10-20%minutes}).
- range scaling in
Related
- Spec: README › Ranges, conventions (shopping lists, pantry, scaling), proposal 0011, canonical tests v9 (docs: range quantities (0011) spec#176)
- Ingredient ranges stay unchanged when scaling a recipe #597
Activity
feat: range quantities scale and add up (cooklang 0.23.0, spec 0011) (#…