Error Messaging Redesign

This commit contains the following:

* New data types to support full tracebacks
* New traceback data type used across stl and ast
* Updates to tests
* fixes for error messaging in sym and some stl functions
This commit is contained in:
Ava Apples Affine 2023-05-23 22:06:11 +00:00
parent 91ad4eed12
commit 789349df48
24 changed files with 837 additions and 374 deletions

View file

@ -1,7 +1,7 @@
mod func_tests {
use relish::ast::lex;
use relish::ast::{Args, Ctr, Seg, Symbol, ValueType};
use relish::ast::{SymTable, Type, UserFn};
use relish::ast::{Args, Ctr, Seg, Symbol, ValueType, Traceback};
use relish::ast::{SymTable, Type, UserFn, start_trace};
use std::rc::Rc;
#[test]
@ -13,7 +13,7 @@ mod func_tests {
docs: String::new(),
args: Args::Strict(vec![Type::Bool]),
value: ValueType::Internal(Rc::new(
|a: &Seg, _: &mut SymTable| -> Result<Ctr, String> {
|a: &Seg, _: &mut SymTable| -> Result<Ctr, Traceback> {
let inner = a;
let mut is_bool = false;
if let Ctr::Bool(_) = *inner.car {
@ -104,7 +104,7 @@ mod func_tests {
args: Args::Strict(vec![Type::Bool]),
docs: String::new(),
value: ValueType::Internal(Rc::new(
|a: &Seg, _: &mut SymTable| -> Result<Ctr, String> {
|a: &Seg, _: &mut SymTable| -> Result<Ctr, Traceback> {
let inner = a;
if let Ctr::Bool(b) = *inner.car {
if b {
@ -113,7 +113,7 @@ mod func_tests {
Ok(Ctr::None)
}
} else {
Err("not a bool".to_string())
Err(start_trace(("", "not a bool".to_string()).into()))
}
},
)),
@ -153,7 +153,7 @@ mod func_tests {
args: Args::Strict(vec![Type::Bool]),
docs: String::new(),
value: ValueType::Internal(Rc::new(
|a: &Seg, _: &mut SymTable| -> Result<Ctr, String> {
|a: &Seg, _: &mut SymTable| -> Result<Ctr, Traceback> {
let inner = a;
let mut is_bool = false;
if let Ctr::Bool(_) = *inner.car {
@ -170,7 +170,11 @@ mod func_tests {
assert_eq!(
syms.call_symbol(&"test_func_in".to_string(), &args, true)
.err()
.unwrap(),
.unwrap()
.0
.first()
.unwrap()
.message,
"arg 1 expected to be bool".to_string(),
);
}
@ -200,7 +204,11 @@ mod func_tests {
assert_eq!(
syms.call_symbol(&"test_func_in".to_string(), &args, true)
.err()
.unwrap(),
.unwrap()
.0
.first()
.unwrap()
.message,
"expected 1 args. Got 2.".to_string(),
);
}
@ -226,7 +234,11 @@ mod func_tests {
assert_eq!(
syms.call_symbol(&"test_func_in".to_string(), &args, true)
.err()
.unwrap(),
.unwrap()
.0
.first()
.unwrap()
.message,
"expected 1 args. Got 0.".to_string(),
);
}
@ -240,7 +252,7 @@ mod func_tests {
args: Args::Strict(vec![Type::Bool]),
docs: String::new(),
value: ValueType::Internal(Rc::new(
|a: &Seg, _: &mut SymTable| -> Result<Ctr, String> {
|a: &Seg, _: &mut SymTable| -> Result<Ctr, Traceback> {
let inner = a;
let mut is_bool = false;
if let Ctr::Bool(_) = *inner.car {
@ -260,8 +272,12 @@ mod func_tests {
assert_eq!(
syms.call_symbol(&"test_func_in".to_string(), &args, true)
.err()
.unwrap(),
"error evaluating args: undefined symbol: undefined-symbol".to_string(),
.unwrap()
.0
.first()
.unwrap()
.message,
"(is an undefined symbol)".to_string(),
);
}
}