pub mod prolog;
pub mod sexpr;
pub mod tptp;
pub use prolog::parse_prolog;
pub use sexpr::parse_sexpr;
pub use tptp::parse_tptp;
use anyhow::{anyhow, Result};
pub fn parse_auto(input: &str) -> Result<tensorlogic_ir::TLExpr> {
let trimmed = input.trim();
if trimmed.starts_with("fof(") || trimmed.starts_with("cnf(") {
parse_tptp(trimmed)
} else if trimmed.starts_with('(') {
parse_sexpr(trimmed)
} else if trimmed.contains(":-") || trimmed.contains('.') {
parse_prolog(trimmed)
} else {
Err(anyhow!(
"Unable to auto-detect format for input: {}",
trimmed
))
}
}
#[cfg(test)]
mod tests {
use super::*;
use tensorlogic_ir::TLExpr;
#[test]
fn test_auto_detect_sexpr() {
let expr = parse_auto("(and (P x) (Q x))").unwrap();
assert!(matches!(expr, TLExpr::And(_, _)));
}
#[test]
fn test_auto_detect_prolog() {
let expr = parse_auto("mortal(X).").unwrap();
assert!(matches!(expr, TLExpr::Pred { .. }));
}
#[test]
fn test_auto_detect_unknown() {
let result = parse_auto("random text without structure");
assert!(result.is_err());
}
}