narust_158/language/conversion/
from.rs1use super::{super::base::*, lexical_fold};
4use anyhow::Result;
5use narsese::{conversion::inter_type::lexical_fold::TryFoldInto, lexical::Term as TermLexical};
6use std::str::FromStr;
7
8impl Term {
9 #[inline]
19 pub fn from_lexical(lexical: TermLexical) -> Result<Self> {
20 lexical_fold::lexical_fold(lexical)
21 }
22
23 #[inline]
28 #[cfg(feature = "dialect_parser")]
29 pub fn from_dialect(input: &str) -> Result<Self> {
30 use super::super::dialect::parse_term;
31 parse_term(input)
32 }
33}
34
35impl TryFoldInto<'_, Term, anyhow::Error> for TermLexical {
37 type Folder = ();
39
40 fn try_fold_into(self, _: &'_ Self::Folder) -> Result<Term> {
41 Term::from_lexical(self)
42 }
43}
44
45impl TryFrom<TermLexical> for Term {
47 type Error = anyhow::Error;
48
49 #[inline]
50 fn try_from(value: TermLexical) -> Result<Self, Self::Error> {
51 value.try_fold_into(&())
52 }
53}
54
55impl FromStr for Term {
58 type Err = anyhow::Error;
59
60 fn from_str(s: &str) -> Result<Self, Self::Err> {
61 s.try_into()
62 }
63}
64
65impl TryFrom<&str> for Term {
69 type Error = anyhow::Error;
70
71 fn try_from(s: &str) -> Result<Self, Self::Error> {
72 use narsese::conversion::string::impl_lexical::format_instances::FORMAT_ASCII;
73 let lexical = FORMAT_ASCII.parse(s)?;
75 let term = lexical.try_into_term()?;
77 let term = term.try_into()?;
79 Ok(term)
81 }
82}