-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca23d2f
commit 9ab3493
Showing
12 changed files
with
123 additions
and
284 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
#[derive(Debug)] | ||
use thiserror::Error; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum LexerError { | ||
#[error("Failed to parse char {0}")] | ||
UnknownCharacter(char), | ||
} | ||
|
||
impl std::fmt::Display for LexerError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::UnknownCharacter(ch) => write!(f, "Failed to parse char {ch}"), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,48 @@ | ||
use super::{ExprError, IntLitReprError, OpParseError}; | ||
use crate::{ | ||
lexer::{LexerError, Token}, | ||
symbol_table::SymbolTableError, | ||
types::{Type, TypeError}, | ||
}; | ||
use thiserror::Error; | ||
|
||
use super::{ExprError, IntLitReprError, OpParseError}; | ||
|
||
#[derive(Debug)] | ||
#[derive(Error, Debug)] | ||
pub enum ParserError { | ||
#[error(transparent)] | ||
Expr(#[from] ExprError), | ||
#[error(transparent)] | ||
Lexer(#[from] LexerError), | ||
#[error(transparent)] | ||
Type(#[from] TypeError), | ||
#[error(transparent)] | ||
Operator(#[from] OpParseError), | ||
#[error(transparent)] | ||
Int(#[from] IntLitReprError), | ||
#[error(transparent)] | ||
SymbolTable(#[from] SymbolTableError), | ||
#[error("Expected token {0}, got {1}")] | ||
UnexpectedToken(Token, Token), | ||
#[error("Expected {0}")] | ||
Expected(Token), | ||
#[error("Failed to parse type, found {0}")] | ||
ParseType(Token), | ||
#[error("Failed to parse prefix token {0}")] | ||
Prefix(Token), | ||
#[error("Failed to parse infix token {0}")] | ||
Infix(Token), | ||
Lexer(LexerError), | ||
Type(TypeError), | ||
Operator(OpParseError), | ||
Int(IntLitReprError), | ||
SymbolTable(SymbolTableError), | ||
#[error("Call to undeclared function {0}")] | ||
UndeclaredFunction(String), | ||
#[error("Function has signature ({}), got called with ({})", | ||
.0 | ||
.iter() | ||
.map(|type_| type_.to_string()) | ||
.collect::<Vec<String>>() | ||
.join(", "), | ||
.1 | ||
.iter() | ||
.map(|type_| type_.to_string()) | ||
.collect::<Vec<String>>() | ||
.join(", ") | ||
)] | ||
FunctionArguments(Vec<Type>, Vec<Type>), | ||
} | ||
|
||
impl std::error::Error for ParserError {} | ||
|
||
impl std::fmt::Display for ParserError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::UnexpectedToken(expected, actual) => { | ||
write!(f, "Expected token {expected}, got {actual}") | ||
} | ||
Self::Expected(token) => write!(f, "Expected {token}"), | ||
Self::ParseType(token) => write!(f, "Failed to parse type, found {token}"), | ||
Self::Prefix(token) => write!(f, "Failed to parse prefix token {token}"), | ||
Self::Infix(token) => write!(f, "Failed to parse infix token {token}"), | ||
Self::Lexer(e) => e.fmt(f), | ||
Self::Type(e) => e.fmt(f), | ||
Self::Operator(e) => e.fmt(f), | ||
Self::Int(e) => e.fmt(f), | ||
Self::SymbolTable(e) => e.fmt(f), | ||
Self::UndeclaredFunction(name) => write!(f, "Call to undeclared function {name}"), | ||
Self::FunctionArguments(expected, actual) => write!( | ||
f, | ||
"Function has signature ({}), got called with ({})", | ||
expected | ||
.iter() | ||
.map(|type_| type_.to_string()) | ||
.collect::<Vec<String>>() | ||
.join(", "), | ||
actual | ||
.iter() | ||
.map(|type_| type_.to_string()) | ||
.collect::<Vec<String>>() | ||
.join(", ") | ||
), | ||
} | ||
} | ||
} | ||
|
||
impl From<TypeError> for ParserError { | ||
fn from(value: TypeError) -> Self { | ||
Self::Type(value) | ||
} | ||
} | ||
|
||
impl From<SymbolTableError> for ParserError { | ||
fn from(value: SymbolTableError) -> Self { | ||
Self::SymbolTable(value) | ||
} | ||
} | ||
|
||
impl From<LexerError> for ParserError { | ||
fn from(value: LexerError) -> Self { | ||
Self::Lexer(value) | ||
} | ||
} | ||
|
||
impl From<ExprError> for ParserError { | ||
fn from(value: ExprError) -> Self { | ||
match value { | ||
ExprError::Type(e) => Self::Type(e), | ||
ExprError::SymbolTable(e) => Self::SymbolTable(e), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,10 @@ | ||
use crate::{symbol_table::SymbolTableError, types::TypeError}; | ||
use thiserror::Error; | ||
|
||
#[derive(Debug)] | ||
#[derive(Error, Debug)] | ||
pub enum ExprError { | ||
Type(TypeError), | ||
SymbolTable(SymbolTableError), | ||
} | ||
|
||
impl From<TypeError> for ExprError { | ||
fn from(value: TypeError) -> Self { | ||
Self::Type(value) | ||
} | ||
} | ||
|
||
impl From<SymbolTableError> for ExprError { | ||
fn from(value: SymbolTableError) -> Self { | ||
Self::SymbolTable(value) | ||
} | ||
#[error(transparent)] | ||
Type(#[from] TypeError), | ||
#[error(transparent)] | ||
SymbolTable(#[from] SymbolTableError), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.