Open ptal opened 8 years ago
Actually we will implement an enum ErrorCategory
that will contain the different enum of each module as well as the level of the current error:
enum ErrorCategory {
Typing(TypingError),
...
}
struct Error {
level: Level;
error: ErrorCategory;
}
It allows to store the errors in the grammar with a field errors: Vec<Error>
. We will also add utility function on the grammar to manipulate errors.
Instead of building errors in different way and everywhere in the code, we take the approach of implementing a file
error.rs
in each module (such as more or less done in rustc). We use an error enum such as:Each error has a struct containing the relevant information for later printing the error. An error enum must implement a trait to retrieve an error code:
That returns the name of the variant, here
TypeMismatch
. It is used in the error attribute #29.Each error structure must implement a trait for printing the error:
This is flexible enough to allow different kind of printing, even for a JSON output or for deep explanation (as with
--explain
in rustc).