Skip to content

Added rng model generation#699

Open
HassanAkbar wants to merge 17 commits into
mainfrom
feat/rng-compiler-to-models
Open

Added rng model generation#699
HassanAkbar wants to merge 17 commits into
mainfrom
feat/rng-compiler-to-models

Conversation

@HassanAkbar

Copy link
Copy Markdown
Member

fixes #9

Comment thread lib/lutaml/model/schema/rng_compiler/utils.rb Fixed
@HassanAkbar HassanAkbar force-pushed the feat/rng-compiler-to-models branch from 627a823 to 303b085 Compare June 1, 2026 13:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds RELAX NG (RNG) schema compilation support to generate Lutaml model classes from RNG grammars (fixes #9), and refactors the existing XSD compiler into a shared “definitions + renderers + compiled output” architecture that can be reused by multiple schema compilers.

Changes:

  • Add Schema.from_relaxng entry point and implement Lutaml::Model::Schema::RngCompiler with fixtures and documentation.
  • Refactor XSD compilation to emit Definitions::* specs and render via shared Renderers::*, with shared CompiledOutput, FileWriter, ClassLoader, and RegistryGenerator infrastructure.
  • Introduce shared templates (Schema::Templates) and namespace naming helpers reused across schema compilers.

Reviewed changes

Copilot reviewed 92 out of 92 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
Gemfile Adds rng dependency via git for development/tests.
README.adoc Documents RELAX NG schema compilation and usage patterns.
lib/lutaml/xml.rb Registers Schema.from_relaxng method and delegates to RngCompiler.
lib/lutaml/model/utils.rb Adds Utils.last_of_split helper.
lib/lutaml/model/schema.rb Autoloads new shared schema infrastructure, definitions, renderers, and RNG compiler.
lib/lutaml/model/schema/class_loader.rb New shared loader to write compiled output to temp dir and load via registry.
lib/lutaml/model/schema/compiled_output.rb New shared compilation output container for models/namespaces and rendered sources.
lib/lutaml/model/schema/file_writer.rb New shared writer for namespaced/flat output plus registry generation.
lib/lutaml/model/schema/module_nesting.rb New helper for module wrapper emission.
lib/lutaml/model/schema/namespace_naming.rb New helper to derive namespace class names/prefixes from URI.
lib/lutaml/model/schema/registry_generator.rb New base registry generator used by compilers.
lib/lutaml/model/schema/templates.rb New shared ERB templates for generated classes/types/namespaces.
lib/lutaml/model/schema/definitions.rb New autoload entrypoint for schema definition objects.
lib/lutaml/model/schema/definitions/attribute.rb New definition type for attributes/elements.
lib/lutaml/model/schema/definitions/choice.rb New definition type for choice blocks.
lib/lutaml/model/schema/definitions/facet.rb New definition type for restriction facets.
lib/lutaml/model/schema/definitions/group_import.rb New definition type for XSD group imports in members.
lib/lutaml/model/schema/definitions/member_walk.rb New traversal helper for heterogeneous member trees.
lib/lutaml/model/schema/definitions/model.rb New definition type for generated Serializable models.
lib/lutaml/model/schema/definitions/namespace.rb New definition type for XML namespace classes.
lib/lutaml/model/schema/definitions/restricted_type.rb New definition type for restricted simple types.
lib/lutaml/model/schema/definitions/sequence.rb New definition type for sequences.
lib/lutaml/model/schema/definitions/simple_content.rb New XSD simpleContent sidecar definition.
lib/lutaml/model/schema/definitions/transform_facet.rb New XSD-only transform facet definition.
lib/lutaml/model/schema/definitions/type_ref.rb New type reference wrapper definition.
lib/lutaml/model/schema/definitions/union_type.rb New definition type for union value types.
lib/lutaml/model/schema/definitions/xml_root.rb New definition type describing XML root directive kind/name.
lib/lutaml/model/schema/renderers.rb New autoload entrypoint for renderers.
lib/lutaml/model/schema/renderers/member_decls.rb Renders attribute declarations from definitions.
lib/lutaml/model/schema/renderers/mappings.rb Renders XML mapping blocks from definitions.
lib/lutaml/model/schema/renderers/model.rb Renders Definitions::Model to Ruby source using shared templates.
lib/lutaml/model/schema/renderers/namespace.rb Renders Definitions::Namespace to Ruby source.
lib/lutaml/model/schema/renderers/registration.rb Renders register/register_class_with_id boilerplate.
lib/lutaml/model/schema/renderers/required_files_calculator.rb Computes dependencies/require lines for generated models.
lib/lutaml/model/schema/renderers/restricted_type.rb Renders restricted types to Ruby source.
lib/lutaml/model/schema/renderers/union.rb Renders union types to Ruby source.
lib/lutaml/model/schema/rng_compiler.rb New RNG compiler orchestrator (parse, compile, output).
lib/lutaml/model/schema/rng_compiler/define_classifier.rb Classifies defines into restricted/union vs structural models.
lib/lutaml/model/schema/rng_compiler/element_visitor.rb Walks RNG AST to build model/type definitions.
lib/lutaml/model/schema/rng_compiler/member_collector.rb Scratch accumulator for choice/group member collection.
lib/lutaml/model/schema/rng_compiler/rng_helpers.rb Centralized RNG AST helper predicates and facet builders.
lib/lutaml/model/schema/rng_compiler/value_type_resolver.rb Resolves leaf value types (primitive/ref/anonymous restrictions).
lib/lutaml/model/schema/xml_compiler.rb Refactors XSD compilation to use SpecBuilder + shared output infrastructure.
lib/lutaml/model/schema/xml_compiler/element_order.rb New helper for resolved traversal order of XSD AST nodes.
lib/lutaml/model/schema/xml_compiler/registry_generator.rb Updates XSD registry generator to subclass shared base and add phases.
lib/lutaml/model/schema/xml_compiler/spec_builder.rb New XSD SpecBuilder orchestrating two-pass collection/build.
lib/lutaml/model/schema/xml_compiler/supported_data_types.rb New built-in XSD type table module.
lib/lutaml/model/schema/xml_compiler/spec_builder/complex_types.rb New XSD complex-type builder producing model specs.
lib/lutaml/model/schema/xml_compiler/spec_builder/members.rb New XSD member builder producing attribute/sequence/choice/group specs.
lib/lutaml/model/schema/xml_compiler/spec_builder/simple_types.rb New XSD simple-type builder producing restricted/union specs.
lib/lutaml/model/schema/xml_compiler/attribute.rb Removed legacy XSD compiler implementation (superseded by definitions/renderers).
lib/lutaml/model/schema/xml_compiler/attribute_group.rb Removed legacy XSD compiler implementation.
lib/lutaml/model/schema/xml_compiler/choice.rb Removed legacy XSD compiler implementation.
lib/lutaml/model/schema/xml_compiler/complex_content.rb Removed legacy XSD compiler implementation.
lib/lutaml/model/schema/xml_compiler/complex_content_restriction.rb Removed legacy XSD compiler implementation.
lib/lutaml/model/schema/xml_compiler/complex_type.rb Removed legacy XSD compiler implementation.
lib/lutaml/model/schema/xml_compiler/element.rb Removed legacy XSD compiler implementation.
lib/lutaml/model/schema/xml_compiler/group.rb Removed legacy XSD compiler implementation.
lib/lutaml/model/schema/xml_compiler/restriction.rb Removed legacy XSD compiler implementation.
lib/lutaml/model/schema/xml_compiler/sequence.rb Removed legacy XSD compiler implementation.
lib/lutaml/model/schema/xml_compiler/simple_content.rb Removed legacy XSD compiler implementation.
lib/lutaml/model/schema/xml_compiler/simple_type.rb Removed legacy XSD compiler implementation.
lib/lutaml/model/schema/xml_compiler/xml_namespace_class.rb Removed legacy XSD namespace class generator (replaced by shared definitions/renderers).
spec/lutaml/model/utils_spec.rb Adds coverage for Utils.last_of_split.
spec/lutaml/xml/schema/compiler_spec.rb Updates XSD compiler spec expectations to new TypeRef / builder structure.
spec/lutaml/model/schema/renderers/model_spec.rb New renderer unit tests for model rendering.
spec/lutaml/model/schema/renderers/namespace_spec.rb New renderer unit tests for namespace rendering.
spec/lutaml/model/schema/renderers/restricted_type_spec.rb New renderer unit tests for restricted type rendering.
spec/lutaml/model/schema/renderers/union_spec.rb New renderer unit tests for union rendering.
spec/fixtures/xml/schema/rng/address_book.rng New RNG fixture.
spec/fixtures/xml/schema/rng/book.rng New RNG fixture.
spec/fixtures/xml/schema/rng/fixed_value.rng New RNG fixture.
spec/fixtures/xml/schema/rng/full_name.rng New RNG fixture (issue #9 regression).
spec/fixtures/xml/schema/rng/integer_range.rng New RNG fixture.
spec/fixtures/xml/schema/rng/list_type.rng New RNG fixture.
spec/fixtures/xml/schema/rng/namespaced.rng New RNG fixture.
spec/fixtures/xml/schema/rng/paragraph.rng New RNG fixture.
spec/fixtures/xml/schema/rng/person.rng New RNG fixture.
spec/fixtures/xml/schema/rng/union.rng New RNG fixture.
spec/lutaml/xml/schema/compiler/attribute_group_spec.rb Removes legacy unit spec (superseded by new architecture tests).
spec/lutaml/xml/schema/compiler/attribute_spec.rb Removes legacy unit spec.
spec/lutaml/xml/schema/compiler/choice_spec.rb Removes legacy unit spec.
spec/lutaml/xml/schema/compiler/complex_content_restriction_spec.rb Removes legacy unit spec.
spec/lutaml/xml/schema/compiler/complex_content_spec.rb Removes legacy unit spec.
spec/lutaml/xml/schema/compiler/complex_type_spec.rb Removes legacy unit spec.
spec/lutaml/xml/schema/compiler/element_spec.rb Removes legacy unit spec.
spec/lutaml/xml/schema/compiler/group_spec.rb Removes legacy unit spec.
spec/lutaml/xml/schema/compiler/restriction_spec.rb Removes legacy unit spec.
spec/lutaml/xml/schema/compiler/sequence_spec.rb Removes legacy unit spec.
spec/lutaml/xml/schema/compiler/simple_content_spec.rb Removes legacy unit spec.
spec/lutaml/xml/schema/compiler/simple_type_spec.rb Removes legacy unit spec.

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

Comment thread lib/lutaml/model/schema/xml_compiler/element_order.rb Outdated
Comment thread lib/lutaml/model/schema/compiled_output.rb
Comment thread lib/lutaml/model/schema/xml_compiler/spec_builder.rb
Comment thread lib/lutaml/model/schema/rng_compiler/element_visitor.rb
Comment thread lib/lutaml/model/schema/rng_compiler/element_visitor.rb
Comment thread lib/lutaml/model/schema/xml_compiler/supported_data_types.rb
Comment thread Gemfile Outdated
@HassanAkbar HassanAkbar marked this pull request as ready for review June 17, 2026 14:55
@HassanAkbar HassanAkbar requested a review from ronaldtse June 17, 2026 14:56
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.

Generate model from model description

3 participants