Expander::expand_expr now returns an Expr.

This commit is contained in:
Filipe Rodrigues 2023-02-13 09:53:11 +00:00
parent 7f305b25fa
commit d419fd845f
2 changed files with 6 additions and 10 deletions

View File

@ -665,12 +665,12 @@ impl<'s> Builder<'s> {
let output_file = match output {
OutItem::File { file: output_file } | OutItem::DepsFile { file: output_file } => output_file,
};
let file_cmpts = self
let output_file = self
.expander
.expand_expr(output_file, &mut RuleOutputVisitor::new(&rules.aliases, &rule.aliases))?;
// Then try to match the output file to the file we need to create
if let Some(rule_pats) = self::match_expr(output_file, &file_cmpts, file)? {
if let Some(rule_pats) = self::match_expr(&output_file, &output_file.cmpts, file)? {
let rule = self
.expander
.expand_rule(rule, &mut RuleVisitor::new(&rules.aliases, &rule.aliases, &rule_pats))

View File

@ -23,11 +23,7 @@ impl Expander {
}
/// Expands an expression to it's components
pub fn expand_expr<'s>(
&self,
expr: &Expr<'s>,
visitor: &mut impl Visitor<'s>,
) -> Result<Vec<ExprCmpt<'s>>, AppError> {
pub fn expand_expr<'s>(&self, expr: &Expr<'s>, visitor: &mut impl Visitor<'s>) -> Result<Expr<'s>, AppError> {
// Go through all components
let cmpts = expr
.cmpts
@ -56,7 +52,7 @@ impl Expander {
// If expanded, check if we need to apply any operations
FlowControl::ExpandTo(alias_expr) => match alias.ops.is_empty() {
// If not, just recursively expand it
true => cmpts.extend(self.expand_expr(&alias_expr, visitor)?),
true => cmpts.extend(self.expand_expr(&alias_expr, visitor)?.cmpts),
// Else expand it to a string, then apply all operations
// Note: We expand to string even if we don't *need* to to ensure the user doesn't
@ -104,7 +100,7 @@ impl Expander {
})
.collect();
Ok(cmpts)
Ok(Expr { cmpts })
}
/// Expands an expression into a string
@ -113,7 +109,7 @@ impl Expander {
expr: &Expr<'s>,
visitor: &mut impl Visitor<'s>,
) -> Result<CowStr<'s>, AppError> {
let expr_cmpts = self.expand_expr(expr, visitor)?.into_boxed_slice();
let expr_cmpts = self.expand_expr(expr, visitor)?.cmpts.into_boxed_slice();
let res = match Box::<[_; 0]>::try_from(expr_cmpts) {
Ok(box []) => Ok("".into()),
Err(cmpts) => match Box::<[_; 1]>::try_from(cmpts) {