use crate::runtimes::TranslateError;
use anyhow::Result;
use navm::{
cmd::Cmd,
output::{Operation, Output},
};
pub fn input_translate(cmd: Cmd) -> Result<String> {
let content = match cmd {
Cmd::NSE(..) => cmd.tail(),
Cmd::CYC(n) => format!(":c {n}"),
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,
},
"out" => Output::OUT {
narsese: None,
content_raw: content,
},
"in" => 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)
}