refactor(ast): Improve error type, remove unnecessary eof judge
This commit is contained in:
+1
-19
@@ -1,16 +1,7 @@
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::lexer::types::TokenValue;
|
||||
use crate::ast::err::ParseError;
|
||||
|
||||
// #[derive(Debug, Clone, PartialEq, Eq, Error)]
|
||||
// pub enum ParseError {
|
||||
// BlockStmt(#[from] BlockStmtError)
|
||||
// }
|
||||
// #[derive(Debug, Clone, PartialEq, Eq, Error)]
|
||||
// pub enum BlockStmtError {
|
||||
// MissingLBrace,
|
||||
// MissingRBrace,
|
||||
// }
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Error)]
|
||||
pub enum LexingError {
|
||||
#[error("invalid int literal")]
|
||||
@@ -23,15 +14,6 @@ pub enum LexingError {
|
||||
UnrecognizedToken(String),
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Error)]
|
||||
pub enum ParseError {
|
||||
#[error("unexpected token {}, expect {}", .0, .1)]
|
||||
UnexpectedToken(TokenValue, &'static str),
|
||||
#[error("cannot combine with previous {}", .0)]
|
||||
CantCombineWith(TokenValue),
|
||||
#[error("expect {0} after")]
|
||||
ExpectButEof(&'static str),
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Error)]
|
||||
pub enum FrontendError {
|
||||
#[error(transparent)]
|
||||
Lexing(#[from] LexingError),
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@ impl std::fmt::Display for TokenValue {
|
||||
TokenValue::Return => write!(f, "return"),
|
||||
TokenValue::Break => write!(f, "break"),
|
||||
TokenValue::Continue => write!(f, "continue"),
|
||||
TokenValue::Eof => write!(f, "<EOF>"),
|
||||
TokenValue::Eof => write!(f, "end of input"),
|
||||
TokenValue::Unrecognized => write!(f, "unrecognized"),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user