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>>>,
|
|
|
|
) -> CompilationResult<'src, Recipe<'src>> {
|
|
|
|
assert_eq!(self.dependencies.len(), resolved.len());
|
|
|
|
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())
|
|
|
|
{
|
|
|
|
return Err(unresolved.recipe.error(
|
|
|
|
CompilationErrorKind::DependencyArgumentCountMismatch {
|
|
|
|
dependency: unresolved.recipe.lexeme(),
|
2020-02-10 20:07:06 -08:00
|
|
|
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 {
|
|
|
|
doc: self.doc,
|
|
|
|
body: self.body,
|
|
|
|
name: self.name,
|
|
|
|
parameters: self.parameters,
|
|
|
|
private: self.private,
|
|
|
|
quiet: self.quiet,
|
|
|
|
shebang: self.shebang,
|
|
|
|
dependencies,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|