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::QuantityUnit;
pub use quantity::ScalableQuantity;
pub use quantity::ScalableValue;
pub use quantity::ScaledQuantity;
pub use quantity::UnitInfo;
pub use quantity::Value;
pub use span::Span;
pub use text::Text;
pub use model::*;
Modules§
- Cooklang syntax extensions
- This lib has 2 features, both enabled by default:
- Cooklang aisle configuration parser
- Analysis pass of the parser
- Abstract Syntax Tree representation of a cooklang recipe
- Support for configurable unit conversion
- Error type, formatting and utilities.
- Generate ingredients lists from recipes
- Utility to add location information to any type
- Metadata of a recipe
- Recipe representation
- Cooklang parser
- Quantity model
- Support for recipe scaling
- Utility to represent a location in the source code
Structs§
- A cooklang parser
- Extensions bitflags
Functions§
- Parse a recipe with a default
CooklangParser
. Avoid calling this in a loop.