Combine analyze() and justfile() functions
This commit is contained in:
parent
f5bb82dea3
commit
9f965094ba
@ -15,17 +15,8 @@ impl<'src> Analyzer<'src> {
|
|||||||
root: &Path,
|
root: &Path,
|
||||||
name: Option<Name<'src>>,
|
name: Option<Name<'src>>,
|
||||||
) -> CompileResult<'src, Justfile<'src>> {
|
) -> CompileResult<'src, Justfile<'src>> {
|
||||||
Self::default().justfile(loaded, paths, asts, root, name)
|
let mut analyzer = Self::default();
|
||||||
}
|
|
||||||
|
|
||||||
fn justfile(
|
|
||||||
mut self,
|
|
||||||
loaded: &[PathBuf],
|
|
||||||
paths: &HashMap<PathBuf, PathBuf>,
|
|
||||||
asts: &HashMap<PathBuf, Ast<'src>>,
|
|
||||||
root: &Path,
|
|
||||||
name: Option<Name<'src>>,
|
|
||||||
) -> CompileResult<'src, Justfile<'src>> {
|
|
||||||
let mut recipes = Vec::new();
|
let mut recipes = Vec::new();
|
||||||
|
|
||||||
let mut assignments = Vec::new();
|
let mut assignments = Vec::new();
|
||||||
@ -71,7 +62,7 @@ impl<'src> Analyzer<'src> {
|
|||||||
Item::Alias(alias) => {
|
Item::Alias(alias) => {
|
||||||
define(alias.name, "alias", false)?;
|
define(alias.name, "alias", false)?;
|
||||||
Self::analyze_alias(alias)?;
|
Self::analyze_alias(alias)?;
|
||||||
self.aliases.insert(alias.clone());
|
analyzer.aliases.insert(alias.clone());
|
||||||
}
|
}
|
||||||
Item::Assignment(assignment) => {
|
Item::Assignment(assignment) => {
|
||||||
assignments.push(assignment);
|
assignments.push(assignment);
|
||||||
@ -95,8 +86,8 @@ impl<'src> Analyzer<'src> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Item::Set(set) => {
|
Item::Set(set) => {
|
||||||
self.analyze_set(set)?;
|
analyzer.analyze_set(set)?;
|
||||||
self.sets.insert(set.clone());
|
analyzer.sets.insert(set.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,29 +95,29 @@ impl<'src> Analyzer<'src> {
|
|||||||
warnings.extend(ast.warnings.iter().cloned());
|
warnings.extend(ast.warnings.iter().cloned());
|
||||||
}
|
}
|
||||||
|
|
||||||
let settings = Settings::from_setting_iter(self.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();
|
let mut recipe_table: Table<'src, UnresolvedRecipe<'src>> = Table::default();
|
||||||
|
|
||||||
for assignment in assignments {
|
for assignment in assignments {
|
||||||
if !settings.allow_duplicate_variables
|
if !settings.allow_duplicate_variables
|
||||||
&& self.assignments.contains_key(assignment.name.lexeme())
|
&& analyzer.assignments.contains_key(assignment.name.lexeme())
|
||||||
{
|
{
|
||||||
return Err(assignment.name.token.error(DuplicateVariable {
|
return Err(assignment.name.token.error(DuplicateVariable {
|
||||||
variable: assignment.name.lexeme(),
|
variable: assignment.name.lexeme(),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
if self
|
if analyzer
|
||||||
.assignments
|
.assignments
|
||||||
.get(assignment.name.lexeme())
|
.get(assignment.name.lexeme())
|
||||||
.map_or(true, |original| assignment.depth <= original.depth)
|
.map_or(true, |original| assignment.depth <= original.depth)
|
||||||
{
|
{
|
||||||
self.assignments.insert(assignment.clone());
|
analyzer.assignments.insert(assignment.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AssignmentResolver::resolve_assignments(&self.assignments)?;
|
AssignmentResolver::resolve_assignments(&analyzer.assignments)?;
|
||||||
|
|
||||||
for recipe in recipes {
|
for recipe in recipes {
|
||||||
define(recipe.name, "recipe", settings.allow_duplicate_recipes)?;
|
define(recipe.name, "recipe", settings.allow_duplicate_recipes)?;
|
||||||
@ -138,10 +129,10 @@ impl<'src> Analyzer<'src> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let recipes = RecipeResolver::resolve_recipes(recipe_table, &self.assignments)?;
|
let recipes = RecipeResolver::resolve_recipes(recipe_table, &analyzer.assignments)?;
|
||||||
|
|
||||||
let mut aliases = Table::new();
|
let mut aliases = Table::new();
|
||||||
while let Some(alias) = self.aliases.pop() {
|
while let Some(alias) = analyzer.aliases.pop() {
|
||||||
aliases.insert(Self::resolve_alias(&recipes, alias)?);
|
aliases.insert(Self::resolve_alias(&recipes, alias)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +140,7 @@ impl<'src> Analyzer<'src> {
|
|||||||
|
|
||||||
Ok(Justfile {
|
Ok(Justfile {
|
||||||
aliases,
|
aliases,
|
||||||
assignments: self.assignments,
|
assignments: analyzer.assignments,
|
||||||
default: recipes
|
default: recipes
|
||||||
.values()
|
.values()
|
||||||
.filter(|recipe| recipe.name.path == root)
|
.filter(|recipe| recipe.name.path == root)
|
||||||
|
Loading…
Reference in New Issue
Block a user