mirror of
https://github.com/Dummi26/mers.git
synced 2026-04-05 13:56:17 +02:00
mers rewrite is starting to be usable
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
use std::{any::Any, sync::Arc};
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::data::{function::Function, Data};
|
||||
use crate::data::{Data, Type};
|
||||
|
||||
use super::MersStatement;
|
||||
use super::{CheckError, MersStatement};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Chain {
|
||||
@@ -10,6 +10,37 @@ pub struct Chain {
|
||||
pub chained: Box<dyn MersStatement>,
|
||||
}
|
||||
impl MersStatement for Chain {
|
||||
fn check_custom(
|
||||
&self,
|
||||
info: &mut super::CheckInfo,
|
||||
init_to: Option<&Type>,
|
||||
) -> Result<Type, CheckError> {
|
||||
if init_to.is_some() {
|
||||
return Err(CheckError("can't init to statement type Chain".to_string()));
|
||||
}
|
||||
let arg = self.first.check(info, None)?;
|
||||
let func = self.chained.check(info, None)?;
|
||||
let mut o = Type::empty();
|
||||
for func in &func.types {
|
||||
if let Some(func) = func
|
||||
.as_any()
|
||||
.downcast_ref::<crate::data::function::FunctionT>()
|
||||
{
|
||||
match (func.0)(&arg) {
|
||||
Ok(t) => o.add(Arc::new(t)),
|
||||
Err(e) =>
|
||||
return Err(CheckError(format!(
|
||||
"cannot run this function with this argument (type: {arg}), because it would cause the following error:\n{e}"
|
||||
))),
|
||||
}
|
||||
} else {
|
||||
return Err(CheckError(format!(
|
||||
"cannot chain with a non-function ({func})"
|
||||
)));
|
||||
}
|
||||
}
|
||||
Ok(o)
|
||||
}
|
||||
fn run_custom(&self, info: &mut super::Info) -> Data {
|
||||
let f = self.first.run(info);
|
||||
let c = self.chained.run(info);
|
||||
|
||||
Reference in New Issue
Block a user