use super::format_in_nars_python;
use crate::runtimes::TranslateError;
use anyhow::Result;
use narsese::lexical::Narsese;
use navm::{
cmd::Cmd,
output::{Operation, Output},
};
pub fn input_translate(cmd: Cmd) -> Result<String> {
let content = match cmd {
Cmd::NSE(narsese) => format_in_nars_python(&Narsese::Task(narsese)),
Cmd::CYC(n) => n.to_string(),
Cmd::REM { .. } => String::new(),
_ => return Err(TranslateError::UnsupportedInput(cmd).into()),
};
Ok(content)
}
pub fn output_translate(content: String) -> Result<Output> {
let head = content.split_once(':').unwrap_or(("", "")).0.to_lowercase();
let output = match &*head {
"answer" => Output::ANSWER {
narsese: None,
content_raw: content,
},
"derived" => Output::OUT {
narsese: None,
content_raw: content,
},
"input" => Output::IN {
narsese: None,
content,
},
"exe" => Output::EXE {
operation: Operation::new("UNKNOWN", []),
content_raw: content,
},
"err" | "error" => Output::ERROR {
description: content,
},
_ => Output::OTHER { content },
};
Ok(output)
}