diff --git a/tools/src/bin/parser/main.rs b/tools/src/bin/parser/main.rs index 056416a..8018c0e 100644 --- a/tools/src/bin/parser/main.rs +++ b/tools/src/bin/parser/main.rs @@ -16,12 +16,7 @@ struct Args { fn main() -> anyhow::Result<()> { let args = Args::parse(); - let repo = Repo::new(&args.repo); - println!("{:#?}", repo); - - let recipe: Option<&Recipe> = repo.get_recipe(&args.target); - println!("{recipe:#?}"); - + repo.compile(&args.target).unwrap(); Ok(()) } diff --git a/tools/src/recipe.rs b/tools/src/recipe.rs index 68c7c6b..134384f 100644 --- a/tools/src/recipe.rs +++ b/tools/src/recipe.rs @@ -15,8 +15,8 @@ pub struct Input { /// be optionally overridden by the recipe to things like "meters" /// (of tubing) or "grams" (of chromic acid). Then this struct /// would be `quantity: usize, units: Option`. - quantity: Option, - amount: Option, + pub quantity: Option, + pub amount: Option, } #[derive(Debug, serde::Deserialize)] @@ -30,36 +30,43 @@ pub struct Output { /// be optionally overridden by the recipe to things like "meters" /// (of tubing) or "grams" (of chromic acid). Then this struct /// would be `quantity: usize, units: Option`. - quantity: Option, - amount: Option, + pub quantity: Option, + pub amount: Option, } #[derive(Debug, serde::Deserialize)] pub struct Operator { - skills: Vec, + pub skills: Vec, } #[derive(Debug, serde::Deserialize)] pub struct Dependencies { - tools: Vec, - operator: Option, + pub tools: Option>, + pub operator: Option, +} + +#[derive(Debug, serde::Deserialize)] +pub struct Purchase { + pub vendor: Vec, + pub documentation: Option>, } #[derive(Debug, serde::Deserialize)] pub enum Action { process(String), print, + purchase(Purchase), } #[derive(Debug, serde::Deserialize)] pub struct Recipe { /// `[inputs]` is a Table where each key the the name (unique id) /// of a recipe in the repo, and the value is an Input object. - inputs: std::collections::HashMap, + pub inputs: std::collections::HashMap, - dependencies: Dependencies, + pub dependencies: Dependencies, - action: Action, + pub action: Action, /// If a recipe has no `[outputs]`, we assume it produces 1x of the /// thing identified by the name of the recipe. @@ -67,7 +74,7 @@ pub struct Recipe { /// FIXME: Or is that always the case, and we should have no outputs /// section? None of the recipes we've been doodling around with /// have anything like byproducts or waste streams... - outputs: Option>, + pub outputs: Option>, } impl Recipe { diff --git a/tools/src/repo.rs b/tools/src/repo.rs index b7861f7..6529463 100644 --- a/tools/src/repo.rs +++ b/tools/src/repo.rs @@ -1,4 +1,5 @@ use crate::recipe::Recipe; +use std::fmt; #[derive(Debug)] pub struct Repo { @@ -20,6 +21,30 @@ impl Repo { self.recipes.get(recipe_name) } + pub fn compile(self: &Self, target: &str) -> anyhow::Result<()> { + let recipe = self.get_recipe(target); + match recipe { + None => { + return Err(anyhow::Error::msg(format!("recipe for {target} not found"))); + } + Some(recipe) => { + println!("{recipe:#?}"); + println!("inputs:"); + for (key, val) in recipe.inputs.iter() { + println!("{key:?} {val:?}"); + if key == "capital" { + println!("aquire capital: {:?}", val.amount.to_owned()); + } else { + self.compile(key)?; + } + } + } + } + Ok(()) + } +} + +impl Repo { fn add_dir(self: &mut Self, path: &str) -> anyhow::Result<()> { // println!("reading Recipes from {path}"); let dir_entries = std::fs::read_dir(path).unwrap();