clean up unexpected

This commit is contained in:
Devyn Cairns 2024-07-03 15:25:15 -07:00
parent 1294d0f710
commit 3bdb864b9d
No known key found for this signature in database

View File

@ -51,6 +51,11 @@ pub(crate) fn compile_expression(
span: Some(expr.span), span: Some(expr.span),
}; };
let unexpected = |expr_name: &str| CompileError::UnexpectedExpression {
expr_name: expr_name.into(),
span: expr.span,
};
let move_in_reg_to_out_reg = |builder: &mut BlockBuilder| { let move_in_reg_to_out_reg = |builder: &mut BlockBuilder| {
// Ensure that out_reg contains the input value, because a call only uses one register // Ensure that out_reg contains the input value, because a call only uses one register
if let Some(in_reg) = in_reg { if let Some(in_reg) = in_reg {
@ -129,10 +134,7 @@ pub(crate) fn compile_expression(
)?; )?;
Ok(()) Ok(())
} }
Expr::VarDecl(_) => Err(CompileError::UnexpectedExpression { Expr::VarDecl(_) => Err(unexpected("VarDecl")),
expr_name: "VarDecl".into(),
span: expr.span,
}),
Expr::Call(call) => { Expr::Call(call) => {
move_in_reg_to_out_reg(builder)?; move_in_reg_to_out_reg(builder)?;
@ -143,10 +145,7 @@ pub(crate) fn compile_expression(
compile_external_call(working_set, builder, head, args, redirect_modes, out_reg) compile_external_call(working_set, builder, head, args, redirect_modes, out_reg)
} }
Expr::Operator(_) => Err(CompileError::UnexpectedExpression { Expr::Operator(_) => Err(unexpected("Operator")),
expr_name: "Operator".into(),
span: expr.span,
}),
Expr::RowCondition(_) => Err(todo("RowCondition")), Expr::RowCondition(_) => Err(todo("RowCondition")),
Expr::UnaryNot(subexpr) => { Expr::UnaryNot(subexpr) => {
drop_input(builder)?; drop_input(builder)?;
@ -365,10 +364,7 @@ pub(crate) fn compile_expression(
} }
Ok(()) Ok(())
} }
Expr::Keyword(_) => Err(CompileError::UnexpectedExpression { Expr::Keyword(_) => Err(unexpected("Keyword")),
expr_name: "Keyword".into(),
span: expr.span,
}),
Expr::ValueWithUnit(_) => Err(todo("ValueWithUnit")), Expr::ValueWithUnit(_) => Err(todo("ValueWithUnit")),
Expr::DateTime(_) => Err(todo("DateTime")), Expr::DateTime(_) => Err(todo("DateTime")),
Expr::Filepath(path, no_expand) => { Expr::Filepath(path, no_expand) => {
@ -441,8 +437,8 @@ pub(crate) fn compile_expression(
Ok(()) Ok(())
} }
} }
Expr::ImportPattern(_) => Err(todo("ImportPattern")), Expr::ImportPattern(_) => Err(unexpected("ImportPattern")),
Expr::Overlay(_) => Err(todo("Overlay")), Expr::Overlay(_) => Err(unexpected("Overlay")),
Expr::Signature(_) => ignore(builder), // no effect Expr::Signature(_) => ignore(builder), // no effect
Expr::StringInterpolation(exprs) | Expr::GlobInterpolation(exprs, _) => { Expr::StringInterpolation(exprs) | Expr::GlobInterpolation(exprs, _) => {
let mut exprs_iter = exprs.iter().peekable(); let mut exprs_iter = exprs.iter().peekable();