2024-02-05 07:05:48 +00:00
use std ::fmt ::Display ;
pub enum RunError {
RequestArgsInMainModule ,
ExecuteItself ( String ) ,
FailToReadFile ,
FailToGetCharFromConsole ,
InvalidInputUShortInt ,
PickTooDeep ,
PickOutOfBounds ,
FailToReadLineFromConsole ,
UnknownLabel ( u16 ) ,
InvalidExpressionUnknownOperator ( String ) ,
MemoryEmpty ,
2024-02-05 23:48:44 +00:00
AttemptToInsertHashOrStringInst ,
AttemptToInsertEmptyConst ,
AttemptToInsertALabel
2024-02-05 07:05:48 +00:00
}
impl Display for RunError {
fn fmt ( & self , f : & mut std ::fmt ::Formatter < '_ > ) -> std ::fmt ::Result {
match self {
RunError ::RequestArgsInMainModule = > write! ( f , " Can't require arguments in the main module " ) ,
RunError ::ExecuteItself ( mod_name ) = > write! ( f , " Module {}: Can't execute itself " , mod_name ) ,
RunError ::FailToReadFile = > write! ( f , " Unable to read file " ) ,
RunError ::FailToGetCharFromConsole = > write! ( f , " Failed to get character from console " ) ,
RunError ::InvalidInputUShortInt = > write! ( f , " Invalid input. Please enter a valid unsigned short integer " ) ,
RunError ::PickTooDeep = > write! ( f , " Picking too deep " ) ,
RunError ::PickOutOfBounds = > write! ( f , " Trying to get a value out of bounds " ) ,
RunError ::FailToReadLineFromConsole = > write! ( f , " Failed to read line from console " ) ,
RunError ::UnknownLabel ( label_name ) = > write! ( f , " Unknown label: {} " , label_name ) ,
RunError ::InvalidExpressionUnknownOperator ( name ) = > write! ( f , " Invalid expression: unknown operator '{}' " , name ) ,
RunError ::MemoryEmpty = > write! ( f , " No elements in memory! " ) ,
2024-02-05 23:48:44 +00:00
RunError ::AttemptToInsertHashOrStringInst = > write! ( f , " Attempt to insert a hash/string-instruction " ) ,
RunError ::AttemptToInsertEmptyConst = > write! ( f , " Attempt to insert an empty constant " ) ,
RunError ::AttemptToInsertALabel = > write! ( f , " Attempt to insert a label " ) ,
2024-02-05 07:05:48 +00:00
}
}
}
pub enum ParseError {
2024-02-05 23:48:44 +00:00
ArgumentNotRequired ( String , usize , String )
2024-02-05 07:05:48 +00:00
}
impl Display for ParseError {
fn fmt ( & self , f : & mut std ::fmt ::Formatter < '_ > ) -> std ::fmt ::Result {
match self {
2024-02-05 23:48:44 +00:00
ParseError ::ArgumentNotRequired ( name , line_number , line ) = > write! ( f , " ParseError: \n {1} | {2} \n error: string argument for {0} not required " , name , line_number , line ) ,
2024-02-05 07:05:48 +00:00
}
}
}