26 releases (15 breaking)

new 0.16.1 May 27, 2025
0.16.0 Mar 27, 2025
0.15.0 Jan 14, 2025
0.14.0 Dec 17, 2024
0.5.1 Jul 24, 2023

#814 in Parser implementations

Download history 78/week @ 2025-02-03 51/week @ 2025-02-10 2533/week @ 2025-02-17 594/week @ 2025-02-24 4915/week @ 2025-03-03 5563/week @ 2025-03-10 5630/week @ 2025-03-17 3865/week @ 2025-03-24 112/week @ 2025-03-31 43/week @ 2025-04-07 59/week @ 2025-04-14 42/week @ 2025-04-21 41/week @ 2025-04-28 59/week @ 2025-05-05 100/week @ 2025-05-12 181/week @ 2025-05-19

386 downloads per month
Used in 8 crates

MIT license

440KB
10K SLoC

Rust 9K SLoC // 0.0% comments Swift 1K SLoC // 0.1% comments

cooklang-rs

crates.io docs.rs license

Cooklang parser in rust with opt-in extensions.

All regular cooklang files parse as the same recipe, the extensions are a superset of the original cooklang format. Also, the extensions can be turned off, so the parser can be used for regular cooklang if you don't like them.

You can see a detailed list of all extensions explained here.

The parser also includes:

  • Rich error report with annotated code spans. (like this one)
  • Unit conversion.
  • Recipe scaling.
  • A parser for cooklang aisle configuration file.

lib.rs:

A cooklang parser with opt-in extensions.

The extensions create a superset of the original cooklang language and can be turned off. To see a detailed list go to extensions.

Also includes:

  • Rich error report with annotated code spans.
  • Unit conversion.
  • Recipe scaling.
  • A parser for cooklang aisle configuration file.

Basic usage

If you just want to parse a single cooklang file, see parse.

If you are going to parse more than one, or want to change the configuration of the parser, construct a parser instance yourself.

To construct a parser use CooklangParser::new or CooklangParser::default if you want to configure the parser. You can configure which Extensions are enabled and the Converter used to convert and check units.

// Create a parser
// (this is the default configuration)
let parser = CooklangParser::new(Extensions::all(), Converter::default());

Then use the parser:

let (recipe, _warnings) = parser.parse("This is an @example").into_result()?;
assert_eq!(recipe.ingredients.len(), 1);
assert_eq!(recipe.ingredients[0].name, "example");

Recipes can be scaled and converted. But the following applies:

Dependencies

~6.5MB
~176K SLoC