1mod json;
2mod msgpack;
3mod protobuf;
4
5pub use json::to_lemma_syntax as from_json;
6pub use msgpack::to_lemma_syntax as from_msgpack;
7pub use protobuf::to_lemma_syntax as from_protobuf;
8
9use crate::{FactValue, LemmaDoc, LemmaError, LemmaType, TypeAnnotation};
10use std::collections::HashMap;
11
12pub(crate) fn find_fact_type(
14 name: &str,
15 doc: &LemmaDoc,
16 all_docs: &HashMap<String, LemmaDoc>,
17) -> Result<LemmaType, LemmaError> {
18 for fact in &doc.facts {
19 let fact_name = crate::analysis::fact_display_name(fact);
20 if fact_name == name {
21 return match &fact.value {
22 FactValue::Literal(lit) => Ok(lit.to_type()),
23 FactValue::TypeAnnotation(TypeAnnotation::LemmaType(t)) => Ok(t.clone()),
24 FactValue::DocumentReference(ref_doc) => {
25 if name.contains('.') {
26 let parts: Vec<&str> = name.splitn(2, '.').collect();
27 if parts.len() == 2 {
28 if let Some(referenced) = all_docs.get(ref_doc) {
29 return find_fact_type(parts[1], referenced, all_docs);
30 }
31 }
32 }
33 Err(LemmaError::Engine(format!(
34 "Cannot override document reference '{}'",
35 name
36 )))
37 }
38 };
39 }
40 }
41 Err(LemmaError::Engine(format!(
42 "Fact '{}' not found in document",
43 name
44 )))
45}