pub mod codes;
mod extract;
mod registry_data;
mod schema;
mod text;
pub mod transform;
use std::sync::Arc;
use crossfoot_core::{ns, Diagnostic, Document, Dts, Instance};
pub struct InlineSet {
pub instances: Vec<Instance>,
pub diags: Vec<Diagnostic>,
}
pub fn is_inline(doc: &Document) -> bool {
let Some(r) = doc.document_element() else {
return false;
};
if r.ns_decls()
.iter()
.any(|(_, u)| &**u == ns::IX11 || &**u == ns::IX10)
&& !r.is(ns::XBRLI, "xbrl")
&& !r.is(ns::LINK, "linkbase")
&& r.local() != "schema"
{
return true;
}
if r.local() != "html" {
return false;
}
r.descendant_elements()
.any(|n| n.ns() == ns::IX11 || n.ns() == ns::IX10)
}
pub fn load_document_set(docs: Vec<Arc<Document>>) -> InlineSet {
extract::load(docs)
}
pub fn validate(dts: &Dts, set: &InlineSet) -> Vec<Diagnostic> {
let mut out = Vec::new();
for inst in &set.instances {
for f in &inst.facts {
let Some(c) = dts.concept(&f.concept) else {
continue;
};
let Some(el) = f.inline.as_ref().and_then(|i| i.element) else {
continue;
};
let n = inst.node(el);
match n.local() {
"nonFraction" if !c.is_numeric => {
out.push(
Diagnostic::error(
codes::NON_FRACTION_NON_NUMERIC,
format!("ix:nonFraction used for non-numeric concept {}", f.concept),
)
.at(n),
);
}
"fraction" if !c.is_fraction => {
out.push(
Diagnostic::error(
codes::FRACTION_NOT_FRACTION_TYPE,
format!(
"ix:fraction used for concept {} which is not a fraction type",
f.concept
),
)
.at(n),
);
}
_ => {}
}
}
}
out
}