Skip to content

feat: range quantities scale and add up (cooklang 0.23.0, spec 0011) - #865

Merged
dubadub merged 1 commit into
mainfrom
chore/cooklang-0.23
Nov 28, 2026
Merged

dubadub merged 1 commit into
mainfrom
chore/cooklang-0.23

Conversation

@dubadub

@dubadub dubadub commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Bumps cooklang to 0.23.0, cooklang-ingredient-parser to 0.23.0, cooklang-reports to 0.11.0 and cooklang-language-server to 0.7.0.

cooklang 0.23 makes ranges core syntax (spec proposal 0011). CookCLI's parser has no extensions, so until now @garlic{2-3%cloves} was Text("2-3"). With this bump it is a range everywhere.

Fixes #597. Part of #862: the first item, plus what the bump changes in tests and comments.

What changes for users

Checked by hand with the released cook 0.41.1 and this branch, on @garlic{2-3%cloves}, @chilli flakes{1/2-1%tsp}, ~{25-30%minutes} and @salt{1%tsp} plus @salt{1-2%tsp}:

0.41.1 this branch
recipe read -f cooklang range.cook:2 on @flour{1-2%tbsp} (#597) @flour{1-2%tbsp} @flour{2-4%tbsp}
recipe read, salt 1 tsp, 1-2 tsp 2 - 3 tsp
recipe read …:4, garlic 2-3 cloves 8 - 12 cloves
shopping-list, salt 1 tsp, 1-2 tsp 2 - 3 tsp
report with get_ingredient_list, two @saffron{0.3335%g} 0.668 g 0.667 g
JSON {"type":"text","value":"2-3"} {"type":"range","value":{"start":…,"end":…}}
schema.org, ~{10-20%minutes} no timeRequired PT15M (the average, as schema.rs already did for scaled ranges)
@beans{1-1/0%cans} text error "Division by zero" (spec 0011)

The web recipe page and shopping list render ranges (2 - 3 cloves, ⏱️ 25 - 30 minutes). The shopping list JS already handled type: "range".

Visible side effects:

  • A range is displayed with the existing range format, 2 - 3, where the text used to show 2-3.
  • In reports, a range with a fraction end shows as 0.5-1 tsp, as 1/2 cup already showed as 0.5 cup there.

Picking one display separator is item 3 of #862.

Code changes

  • doctor: the timer pass no longer adds Extensions::RANGE_VALUES, which does nothing from cooklang 0.23. The comments that explained it are updated.
  • Comments:
    • report.rs said cooklang-reports parses with every extension on, but it uses none;
    • schema.rs said ranges only come from scaling;
    • cooklang_source.rs mentioned RANGE_VALUES.

Tests

Not in this PR (rest of #862)

These are unchanged by the bump. Each behaves as it did when ranges were text:

  • the display separator;
  • countdowns for range timers in the web UI;
  • recipe references with a range amount, still refused;
  • typed free-hand range lines;
  • pantry amounts.

One write path does change: new .shopping-list selection lines (optional_selections, written with Display).

  • An optional range is now scaled and written as decimals: @?chilli flakes{1/3-1/2%tsp} gives 0.333-0.5%tsp at ×1 and 0.667-1%tsp at ×2.
  • It used to be copied as written, 1/3-1/2%tsp, at every scale.
  • A plain number already behaves this way: @?pepper{1/3%tsp} gives 0.333%tsp.
  • Existing lines are still written back exactly, with Quantity::to_cooklang.
  • Fix: write selections with Quantity::to_cooklang as well (Range quantities: scale, add up and time {2-3%cloves} and ~{25-30%minutes} as numbers (spec 0011) #862 item 8).

The schema.org lower-end-or-average decision (item 5) is also open. This PR keeps the average.

Bump cooklang and cooklang-ingredient-parser to 0.23.0, cooklang-reports
to 0.11.0 and cooklang-language-server to 0.7.0. cooklang 0.23 parses
ranges without extensions, so @Garlic{2-3%cloves} is a range rather
than text to CookCLI's parser: it scales (#597), adds up on shopping
lists and in reports, and is a range in JSON.

- doctor: drop the RANGE_VALUES workaround in the timer pass
- a zero denominator in a range ({1-1/0}) is an error, per the spec
- schema.org: a range timer gives timeRequired (its average)
- fix stale comments about range values and cooklang-reports' parser
- tests: range scaling, JSON and shopping list totals; the BOM span
  test no longer relies on the dropped scaling-lock warning

Fixes #597. Part of #862.
@claude

claude Bot commented Nov 28, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

@dubadub
dubadub merged commit 74aa194 into main Nov 28, 2026
6 checks passed
@dubadub
dubadub deleted the chore/cooklang-0.23 branch November 28, 2026 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ingredient ranges stay unchanged when scaling a recipe

1 participant