typr-core 0.5.5

Core type checking and transpilation logic for TypR - a typed superset of R
Documentation
#![allow(
    dead_code,
    unused_variables,
    unused_imports,
    unreachable_code,
    unused_assignments
)]
use crate::components::context::config::Config;
use crate::components::context::Context;
use crate::components::error_message::help_data::HelpData;
use crate::components::language::Lang;
use crate::components::language::ModulePosition;
use crate::components::r#type::Type;

pub struct ModuleLang {
    name: String,
    members: Vec<Lang>,
    position: ModulePosition,
    config: Config,
    help_data: HelpData,
}

impl ModuleLang {
    pub fn to_record(self, type_module: &Type, context: &Context) -> Lang {
        let new_args = self
            .members
            .iter()
            .flat_map(|arg| arg.clone().to_arg_value(type_module, context))
            .flatten()
            .collect::<Vec<_>>();
        Lang::List {
            value: new_args,
            spreads: Vec::new(),
            help_data: self.get_help_data(),
        }
    }

    pub fn get_help_data(&self) -> HelpData {
        self.help_data.clone()
    }
}

impl TryFrom<Lang> for ModuleLang {
    type Error = String;

    fn try_from(value: Lang) -> Result<Self, Self::Error> {
        match value {
            Lang::Module {
                name,
                body: args,
                module_position: position,
                config,
                help_data: h,
            } => Ok(ModuleLang {
                name,
                members: args,
                position,
                config,
                help_data: h,
            }),
            _ => Err(format!(
                "{} can't be converted to struct ModuleLang",
                value.simple_print()
            )),
        }
    }
}