improved error messages

- some small bugs are now fixed
- include comments in error messages (if this causes issues, use --hide-comments)
- colors should make more sense now
- error-related things moved to mers_lib/src/errors/
This commit is contained in:
Mark
2023-11-16 14:50:09 +01:00
parent c39e784939
commit 12925fed67
33 changed files with 462 additions and 320 deletions

View File

@@ -5,7 +5,8 @@ use std::{
use crate::{
data::{self, Data, MersType, Type},
program::run::{CheckError, CheckInfo, Info},
errors::CheckError,
program::run::{CheckInfo, Info},
};
use super::Config;

View File

@@ -9,10 +9,8 @@ use crate::{
function::{Function, FunctionT},
Data, MersData, MersType, Type,
},
program::{
self,
run::{CheckError, CheckInfo},
},
errors::CheckError,
program::{self, run::CheckInfo},
};
use super::Config;
@@ -140,13 +138,6 @@ impl Config {
}
}
fn iter_out(
a: &Type,
name: &str,
func: impl Fn(&FunctionT) -> ItersT + Sync + Send,
) -> Result<Type, CheckError> {
iter_out_arg(a, name, func)
}
fn iter_out_arg<T: MersType>(
a: &Type,
name: &str,

View File

@@ -135,7 +135,7 @@ impl Config {
Data::new(data::function::Function {
info: Arc::new(program::run::Info::neverused()),
info_check: Arc::new(Mutex::new(CheckInfo::neverused())),
out: Arc::new(|a, i| {
out: Arc::new(|a, _i| {
if let Some(v) = a.iterable() {
Ok(Type::new(ListT(v)))
} else {

View File

@@ -2,10 +2,8 @@ use std::sync::{Arc, Mutex};
use crate::{
data::{self, Data, MersType, Type},
program::{
self,
run::{CheckError, CheckInfo},
},
errors::CheckError,
program::{self, run::CheckInfo},
};
use super::Config;

View File

@@ -6,10 +6,8 @@ use std::{
use crate::{
data::{self, Data, MersData, MersType, Type},
program::{
self,
run::{CheckError, CheckInfo},
},
errors::CheckError,
program::{self, run::CheckInfo},
};
use super::Config;

View File

@@ -3,8 +3,11 @@ use std::{
sync::{Arc, Mutex},
};
use colored::Colorize;
use crate::{
data::{self, Data, Type},
errors::error_colors,
program::{self, run::CheckInfo},
};
@@ -23,7 +26,17 @@ impl Config {
Data::new(data::function::Function {
info: Arc::new(program::run::Info::neverused()),
info_check: Arc::new(Mutex::new(CheckInfo::neverused())),
out: Arc::new(|a, i| Ok(Type::new(data::string::StringT))),
out: Arc::new(|a, _i| {
if a.is_zero_tuple() {
Ok(Type::new(data::string::StringT))
} else {
Err(format!(
"expected (), got {}",
a.to_string().color(error_colors::FunctionArgument)
)
.into())
}
}),
run: Arc::new(|_a, _i| {
let mut line = String::new();
_ = std::io::stdin().read_line(&mut line);
@@ -36,7 +49,7 @@ impl Config {
Data::new(data::function::Function {
info: Arc::new(program::run::Info::neverused()),
info_check: Arc::new(Mutex::new(CheckInfo::neverused())),
out: Arc::new(|a, i| Ok(Type::empty_tuple())),
out: Arc::new(|_a, _i| Ok(Type::empty_tuple())),
run: Arc::new(|a, _i| {
eprintln!("{:#?}", a.get());
Data::empty_tuple()
@@ -48,10 +61,10 @@ impl Config {
Data::new(data::function::Function {
info: Arc::new(program::run::Info::neverused()),
info_check: Arc::new(Mutex::new(CheckInfo::neverused())),
out: Arc::new(|a, i| Ok(Type::empty_tuple())),
out: Arc::new(|_a, _i| Ok(Type::empty_tuple())),
run: Arc::new(|a, _i| {
eprint!("{}", a.get());
std::io::stderr().lock().flush();
_ = std::io::stderr().lock().flush();
Data::empty_tuple()
}),
}),
@@ -61,7 +74,7 @@ impl Config {
Data::new(data::function::Function {
info: Arc::new(program::run::Info::neverused()),
info_check: Arc::new(Mutex::new(CheckInfo::neverused())),
out: Arc::new(|a, i| Ok(Type::empty_tuple())),
out: Arc::new(|_a, _i| Ok(Type::empty_tuple())),
run: Arc::new(|a, _i| {
eprintln!("{}", a.get());
Data::empty_tuple()
@@ -73,10 +86,10 @@ impl Config {
Data::new(data::function::Function {
info: Arc::new(program::run::Info::neverused()),
info_check: Arc::new(Mutex::new(CheckInfo::neverused())),
out: Arc::new(|a, i| Ok(Type::empty_tuple())),
out: Arc::new(|_a, _i| Ok(Type::empty_tuple())),
run: Arc::new(|a, _i| {
print!("{}", a.get());
std::io::stdout().lock().flush();
_ = std::io::stdout().lock().flush();
Data::empty_tuple()
}),
}),
@@ -86,7 +99,7 @@ impl Config {
Data::new(data::function::Function {
info: Arc::new(program::run::Info::neverused()),
info_check: Arc::new(Mutex::new(CheckInfo::neverused())),
out: Arc::new(|a, i| Ok(Type::empty_tuple())),
out: Arc::new(|_a, _i| Ok(Type::empty_tuple())),
run: Arc::new(|a, _i| {
println!("{}", a.get());
Data::empty_tuple()