def handle_array_types(db_struct): """ Handle array types once all UDTs are expanded. This function modifies the structure in place. """ if isinstance(db_struct, dict): for key, value in list(db_struct.items()): if isinstance(value, dict): handle_array_types(value) elif isinstance(value, str): # Parsing array definitions, e.g., "Array[1..3] of Real" match = re.match(r"Array\[(\d+)\.\.(\d+)\] of (\w+)", value) if match: lower_bound, upper_bound, base_type = ( int(match.group(1)), int(match.group(2)), match.group(3), ) # Expand this field into multiple fields db_struct.pop(key) # Remove the original field for i in range(lower_bound, upper_bound + 1): db_struct[f"{key}_{i}"] = {"type": base_type, 'is_array_element': True} print( f"Expanded field '{key}' into array fields: {key}_{lower_bound} to {key}_{upper_bound} of type {base_type}