From 32d7d2f03dd2207ca3349d55feb1d25cee513ec8 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Mon, 3 Jun 2024 15:56:27 -0700 Subject: [PATCH] consolidate recipe table --- src/analyzer.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/analyzer.rs b/src/analyzer.rs index 04d644f..e2ef9cf 100644 --- a/src/analyzer.rs +++ b/src/analyzer.rs @@ -17,7 +17,7 @@ impl<'src> Analyzer<'src> { ) -> CompileResult<'src, Justfile<'src>> { let mut analyzer = Self::default(); - let mut recipes = Vec::new(); + let mut unprocessed_recipes = Vec::new(); let mut unprocessed_assignments = Vec::new(); @@ -82,7 +82,7 @@ impl<'src> Analyzer<'src> { Item::Recipe(recipe) => { if recipe.enabled() { Self::analyze_recipe(recipe)?; - recipes.push(recipe); + unprocessed_recipes.push(recipe); } } Item::Set(set) => { @@ -97,8 +97,6 @@ impl<'src> Analyzer<'src> { let settings = Settings::from_setting_iter(analyzer.sets.into_iter().map(|(_, set)| set.value)); - let mut recipe_table: Table<'src, UnresolvedRecipe<'src>> = Table::default(); - for assignment in unprocessed_assignments { if !settings.allow_duplicate_variables && analyzer.assignments.contains_key(assignment.name.lexeme()) @@ -119,17 +117,20 @@ impl<'src> Analyzer<'src> { AssignmentResolver::resolve_assignments(&analyzer.assignments)?; - for recipe in recipes { - define(recipe.name, "recipe", settings.allow_duplicate_recipes)?; - if recipe_table - .get(recipe.name.lexeme()) - .map_or(true, |original| recipe.file_depth <= original.file_depth) - { - recipe_table.insert(recipe.clone()); + let recipes = { + let mut recipe_table: Table<'src, UnresolvedRecipe<'src>> = Table::default(); + for recipe in unprocessed_recipes { + define(recipe.name, "recipe", settings.allow_duplicate_recipes)?; + if recipe_table + .get(recipe.name.lexeme()) + .map_or(true, |original| recipe.file_depth <= original.file_depth) + { + recipe_table.insert(recipe.clone()); + } } - } - let recipes = RecipeResolver::resolve_recipes(recipe_table, &analyzer.assignments)?; + RecipeResolver::resolve_recipes(recipe_table, &analyzer.assignments)? + }; let mut aliases = Table::new(); while let Some(alias) = analyzer.aliases.pop() {