Skip to main content

Relaxng

Struct Relaxng 

Source
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 of elementdefs.
  • 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:QNAME for refs at define scope, element:TAG@pattern:HOST for refs inside an element TAG {…} hosted by define HOST (bare element:TAG when the element sits outside any define). Drives the “Used by” lists in the schema docs; tex::symbol_uses reports the element or the host pattern, whichever identifies the definition uniquely.
  • internal_grammars — counter for naming embedded <grammar> blocks (grammar1, grammar2, …).

Fields§

§name: String

Top-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

Source

pub fn new(name: impl Into<String>) -> Self

Construct an empty schema state. Use Self::load_schema to populate from an RNG file.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn add_schema_declaration(&self, document: &mut Document)

Insert a <?latexml RelaxNGSchema="..."?> processing instruction on the given document.

Source

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.

Trait Implementations§

Source§

impl Debug for Relaxng

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Relaxng

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.