trait Add for ErrorAndSpan
At the moment, we propagate parsing errors pretty random up through the call stack when they occur. I propose that we implement the std::ops::BitOr
trait, so we can use constructs like this:
let eas = yield_parse!(Exp::Field, Box::new, self.parse_field_exp(offset));
eas |= yield_parse!(Exp::FunCall, Box::new, self.parse_fun_call(offset));
eas |= yield_parse!(Exp::Ident, self.parse_ident(offset));
eas |= yield_parse!(Exp::Int, self.parse_literal_int(offset));
eas |= yield_parse!(Exp::Char, self.parse_literal_char(offset));
eas |= yield_parse!(Exp::Bool, self.parse_literal_bool(offset));
The implementation of BitOr should then return the first occurring error (a.k.a. the error with the smallest span.start
). This way, we will be able to describe the correct error to the user, instead of just picking one at random, or needing to generate a custom one.