2019-12-07 04:03:03 -08:00
|
|
|
use crate::common::*;
|
|
|
|
|
|
|
|
pub(crate) type UnresolvedRecipe<'src> = Recipe<'src, UnresolvedDependency<'src>>;
|
|
|
|
|
|
|
|
impl<'src> UnresolvedRecipe<'src> {
|
|
|
|
pub(crate) fn resolve(
|
|
|
|
self,
|
|
|
|
resolved: Vec<Rc<Recipe<'src>>>,
|
2021-07-26 01:26:06 -07:00
|
|
|
) -> CompileResult<'src, Recipe<'src>> {
|
2021-07-22 00:20:25 -07:00
|
|
|
assert_eq!(
|
|
|
|
self.dependencies.len(),
|
|
|
|
resolved.len(),
|
|
|
|
"UnresolvedRecipe::resolve: dependency count not equal to resolved count: {} != {}",
|
|
|
|
self.dependencies.len(),
|
|
|
|
resolved.len()
|
|
|
|
);
|
|
|
|
|
2019-12-07 04:03:03 -08:00
|
|
|
for (unresolved, resolved) in self.dependencies.iter().zip(&resolved) {
|
|
|
|
assert_eq!(unresolved.recipe.lexeme(), resolved.name.lexeme());
|
|
|
|
if !resolved
|
|
|
|
.argument_range()
|
|
|
|
.contains(&unresolved.arguments.len())
|
|
|
|
{
|
2021-07-26 01:26:06 -07:00
|
|
|
return Err(
|
|
|
|
unresolved
|
|
|
|
.recipe
|
|
|
|
.error(CompileErrorKind::DependencyArgumentCountMismatch {
|
|
|
|
dependency: unresolved.recipe.lexeme(),
|
|
|
|
found: unresolved.arguments.len(),
|
|
|
|
min: resolved.min_arguments(),
|
|
|
|
max: resolved.max_arguments(),
|
|
|
|
}),
|
|
|
|
);
|
2019-12-07 04:03:03 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let dependencies = self
|
|
|
|
.dependencies
|
|
|
|
.into_iter()
|
|
|
|
.zip(resolved)
|
|
|
|
.map(|(unresolved, resolved)| Dependency {
|
2020-02-10 20:07:06 -08:00
|
|
|
recipe: resolved,
|
2019-12-07 04:03:03 -08:00
|
|
|
arguments: unresolved.arguments,
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
Ok(Recipe {
|
|
|
|
body: self.body,
|
2021-07-22 00:20:25 -07:00
|
|
|
doc: self.doc,
|
2019-12-07 04:03:03 -08:00
|
|
|
name: self.name,
|
|
|
|
parameters: self.parameters,
|
|
|
|
private: self.private,
|
|
|
|
quiet: self.quiet,
|
|
|
|
shebang: self.shebang,
|
2021-07-22 00:20:25 -07:00
|
|
|
priors: self.priors,
|
2019-12-07 04:03:03 -08:00
|
|
|
dependencies,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|