14 releases (7 breaking)

new 0.8.0 Sep 26, 2023
0.6.0 Aug 7, 2023
0.5.1 Jul 24, 2023

#3 in #cooking-recipes

Download history 10/week @ 2023-06-08 66/week @ 2023-06-15 44/week @ 2023-06-22 38/week @ 2023-06-29 98/week @ 2023-07-06 28/week @ 2023-07-13 142/week @ 2023-07-20 54/week @ 2023-07-27 45/week @ 2023-08-03 55/week @ 2023-08-10 88/week @ 2023-08-17 89/week @ 2023-08-24 48/week @ 2023-08-31 63/week @ 2023-09-07 29/week @ 2023-09-14 85/week @ 2023-09-21

241 downloads per month
Used in 5 crates

MIT license

320KB
7.5K SLoC

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.

As soon as 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 src = "This is an @example.";
let name = "Example Recipe";
let (recipe, _warnings) = parser.parse(src, name).into_result()?;
assert_eq!(recipe.name, name);
assert_eq!(recipe.ingredients.len(), 1);
assert_eq!(recipe.ingredients[0].name, "example");

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

Dependencies

~8–11MB
~268K SLoC