refactor(ast): Improve error type, remove unnecessary eof judge

This commit is contained in:
2026-06-12 11:11:31 +08:00
parent 4dabf32c2a
commit ef3dcb41aa
8 changed files with 62 additions and 231 deletions
+1 -19
View File
@@ -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
View File
@@ -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"),
}
}