pub struct Relaxng {
pub name: String,
pub modules: Vec<Pattern>,
pub elementdefs: FxHashMap<String, String>,
pub element_reverse_defs: FxHashMap<String, String>,
pub elements: FxHashMap<String, Vec<Pattern>>,
pub defs: FxHashMap<String, Pattern>,
pub def_combiner: FxHashMap<String, DefCombiner>,
pub uses_name: FxHashMap<String, FxHashSet<String>>,
pub internal_grammars: u32,
pub document_namespaces: FxHashMap<String, String>,
pub primary_namespace: Option<String>,
pub display_strip_prefixes: Vec<String>,
}Expand description
Internal representation of a RelaxNG schema. Built by scan and
simplify; consumed by tex (and, for runtime validation,
would be consumed by Model::add_tag_content etc.).
The mutable fields beyond name and modules are populated during
simplify:
elementdefs— pattern qname → element tag, when a pattern resolves to a single element.element_reverse_defs— inverse ofelementdefs.elements— element tag → list of body patterns, accumulating across overrides / re-definitions.defs— pattern qname → its (combined) body pattern.def_combiner— pattern qname → the combiner that won the most recent definition.uses_name— pattern qname → set of containers that reference it:pattern:QNAMEfor refs at define scope,element:TAG@pattern:HOSTfor refs inside anelement TAG {…}hosted by define HOST (bareelement:TAGwhen the element sits outside any define). Drives the “Used by” lists in the schema docs;tex::symbol_usesreports the element or the host pattern, whichever identifies the definition uniquely.internal_grammars— counter for naming embedded<grammar>blocks (grammar1,grammar2, …).
Fields§
§name: StringTop-level schema name (typically the .rng filename without ext).
modules: Vec<Pattern>Modules in document-order. Populated by simplify; each entry is
a Pattern::Module whose body is populated retroactively (the
Perl push-then-extend pattern).
elementdefs: FxHashMap<String, String>§element_reverse_defs: FxHashMap<String, String>§elements: FxHashMap<String, Vec<Pattern>>§defs: FxHashMap<String, Pattern>§def_combiner: FxHashMap<String, DefCombiner>§uses_name: FxHashMap<String, FxHashSet<String>>§internal_grammars: u32§document_namespaces: FxHashMap<String, String>Document-namespace prefix → URI, populated as the scanner sees
xmlns: attributes on RelaxNG nodes.
primary_namespace: Option<String>The master grammar’s <grammar ns="…"> URI — populated by the
first call to scan_external (i.e. the schema entry point).
Subsequent included grammars don’t overwrite it. Used by the
schema-doc emitter to auto-register the corresponding namespace
prefix for elision in display names.
display_strip_prefixes: Vec<String>Namespace prefixes whose prefix: part should be elided from
rendered display names in the schema docs (clean_tex_name),
since they’re contextually obvious for the schema. Auto-populated
from primary_namespace when the schema-doc emission starts —
e.g. LaTeXML’s default namespace = "http://dlmf.nist.gov/LaTeXML"
(mapped to the ltx prefix) becomes a strip-prefix so display
names read para rather than ltx:para.
Implementations§
Source§impl Relaxng
impl Relaxng
Sourcepub fn new(name: impl Into<String>) -> Self
pub fn new(name: impl Into<String>) -> Self
Construct an empty schema state. Use Self::load_schema to
populate from an RNG file.
Sourcepub fn register_namespace(
&mut self,
prefix: impl Into<String>,
uri: impl Into<String>,
)
pub fn register_namespace( &mut self, prefix: impl Into<String>, uri: impl Into<String>, )
Register a prefix → URI binding ahead of scanning. Mirrors
Model::register_namespace for standalone callers (which don’t
have a live Model to consult). Callers that already populated
the schema’s xmlns: declarations dynamically don’t need this;
it’s intended for namespaces that trang flattens away — the most
common case is a .rnc whose default namespace = "..." carries
no prefix, so the URI is preserved on <grammar ns="..."/> but
no xmlns: survives. Later calls overwrite earlier ones.
Sourcepub fn with_latexml_defaults(&mut self) -> &mut Self
pub fn with_latexml_defaults(&mut self) -> &mut Self
Register the prefixes that Model::new_default() ships with the
LaTeXML schema (xml, ltx, svg, xlink, m, xhtml). The
runtime Model resolves these via its own registry, so this is
only needed for standalone tooling (the genschema_oxide
binary, integration tests against LaTeXML.rng) where we don’t
have a Model object to consult. Returns &mut self for chaining.
Sourcepub fn register_display_prefix_strip(&mut self, prefix: impl Into<String>)
pub fn register_display_prefix_strip(&mut self, prefix: impl Into<String>)
Register a namespace prefix to elide from rendered display names in the schema docs. Idempotent — duplicates are dropped.
Sourcepub fn auto_strip_primary_namespace(&mut self)
pub fn auto_strip_primary_namespace(&mut self)
Look up primary_namespace in document_namespaces and, if it
resolves to a non-empty prefix, register that prefix for elision
from rendered display names. Call after scan + simplify, before
tex::document_modules. No-op when there’s no primary namespace
or when its prefix is the default (empty) one.
When two prefixes map to the same URI (rare — a schema author
could declare xmlns:foo="…" and xmlns:bar="…" to the same
namespace), the lexicographically smallest prefix wins. We sort
the candidates explicitly so the chosen prefix is identical
between builds: document_namespaces is a FxHashMap, whose
iteration order isn’t a stable contract.
Sourcepub fn add_schema_declaration(&self, document: &mut Document)
pub fn add_schema_declaration(&self, document: &mut Document)
Insert a <?latexml RelaxNGSchema="..."?> processing instruction
on the given document.
Sourcepub fn load_schema(
&mut self,
name: &str,
search_paths: &[&Path],
) -> Result<(), ScanError>
pub fn load_schema( &mut self, name: &str, search_paths: &[&Path], ) -> Result<(), ScanError>
Load + scan + simplify the schema named in self.name (or
name_override). Searches search_paths for the .rng file. After
success, the AST sits in Self::modules and the lookup tables
are populated.