Class: Lutaml::Xsd::RngToXsdConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/xsd/rng_to_xsd_converter.rb

Overview

Converts an Rng::Grammar object to an Lutaml::Xml::Schema::Xsd::Schema. Follows the same mapping logic as jing-trang’s RNG-to-XSD conversion.

Instance Method Summary collapse

Constructor Details

#initialize(grammar, file_path: nil) ⇒ RngToXsdConverter

Returns a new instance of RngToXsdConverter.

Parameters:

  • grammar (Rng::Grammar)

    The parsed RNG grammar

  • file_path (String) (defaults to: nil)

    Original file path (for error messages)



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/lutaml/xsd/rng_to_xsd_converter.rb', line 10

def initialize(grammar, file_path: nil)
  @grammar = grammar
  @file_path = file_path

  # Build define name -> Rng::Define lookup
  @define_map = build_define_map(grammar)

  # Cache which defines wrap a single element (define_is_element_like?)
  @element_like_define = {}

  # Collision detection: element_name -> [define_names]
  @element_name_collisions = build_element_name_collisions

  # Track converted defines to prevent infinite recursion
  @converting = Set.new

  # Cache: define_name -> { group:, attribute_group:, simple_type:, complex_type:, element: }
  @define_results = {}
end

Instance Method Details

#convertLutaml::Xml::Schema::Xsd::Schema

Convert the grammar to an XSD Schema

Returns:

  • (Lutaml::Xml::Schema::Xsd::Schema)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/lutaml/xsd/rng_to_xsd_converter.rb', line 32

def convert
  @schema = Lutaml::Xml::Schema::Xsd::Schema.new
  @schema.element_form_default = "qualified"
  schema = @schema

  # Set target_namespace only if it's a real value (not uninitialized)
  ns = @grammar.ns
  schema.target_namespace = ns unless ns.nil? || ns.is_a?(Lutaml::Model::UninitializedClass)

  # Phase 0: Convert includes from RNC/RNG file
  convert_includes(schema)

  # Phase 1: Convert all defines
  convert_all_defines

  # Phase 2: Convert start elements and top-level elements
  convert_start_elements(schema)
  convert_grammar_elements(schema)

  schema
end