2021-04-18 20:33:55 +00:00
|
|
|
use std::ops::Range;
|
|
|
|
|
2021-06-06 22:09:45 +00:00
|
|
|
use crate::{brian::InterpretError, lexer::Token};
|
2021-06-02 20:29:31 +00:00
|
|
|
|
2021-04-18 20:33:55 +00:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct Error {
|
|
|
|
pub kind: ErrorKind,
|
2021-06-06 21:13:48 +00:00
|
|
|
pub span: Range<usize>,
|
2021-04-18 20:33:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub enum ErrorKind {
|
2021-04-26 08:44:42 +00:00
|
|
|
SyntaxError(String),
|
2021-06-06 22:09:45 +00:00
|
|
|
UnexpectedEof,
|
|
|
|
UnexpectedToken(Token),
|
2021-04-27 09:09:19 +00:00
|
|
|
InvalidIdentifier,
|
2021-05-20 23:18:01 +00:00
|
|
|
UnknownVariable(String),
|
|
|
|
MeloVariable(String),
|
|
|
|
TypeError(String),
|
2021-05-26 02:22:38 +00:00
|
|
|
TopLevelBreak,
|
2021-05-27 15:05:57 +00:00
|
|
|
ArithmeticError,
|
2021-06-02 20:29:31 +00:00
|
|
|
BfInterpretError(InterpretError),
|
2021-06-06 22:09:45 +00:00
|
|
|
MissingLhs,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Error {
|
|
|
|
pub fn new(kind: ErrorKind, span: Range<usize>) -> Self {
|
|
|
|
Self { kind, span }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn unexpected_eof() -> Self {
|
|
|
|
Self::new(ErrorKind::UnexpectedEof, 0..0)
|
|
|
|
}
|
2021-04-27 11:48:56 +00:00
|
|
|
}
|