Skip to content

Proposal 0018: optional ingredients and cookware - #153

Merged
dubadub merged 2 commits into
mainfrom
proposal/0018-optional-components
Sep 29, 2026
Merged

dubadub merged 2 commits into
mainfrom
proposal/0018-optional-components

Conversation

@dubadub

@dubadub dubadub commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

Moves the optional marker ? from a parser extension into the spec.

Rendered proposal

Summary

  • Syntax: a ? immediately after the sigil marks an ingredient or cookware as optional — @?thyme, @?chilli flakes{1%pinch}, #?splatter guard{}. The ? is not part of the name; parsers expose an optional boolean. Timers are unaffected.
  • Scope: only ? is standardised. The other cooklang-rs component modifiers (&, -, +, @@) remain extensions.
  • Semantics: optionality is per occurrence. Required and optional occurrences of the same ingredient aggregate separately (parmesan 100 g + parmesan 50 g (optional)), so the required total never includes skippable amounts.
  • Shopping list format (extends 0016): optional ingredients are opt-in. A recipe reference contributes only required ingredients; each accepted optional ingredient is recorded as an indented selection line carrying the final (already scaled) amount to buy, so totals are a plain sum:
    ./Breakfast/Eggs on toast{2}
      ? chilli flakes{2%pinch}
    
    Several selection lines with the same name each contribute, which covers recipes that use the same optional ingredient more than once (accept all occurrences or only some).
  • Applications: mark optional components in lists and steps, ask which optional ingredients to include when adding a recipe to a shopping list, and ignore missing optional ingredients in pantry matching.

Motivation

@?thyme already works in cooklang-rs behind the COMPONENT_MODIFIERS flag and authors use it, but because it isn't in the spec, tools disagree: some show optional thyme, others a required ingredient named ?thyme. See cooklang/cookcli#502, which works around this by enabling the whole modifiers bundle (and changes @-salt as a side effect).

Related discussions: #50, #122.

This PR contains the proposal only; README, EBNF, canonical tests and conventions updates follow once it is accepted.

- standardise the `?` marker (`@?thyme`, `#?stand mixer{}`) from the
  cooklang-rs component modifiers extension; other modifiers stay extensions
- optionality is per occurrence; required and optional amounts aggregate
  separately
- extend the shopping list format (0016) with `? name` selection lines so
  optional ingredients are opt-in per recipe
- `? name{quantity}` stores the final, already scaled amount to buy, so
  totals are a plain sum with no recipe lookup
- several selection lines with the same name each contribute, covering
  recipes that use the same optional ingredient more than once
- accepted optional recipe references carry their multiplier
@dubadub
dubadub marked this pull request as ready for review September 18, 2026 19:45
@tmlmt

tmlmt commented Sep 18, 2026

Copy link
Copy Markdown

About the "Semantics" paragraph in the PR summary, or the "Aggregation" section in the spec proposal: quantities don't aggregate without the & reference modifier anyway?

@omeganot

Copy link
Copy Markdown

I too am a little confused by the Semantics and aggregation. "Never" implies no possible way. That feels like a miss. Perhaps a toggle in the CLI or web views of the recipes to include optional ingredients in a separate part of the list? That way I can see what the recipe requires, then see what optional ingredients are listed, which I may not have and want to buy, or may not think about including them without looking at them in the list.

@dubadub

dubadub commented Sep 29, 2026

Copy link
Copy Markdown
Member Author

I think we need to separate what parser outputs and how apps display it. In some contexts we should separate these ingredients and in some not, so the parser itself shouldn't aggregate ingredients and leave this option to the consumer (the apps). Saying that parser should provide tools to aggregate ingredients, so apps not re-implementing them.

@dubadub
dubadub merged commit 3cc4fde into main Sep 29, 2026
@dubadub
dubadub deleted the proposal/0018-optional-components branch September 29, 2026 19:18
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.

3 participants