Expand description
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:
- Parsing returns a
ScalableRecipe
. - Only
ScalableRecipe
can bescaled
ordefault_scaled
only once to obtain aScaledRecipe
. - Only
ScaledRecipe
can beconverted
.
Re-exports§
pub use analysis::ParseOptions;
pub use convert::Converter;
pub use located::Located;
pub use metadata::Metadata;
pub use parser::Modifiers;
pub use quantity::GroupedQuantity;
pub use quantity::Quantity;
pub use quantity::ScalableQuantity;
pub use quantity::ScalableValue;
pub use quantity::ScaledQuantity;
pub use quantity::Value;
pub use span::Span;
pub use text::Text;
pub use model::*;
Modules§
- _extensions
- Cooklang syntax extensions
- _features
- This lib has 2 features, both enabled by default:
- aisle
- Cooklang aisle configuration parser
- analysis
- Analysis pass of the parser
- ast
- Abstract Syntax Tree representation of a cooklang recipe
- convert
- Support for configurable unit conversion
- error
- Error type, formatting and utilities.
- ingredient_
list - Generate ingredients lists from recipes
- located
- Utility to add location information to any type
- metadata
- Metadata of a recipe
- model
- Recipe representation
- parser
- Cooklang parser
- quantity
- Quantity model
- scale
- Support for recipe scaling
- span
- Utility to represent a location in the source code
- text
Structs§
- Cooklang
Parser - A cooklang parser
- Extensions
- Extensions bitflags
Functions§
- parse
- Parse a recipe with a default
CooklangParser
. Avoid calling this in a loop.