use super::{super::base::*, lexical_fold};
use anyhow::Result;
use narsese::{conversion::inter_type::lexical_fold::TryFoldInto, lexical::Term as TermLexical};
use std::str::FromStr;
impl Term {
#[inline]
pub fn from_lexical(lexical: TermLexical) -> Result<Self> {
lexical_fold::lexical_fold(lexical)
}
#[inline]
#[cfg(feature = "dialect_parser")]
pub fn from_dialect(input: &str) -> Result<Self> {
use super::super::dialect::parse_term;
parse_term(input)
}
}
impl TryFoldInto<'_, Term, anyhow::Error> for TermLexical {
type Folder = ();
fn try_fold_into(self, _: &'_ Self::Folder) -> Result<Term> {
Term::from_lexical(self)
}
}
impl TryFrom<TermLexical> for Term {
type Error = anyhow::Error;
#[inline]
fn try_from(value: TermLexical) -> Result<Self, Self::Error> {
value.try_fold_into(&())
}
}
impl FromStr for Term {
type Err = anyhow::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
s.try_into()
}
}
impl TryFrom<&str> for Term {
type Error = anyhow::Error;
fn try_from(s: &str) -> Result<Self, Self::Error> {
use narsese::conversion::string::impl_lexical::format_instances::FORMAT_ASCII;
let lexical = FORMAT_ASCII.parse(s)?;
let term = lexical.try_into_term()?;
let term = term.try_into()?;
Ok(term)
}
}