consolidate recipe table

This commit is contained in:
Greg Shuflin 2024-06-03 15:56:27 -07:00
parent 61f7ab33c6
commit 32d7d2f03d

View File

@ -17,7 +17,7 @@ impl<'src> Analyzer<'src> {
) -> CompileResult<'src, Justfile<'src>> { ) -> CompileResult<'src, Justfile<'src>> {
let mut analyzer = Self::default(); let mut analyzer = Self::default();
let mut recipes = Vec::new(); let mut unprocessed_recipes = Vec::new();
let mut unprocessed_assignments = Vec::new(); let mut unprocessed_assignments = Vec::new();
@ -82,7 +82,7 @@ impl<'src> Analyzer<'src> {
Item::Recipe(recipe) => { Item::Recipe(recipe) => {
if recipe.enabled() { if recipe.enabled() {
Self::analyze_recipe(recipe)?; Self::analyze_recipe(recipe)?;
recipes.push(recipe); unprocessed_recipes.push(recipe);
} }
} }
Item::Set(set) => { 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 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 { for assignment in unprocessed_assignments {
if !settings.allow_duplicate_variables if !settings.allow_duplicate_variables
&& analyzer.assignments.contains_key(assignment.name.lexeme()) && analyzer.assignments.contains_key(assignment.name.lexeme())
@ -119,17 +117,20 @@ impl<'src> Analyzer<'src> {
AssignmentResolver::resolve_assignments(&analyzer.assignments)?; AssignmentResolver::resolve_assignments(&analyzer.assignments)?;
for recipe in recipes { let recipes = {
define(recipe.name, "recipe", settings.allow_duplicate_recipes)?; let mut recipe_table: Table<'src, UnresolvedRecipe<'src>> = Table::default();
if recipe_table for recipe in unprocessed_recipes {
.get(recipe.name.lexeme()) define(recipe.name, "recipe", settings.allow_duplicate_recipes)?;
.map_or(true, |original| recipe.file_depth <= original.file_depth) if recipe_table
{ .get(recipe.name.lexeme())
recipe_table.insert(recipe.clone()); .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(); let mut aliases = Table::new();
while let Some(alias) = analyzer.aliases.pop() { while let Some(alias) = analyzer.aliases.pop() {