Skip to content

Implement support for xsd:redefine and xs:override#238

Merged
Bergmann89 merged 5 commits intomasterfrom
issue-192
Feb 19, 2026
Merged

Implement support for xsd:redefine and xs:override#238
Bergmann89 merged 5 commits intomasterfrom
issue-192

Conversation

@Bergmann89
Copy link
Owner

Related to #192

…ma info

This allows us to later resolve the dependencies and link the schemas together,
which is necessary for features like type references across schemas. Especially
for the planed support for `xs:redefine` and `xs:override`.
Instead of resolving types always globally, the `IdentCache` is now able
to resolve types relative to a given schema. This is needed for the planed
support for `xs:override` and `xs:redefine`.
Instead of searching the node inside the schema again, we can build the
node cache in parallel with the ident cache, which will speed up the
process of resolving identifiers.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds first-class handling of schema composition features (xs:redefine and xs:override) to the parsing + interpretation pipeline, with new feature tests/fixtures to validate generated Rust output across backends.

Changes:

  • Extend the parser to track per-schema dependencies (include/import/redefine/override) and enforce xs:include targetNamespace compatibility.
  • Refactor the interpreter to a dependency-driven node cache/type generation pipeline that can accommodate redefine/override rewrites.
  • Add new redefine/override_ feature tests and update many expectation fixtures due to naming/ordering changes.

Reviewed changes

Copilot reviewed 52 out of 54 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
xsd-parser/tests/utils.rs Adds a “no input” generator test helper; simplifies expectation formatting via rustfmt (now double-formatted for stability).
xsd-parser/tests/schema/xml_schema/expected/quick_xml.rs Updates expected generated identifiers due to naming/index changes from interpreter refactor.
xsd-parser/tests/schema/xccdf_1_2/expected/quick_xml.rs Updates expected generated identifiers due to naming/index changes from interpreter refactor.
xsd-parser/tests/schema/xccdf_1_2/expected/default.rs Updates expected generated identifiers due to naming/index changes from interpreter refactor.
xsd-parser/tests/schema/opendrive/v1_6/expected/default.rs Updates expected generated identifiers due to naming/index changes from interpreter refactor.
xsd-parser/tests/schema/opendrive/v1_4/expected/default.rs Updates expected generated identifiers due to naming/index changes from interpreter refactor.
xsd-parser/tests/schema/ideal_merchant_acquirer/expected/default.rs Updates expected generated identifiers due to naming/index changes from interpreter refactor.
xsd-parser/tests/feature/redefine/schema/schema2.xsd New schema exercising xs:redefine with an extension-based type redefinition.
xsd-parser/tests/feature/redefine/schema/schema1.xsd New schema that includes the base schema and references base definitions.
xsd-parser/tests/feature/redefine/schema/base.xsd New base schema used by redefine feature tests.
xsd-parser/tests/feature/redefine/mod.rs New feature test module validating generation + quick_xml round-trip parsing for redefine.
xsd-parser/tests/feature/redefine/expected/default.rs Expected generated Rust for redefine test (default backend).
xsd-parser/tests/feature/redefine/example/Persons.xml Example instance XML for base (non-redefined) type.
xsd-parser/tests/feature/redefine/example/AdvancedPersons.xml Example instance XML for redefined type extension.
xsd-parser/tests/feature/override_/schema/schema2.xsd New schema exercising xs:override replacing a type definition.
xsd-parser/tests/feature/override_/schema/schema1.xsd New schema that includes the base schema and references base definitions.
xsd-parser/tests/feature/override_/schema/base.xsd New base schema used by override feature tests.
xsd-parser/tests/feature/override_/mod.rs New feature test module validating generation + quick_xml round-trip parsing for override.
xsd-parser/tests/feature/override_/expected/default.rs Expected generated Rust for override test (default backend).
xsd-parser/tests/feature/override_/example/Persons.xml Example instance XML for base (non-overridden) type.
xsd-parser/tests/feature/override_/example/AdvancedPersons.xml Example instance XML intended for overridden type instance parsing.
xsd-parser/tests/feature/mod.rs Registers new override_ and redefine feature test modules.
xsd-parser/src/pipeline/parser/mod.rs Introduces temp schema ids, dependency tracking, and include targetNamespace validation; expands handling for redefine/override.
xsd-parser/src/pipeline/parser/error.rs Adds a dedicated parser error for mismatching include targetNamespace.
xsd-parser/src/pipeline/optimizer/replace_xs_any_type_with_any_element.rs Adjusts namespace fallback behavior for xs:anyType replacement.
xsd-parser/src/pipeline/interpreter/state/prepare_schemas.rs New interpreter step to precompute per-schema metadata.
xsd-parser/src/pipeline/interpreter/state/prepare_modules.rs New interpreter step to precompute per-namespace module metadata.
xsd-parser/src/pipeline/interpreter/state/generate_types/variant_processor.rs Major refactor: variant building now uses a TypeProcessor and node/dependency resolution API.
xsd-parser/src/pipeline/interpreter/state/generate_types/update.rs Extracts “update” helpers into a dedicated module.
xsd-parser/src/pipeline/interpreter/state/generate_types/type_processor.rs New core type generation engine that processes nodes with stack/context and resolves dependencies.
xsd-parser/src/pipeline/interpreter/state/generate_types/name_builder.rs Adds stack-based auto-extension support for generated names during type processing.
xsd-parser/src/pipeline/interpreter/state/generate_types.rs New generate-types orchestration + stack model for the refactored interpreter pipeline.
xsd-parser/src/pipeline/interpreter/state/fix_element_naming_conflicts.rs Moves naming conflict resolution into State method form.
xsd-parser/src/pipeline/interpreter/state/create_node_list.rs New node ordering step that enforces strong-dependency ordering and detects circular deps.
xsd-parser/src/pipeline/interpreter/state/crate_node_cache.rs New node-cache construction pass including redefine/override dependency rewrites.
xsd-parser/src/pipeline/interpreter/state/crate_ident_cache.rs New ident-cache construction pass that understands redefine/override content.
xsd-parser/src/pipeline/interpreter/state.rs Rebuilds interpreter State around node cache + ident cache; removes old schema-walking interpreter.
xsd-parser/src/pipeline/interpreter/schema.rs Removed old schema interpreter implementation (replaced by node-cache pipeline).
xsd-parser/src/pipeline/interpreter/name_builder.rs Removed old name-builder extension (replaced by generate_types/name_builder.rs).
xsd-parser/src/pipeline/interpreter/mod.rs Updates interpreter entrypoints to use the new State pipeline; removes old modules.
xsd-parser/src/pipeline/interpreter/error.rs Updates interpreter errors for the new pipeline (expected simple/complex type, circular deps, etc.).
xsd-parser/src/models/schema/mod.rs Adds schema dependency modeling (Dependency<T>), schema id generation, and convenience helpers.
xsd-parser/src/models/name.rs Adds conversions from Name to String and Cow<'static, str> for cache/storage.
xsd-parser/src/models/mod.rs Removes NodeIdent exports to align with refactor (TypeIdent-only pipeline).
xsd-parser/src/models/meta/type_.rs Adds MetaType::redefined_base tracking and is_redefinition() helper.
xsd-parser/src/models/ident_cache.rs Replaces old alt-ident cache with schema/dependency-aware cache + iterators and schema-scoped resolution.
xsd-parser/src/models/ident.rs Removes NodeIdent type and related conversions; keeps TypeIdent as the primary identifier.
xsd-parser/src/lib.rs Plumbs new parser error variant through the public error conversion.
xsd-parser-types/src/xml/qname.rs Extends QName capabilities (from_bytes) and customizes Eq/PartialEq/Hash.
Comments suppressed due to low confidence (1)

