Skip to content

Commit

Permalink
feat: display more information when an invalid expression construct i…
Browse files Browse the repository at this point in the history
…s encountered (related to #10)
  • Loading branch information
oddlama committed Mar 8, 2023
1 parent e50c6b1 commit 215eec3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/bridge/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ pub enum Expr {

#[derive(Error, Debug, Clone)]
pub enum EvalError {
#[error("encountered a terminal that cannot be evaluated")]
InvalidTerminal,
#[error("encountered a terminal that cannot be evaluated: {terminal}")]
InvalidTerminal{ terminal: String },
}

impl Expr {
Expand Down Expand Up @@ -102,7 +102,7 @@ impl Expr {
) =>
unsafe { ((**a).get_tristate_value() != (**b).get_tristate_value()).into() },
Expr::Terminal(Terminal::Symbol(s)) => unsafe { (**s).get_tristate_value() },
Expr::Terminal(_) => return Err(EvalError::InvalidTerminal),
Expr::Terminal(t) => return Err(EvalError::InvalidTerminal{ terminal: format!("{:?}", t) }),
})
}

Expand Down
10 changes: 5 additions & 5 deletions src/bridge/satisfier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub enum SolveError {
Unsatisfiable,
#[error("complex negated expressions are unsupported")]
ComplexNot,
#[error("expression contains unsupported constructs")]
UnsupportedConstituents,
#[error("expression contains at least one unsupported construct: {description}")]
UnsupportedConstituents { description: String },
#[error("expression contains an ambiguous comparison")]
AmbiguousComparison,
#[error("encountered an invalid symbol")]
Expand Down Expand Up @@ -219,7 +219,7 @@ impl Solver for SimpleSolver {
fn satisfy(&self, bridge: &Bridge, expr: &Expr, desired_value: Tristate) -> Result<Assignments, SolveError> {
// If the expression already evaluates to at least the desired value,
// we don't have to change any variables
if expr.eval().map_err(|_| SolveError::UnsupportedConstituents)? >= desired_value {
if expr.eval().map_err(|e| SolveError::UnsupportedConstituents{ description: e.to_string() })? >= desired_value {
return Ok(HashMap::new());
}

Expand Down Expand Up @@ -262,7 +262,7 @@ impl Solver for SimpleSolver {
}
}
Expr::Terminal(Terminal::Symbol(s)) => self.satisfy_eq(&bridge.wrap_symbol(*s), Tristate::No)?,
Expr::Terminal(_) => return Err(SolveError::UnsupportedConstituents),
Expr::Terminal(k) => return Err(SolveError::UnsupportedConstituents{ description: format!("{:?}", k) }),
_ => return Err(SolveError::ComplexNot),
},
Expr::Terminal(Terminal::Eq(a, b)) => {
Expand Down Expand Up @@ -298,7 +298,7 @@ impl Solver for SimpleSolver {
};
self.satisfy_neq(&s, Tristate::No, desired_value)?
}
Expr::Terminal(_) => return Err(SolveError::UnsupportedConstituents),
Expr::Terminal(k) => return Err(SolveError::UnsupportedConstituents{ description: format!("{:?}", k)}),
})
}
}
Expand Down

0 comments on commit 215eec3

Please sign in to comment.