cl-interpret: remove Loc from error type

This allows removal of intermediate expression metadata from the AST
This commit is contained in:
John 2024-04-13 02:54:02 -05:00
parent 21c9909f0c
commit 3b0190b389
2 changed files with 10 additions and 11 deletions

View File

@ -141,7 +141,7 @@ impl Interpret for Assign {
let head = match &head.kind {
ExprKind::Path(Path { parts, .. }) if parts.len() == 1 => {
match parts.last().expect("parts should not be empty") {
PathPart::SuperKw => Err(Error::NotAssignable(head.extents.head))?,
PathPart::SuperKw => Err(Error::NotAssignable)?,
PathPart::SelfKw => todo!("Assignment to `self`"),
PathPart::Ident(Identifier(s)) => s,
}
@ -153,7 +153,7 @@ impl Interpret for Assign {
ExprKind::Empty | ExprKind::Group(_) | ExprKind::Tuple(_) => {
todo!("Pattern Destructuring?")
}
_ => Err(Error::NotAssignable(head.extents.head))?,
_ => Err(Error::NotAssignable)?,
};
// Get the initializer and the tail
let init = tail.interpret(env)?;

View File

@ -522,7 +522,6 @@ pub mod error {
//! The [Error] type represents any error thrown by the [Environment](super::Environment)
use super::temp_type_impl::ConValue;
use cl_structures::span::Loc;
pub type IResult<T> = Result<T, Error>;
@ -546,12 +545,12 @@ pub mod error {
TypeError,
/// In clause of For loop didn't yield a Range
NotIterable,
/// A value at this [location](struct@Loc) can't be indexed
NotIndexable(Loc),
/// A value could not be indexed
NotIndexable,
/// An array index went out of bounds
OobIndex(usize, usize),
/// An expression at this [location](struct@Loc)ation is not assignable
NotAssignable(Loc),
/// An expression is not assignable
NotAssignable,
/// A name was not defined in scope before being used
NotDefined(String),
/// A name was defined but not initialized
@ -578,14 +577,14 @@ pub mod error {
Error::ScopeExit => "Exited the last scope. This is a logic bug.".fmt(f),
Error::TypeError => "Incompatible types".fmt(f),
Error::NotIterable => "`in` clause of `for` loop did not yield an iterable".fmt(f),
Error::NotIndexable(location) => {
write!(f, "{location} expression cannot be indexed")
Error::NotIndexable => {
write!(f, "expression cannot be indexed")
}
Error::OobIndex(idx, len) => {
write!(f, "Index out of bounds: index was {idx}. but len is {len}")
}
Error::NotAssignable(location) => {
write!(f, "{location} expression is not assignable")
Error::NotAssignable => {
write!(f, "expression is not assignable")
}
Error::NotDefined(value) => {
write!(f, "{value} not bound. Did you mean `let {value};`?")