Skip to content
Snippets Groups Projects

Resolve "Kernel errors"

Merged v-lafeychine requested to merge 19-kernel-errors-2 into main
3 files
+ 236
148
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 17
65
use crate::term::Term;
use derive_more::Display;
// TODO #19
#[derive(Clone, Debug, Display, PartialEq, Eq)]
#[display(fmt = "{}:{}-{}:{}", line1, column1, line2, column2)]
// Line/column position
pub struct Loc {
pub line1: usize,
pub column1: usize,
pub line2: usize,
pub column2: usize,
use crate::environment::EnvironmentError;
use crate::type_checker::TypeCheckerError;
use derive_more::{Display, From};
/// Type representing kernel errors.
#[derive(Clone, Debug, Display, Eq, PartialEq)]
pub struct Error {
/// The kind of form error that occurred.
pub kind: ErrorKind,
// This struct might contains more fields in the future (waiting for #15)
}
impl Loc {
pub fn new(x1: usize, y1: usize, x2: usize, y2: usize) -> Loc {
Loc {
line1: x1,
column1: y1,
line2: x2,
column2: y2,
}
}
#[non_exhaustive]
#[derive(Clone, Debug, Display, Eq, PartialEq, From)]
pub enum ErrorKind {
Environment(EnvironmentError),
TypeChecker(TypeCheckerError),
}
// TODO #19
/// Type representing kernel errors, is used by the toplevel to pretty-print errors.
#[derive(Clone, Debug, Display, PartialEq, Eq)]
pub enum KernelError {
// cannot parse command
#[display(fmt = "cannot parse: {}", _1)]
CannotParse(Loc, String),
// s is already defined
#[display(fmt = "{} is already defined", _0)]
AlreadyDefined(String),
/// s is not defined
#[display(fmt = "{} is not defined", _0)]
ConstNotFound(String),
/// t is not a universe
#[display(fmt = "{} is not a universe", _0)]
NotUniverse(Term),
/// t is not a type
#[display(fmt = "{} is not a type", _0)]
NotType(Term),
impl std::error::Error for Error {}
/// t1 and t2 are not definitionally equal
#[display(fmt = "{} and {} are not definitionaly equal", _0, _1)]
NotDefEq(Term, Term),
/// f of type t1 cannot be applied to x of type t2
#[display(fmt = "{} : {} cannot be applied to {} : {}", _0, _1, _2, _3)]
WrongArgumentType(Term, Term, Term, Term),
/// t1 of type ty is not a function so cannot be applied to t2
#[display(
fmt = "{} : {} is not a function so cannot be applied to {}",
_0,
_1,
_2
)]
NotAFunction(Term, Term, Term),
/// Expected ty1, found ty2
#[display(fmt = "expected {}, found {}", _0, _1)]
TypeMismatch(Term, Term),
}
pub type Result<T> = std::result::Result<T, Error>;
Loading