2021-04-18 15:33:55 -05:00
|
|
|
use std::ops::Range;
|
|
|
|
|
2021-06-06 17:09:45 -05:00
|
|
|
use crate::{brian::InterpretError, lexer::Token};
|
2021-06-02 15:29:31 -05:00
|
|
|
|
2021-04-18 15:33:55 -05:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct Error {
|
|
|
|
pub kind: ErrorKind,
|
2021-06-06 16:13:48 -05:00
|
|
|
pub span: Range<usize>,
|
2021-04-18 15:33:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub enum ErrorKind {
|
2021-04-26 03:44:42 -05:00
|
|
|
SyntaxError(String),
|
2021-06-06 17:09:45 -05:00
|
|
|
UnexpectedEof,
|
|
|
|
UnexpectedToken(Token),
|
2021-04-27 04:09:19 -05:00
|
|
|
InvalidIdentifier,
|
2021-05-20 18:18:01 -05:00
|
|
|
UnknownVariable(String),
|
|
|
|
MeloVariable(String),
|
|
|
|
TypeError(String),
|
2021-05-25 21:22:38 -05:00
|
|
|
TopLevelBreak,
|
2021-05-27 10:05:57 -05:00
|
|
|
ArithmeticError,
|
2021-06-02 15:29:31 -05:00
|
|
|
BfInterpretError(InterpretError),
|
2021-06-06 17:09:45 -05: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 06:48:56 -05:00
|
|
|
}
|