added CLI

This commit is contained in:
afonya 2025-06-16 18:15:57 +02:00
parent bd5ce01234
commit 5d43674d0e
Signed by: afonya
GPG key ID: EBB9C4CAFAAFB2DC
8 changed files with 395 additions and 357 deletions

View file

@ -70,6 +70,17 @@ fn convert_types_to_short(typ: &ErrorType) -> String {
ErrorType::IOError => String::from("IO:"),
}
}
pub fn reverse_type_short(str: String) -> ErrorType {
match str.as_str() {
"ST" => ErrorType::SyntaxError,
"TP" => ErrorType::TypeError,
"MT" => ErrorType::MathError,
"SM" => ErrorType::SemanticError,
"MC" => ErrorType::MachineError,
"IO" => ErrorType::IOError,
_ => panic!("Unknown error type short: {}", str),
}
}
fn convert_subtypes_to_string(stype: &ErrorSubType) -> String {
match stype {
ErrorSubType::UnexpectedEnd => String::from("Unexpected end"),
@ -126,6 +137,35 @@ fn convert_subtypes_to_short(stype: &ErrorSubType) -> String {
ErrorSubType::RuntimeError => String::from("RE:"),
}
}
pub fn reverse_subtype_short(str: String) -> ErrorSubType {
match str.as_str() {
"UE" => ErrorSubType::UnexpectedEnd,
"UP" => ErrorSubType::UnexpectedOperation,
"EX" => ErrorSubType::Expected,
"UN" => ErrorSubType::Unexpected,
"IK" => ErrorSubType::InvalidTableKeys,
"UC" => ErrorSubType::Unclosed,
"EW" => ErrorSubType::ElseWithoutIf,
"BC" => ErrorSubType::BreakContinueWithoutLoop,
"UO" => ErrorSubType::UnknownOperation,
"VN" => ErrorSubType::VariableNotFound,
"VE" => ErrorSubType::VariableAlreadyExists,
"AD" => ErrorSubType::ArgumentDuplication,
"RF" => ErrorSubType::RegisterNotFound,
"MO" => ErrorSubType::MemoryOutOfBounds,
"OC" => ErrorSubType::UnknownOPCode,
"UF" => ErrorSubType::UnknownFunction,
"US" => ErrorSubType::UnknownString,
"UM" => ErrorSubType::UnknownMemoryLocation,
"NF" => ErrorSubType::NonFunctionCall,
"DZ" => ErrorSubType::DivisionByZero,
"WT" => ErrorSubType::WrongType,
"TA" => ErrorSubType::TooManyArguments,
"FE" => ErrorSubType::FileError,
"RE" => ErrorSubType::RuntimeError,
_ => panic!("Unknown error subtype short: {}", str),
}
}
pub fn create_error(message: &str, position: usize, typ: ErrorType, stype: ErrorSubType) -> ASLError {
let mut code = convert_types_to_short(&typ);