Unfortunately, using matches is disgusting:
pub fn plus_op(&self, other: Type) -> RTResult {
match self {
Type::NullType {start: selfstart, end: selfend} => {
let mut res = RTResult {exception: InterpreterException {failed: false, name: "".to_string(), msg: "".to_string(), start: selfstart.clone(), end: selfend.clone()}, value: Type::NullType {start: selfstart.clone(), end: selfend.clone()}};
return res.failure(InterpreterException {
failed: true,
name : "TypeError".to_string(),
msg : "Null can not be added to".to_string(),
start : selfstart.clone(), end: selfend.clone()
});
},
Type::IntType {value: selfvalue, start: selfstart, end: _} => {
match other {
Type::IntType {value: othervalue, start: _, end: otherend} => {
let mut res = RTResult {exception: InterpreterException {failed: false, name: "".to_string(), msg: "".to_string(), start: selfstart.clone(), end: otherend.clone()}, value: Type::NullType {start: selfstart.clone(), end: otherend.clone()}};
return res.success(
Type::IntType{value: selfvalue + othervalue, start: selfstart.clone(), end: otherend}
);
},
Type::NullType {start: _, end: otherend} => {
let mut res = RTResult {exception: InterpreterException {failed: false, name: "".to_string(), msg: "".to_string(), start: selfstart.clone(), end: otherend.clone()}, value: Type::NullType {start: selfstart.clone(), end: otherend.clone()}};
return res.failure(InterpreterException {
failed: true,
name : "TypeError".to_string(),
msg : "Null can not be added to Int".to_string(),
start : selfstart.clone(), end: otherend.clone()
});
},
Type::FloatType {value: _, start: _, end: otherend} => {
let mut res = RTResult {exception: InterpreterException {failed: false, name: "".to_string(), msg: "".to_string(), start: selfstart.clone(), end: otherend.clone()}, value: Type::NullType {start: selfstart.clone(), end: otherend.clone()}};
return res.failure(InterpreterException {
failed: true,
name : "TypeError".to_string(),
msg : "Float can not be added to Int".to_string(),
start : selfstart.clone(), end: otherend.clone()
});
},
Type::StringType {value: _, start: _, end: otherend} => {
let mut res = RTResult {exception: InterpreterException {failed: false, name: "".to_string(), msg: "".to_string(), start: selfstart.clone(), end: otherend.clone()}, value: Type::NullType {start: selfstart.clone(), end: otherend.clone()}};
return res.failure(InterpreterException {
failed: true,
name : "TypeError".to_string(),
msg : "String can not be added to Int".to_string(),
start : selfstart.clone(), end: otherend.clone()
});
}
}
},
Type::FloatType {value: selfvalue, start: selfstart, end: _} => {
match other {
Type::FloatType {value: othervalue, start: _, end: otherend} => {
let mut res = RTResult {exception: InterpreterException {failed: false, name: "".to_string(), msg: "".to_string(), start: selfstart.clone(), end: otherend.clone()}, value: Type::NullType {start: selfstart.clone(), end: otherend.clone()}};
return res.success(
Type::FloatType{value: selfvalue + othervalue, start: selfstart.clone(), end: otherend}
);
},
Type::NullType {start: _, end: otherend} => {
let mut res = RTResult {exception: InterpreterException {failed: false, name: "".to_string(), msg: "".to_string(), start: selfstart.clone(), end: otherend.clone()}, value: Type::NullType {start: selfstart.clone(), end: otherend.clone()}};
return res.failure(InterpreterException {
failed: true,
name : "TypeError".to_string(),
msg : "Null can not be added to Float".to_string(),
start : selfstart.clone(), end: otherend.clone()
});
},
Type::IntType {value: _, start: _, end: otherend} => {
let mut res = RTResult {exception: InterpreterException {failed: false, name: "".to_string(), msg: "".to_string(), start: selfstart.clone(), end: otherend.clone()}, value: Type::NullType {start: selfstart.clone(), end: otherend.clone()}};
return res.failure(InterpreterException {
failed: true,
name : "TypeError".to_string(),
msg : "Int can not be added to Float".to_string(),
start : selfstart.clone(), end: otherend.clone()
});
},
Type::StringType {value: _, start: _, end: otherend} => {
let mut res = RTResult {exception: InterpreterException {failed: false, name: "".to_string(), msg: "".to_string(), start: selfstart.clone(), end: otherend.clone()}, value: Type::NullType {start: selfstart.clone(), end: otherend.clone()}};
return res.failure(InterpreterException {
failed: true,
name : "TypeError".to_string(),
msg : "String can not be added to Float".to_string(),
start : selfstart.clone(), end: otherend.clone()
});
}
}
},
Type::StringType {value: selfvalue, start: selfstart, end: _} => {
match other {
Type::StringType {value: othervalue, start: _, end: otherend} => {
let mut res = RTResult {exception: InterpreterException {failed: false, name: "".to_string(), msg: "".to_string(), start: selfstart.clone(), end: otherend.clone()}, value: Type::NullType {start: selfstart.clone(), end: otherend.clone()}};
return res.success(
Type::StringType{value: selfvalue.to_string() + othervalue.as_str(), start: selfstart.clone(), end: otherend}
);
},
Type::NullType {start: _, end: otherend} => {
let mut res = RTResult {exception: InterpreterException {failed: false, name: "".to_string(), msg: "".to_string(), start: selfstart.clone(), end: otherend.clone()}, value: Type::NullType {start: selfstart.clone(), end: otherend.clone()}};
return res.failure(InterpreterException {
failed: true,
name : "TypeError".to_string(),
msg : "Null can not be added to String".to_string(),
start : selfstart.clone(), end: otherend.clone()
});
},
Type::IntType {value: _, start: _, end: otherend} => {
let mut res = RTResult {exception: InterpreterException {failed: false, name: "".to_string(), msg: "".to_string(), start: selfstart.clone(), end: otherend.clone()}, value: Type::NullType {start: selfstart.clone(), end: otherend.clone()}};
return res.failure(InterpreterException {
failed: true,
name : "TypeError".to_string(),
msg : "Int can not be added to String".to_string(),
start : selfstart.clone(), end: otherend.clone()
});
},
Type::FloatType {value: _, start: _, end: otherend} => {
let mut res = RTResult {exception: InterpreterException {failed: false, name: "".to_string(), msg: "".to_string(), start: selfstart.clone(), end: otherend.clone()}, value: Type::NullType {start: selfstart.clone(), end: otherend.clone()}};
return res.failure(InterpreterException {
failed: true,
name : "TypeError".to_string(),
msg : "Float can not be added to String".to_string(),
start : selfstart.clone(), end: otherend.clone()
});
}
}
}
}
}