recipe_grid.compiler
: Recipe description language compiler¶
The recipe description language is compiled into the recipe Grid data model
(see recipe_grid.recipe
) by the following function:
- recipe_grid.compiler.compile(sources: List[str]) List[Recipe] ¶
Compile a recipe from source into a series of
recipe_grid.recipe.Recipe
data structures.The input recipe may be split into several blocks with later blocks referencing sub recipes in earlier ones. The code for each block should be passed separately and for each of these a separate
Recipe
object will be produced.May throw
peggie.ParseError
during parsing and subclasses ofRecipeCompileError
during compilation.Tip
It is assumed that all source blocks originate from a single file (e.g. from different indented blocks in a Markdown file). To make error messages report correct line numbers, pad the start of each source string with empty lines according to the position of the block in the original file. This will ensure that error messages give useful line numbers.
During compilation the following exception types may be thrown. In all cases,
when cast to str
, the string representation takes the form similar
to:
At line 19 column 2:
))
^
Expected ','
With a line number, code snippet and error explanation provided.
- exception peggie.ParseError
Thrown if parsing fails due to a syntactic error (see
peggie.ParseError
in thepeggie
documentation for details).
- exception recipe_grid.compiler.RecipeCompileError(line: int, column: int, snippet: str)¶
Base type for compilation errors.
- exception recipe_grid.compiler.NameRedefinedError(line: int, column: int, snippet: str, second_output_name_definition: String)¶
Thrown when an output name is redefined.
- exception recipe_grid.compiler.ProportionGivenForIngredientError(line: int, column: int, snippet: str, ast_reference: Reference)¶
Thrown when an ingredient is prefixed with a proportion rather than a quantity. This probably implies that this was intended to be a reference to some earlier output and the user misspelt the name.