xsd-parser/src/pipeline/optimizer/replace_xs_any_type_with_any_element.rs:63

  • Falling back to NamespaceId::ANONYMOUS when the XS namespace isn't present can cause this optimization to target an unrelated anyType in the anonymous namespace (or just silently do nothing depending on the type set). If the XS namespace can't be resolved, it's safer to return early or keep the fallback as NamespaceId::UNKNOWN so the optimizer doesn't mutate the wrong type set.
        let ns = self
            .types
            .modules
            .values()
            .find_map(|meta| {
                matches!(&meta.namespace, Some(ns) if *ns == Namespace::XS)
                    .then_some(meta.namespace_id)
            })
            .unwrap_or(NamespaceId::ANONYMOUS);
        let ident = TypeIdent {
            ns,
            schema: SchemaId::UNKNOWN,
            name: Name::ANY_TYPE,
            type_: IdentType::Type,
        };

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

To be able to implement support for `xs:redefine` and `xs:override`, we needed to
refactor the interpreter first. It is not split into multiple stages that depend
on each other. In simplified terms, the stages are:
- create ident cache: needed for resolving references to other named nodes
- create node cache: uses the name resolver to build a dependency tree of all nodes
    and resolve overwritten or redefined nodes
- generate types: uses the node cache to generate the actual meta types structure

While splitting the code in several stages makes the code base more readable and
maintainable, it also add additional assumptions about the state of the interpreter
between the stages, that need to be taken into consideration when implementing the
new features. All these constraints are usually ensured using panics or assertions.
@Bergmann89 Bergmann89 merged commit 1e5fde1 into master Feb 19, 2026
2 checks passed
@Bergmann89 Bergmann89 deleted the issue-192 branch February 19, 2026 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants