Skip to content

mipalgu/swift-ecore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

103 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swift ECore

CI Documentation

A pure Swift implementation of the Eclipse Modelling Framework (EMF) Ecore metamodel for macOS, Linux, and Windows.

Features

  • Pure Swift: No Java/EMF dependencies, Swift 6.2+ with strict concurrency
  • Cross-Platform: Full support for macOS and Linux
  • Value Types: Sendable structs and enums for thread safety
  • BigInt Support: Full arbitrary-precision integer support via swift-numerics
  • Complete Metamodel: EClass, EAttribute, EReference, EPackage, EEnum, EDataType
  • Resource Infrastructure: EMF-compliant object management and ID-based reference resolution
  • JSON Serialisation: Load and save JSON models with full round-trip support
  • Bidirectional References: Automatic opposite reference management across resources
  • XMI Parsing: Load .ecore metamodels and .xmi instance files
  • Dynamic Attribute Parsing: Arbitrary XML attributes with automatic type inference (Int, Double, Bool, String)
  • XPath Reference Resolution: Same-resource references with XPath-style navigation (//@feature.index)
  • XMI Serialisation: Write models to XMI format with full round-trip support

Requirements

  • Swift 6.0 or later
  • macOS 15.0+ or Linux (macOS 15.0+ required for SwiftXML dependency)

Building

# Build the library
swift build

# Run tests
swift test

Usage

The library implements the core of the Eclipse Modelling Framework and can be included in other libraries, tools, and utilities (see the documentation). For practical use, the swift-ecore command-line tool from the swift-modelling repository provides comprehensive Eclipse Modelling Framework functionality for Swift.

Implementation Status

Core Types ✅

  • SPM package structure
  • Primitive type mappings (EString, EInt, EBoolean, EBigInt, etc.)
  • BigInt support via swift-numerics
  • Type conversion utilities
  • 100% test coverage for primitive types

Metamodel Core ✅

  • EObject protocol
  • EModelElement (annotations)
  • ENamedElement
  • EClassifier hierarchy (EDataType, EEnum, EEnumLiteral)
  • EClass with structural features
  • EStructuralFeature (EAttribute and EReference with ID-based opposites)
  • EPackage and EFactory
  • Resource and ResourceSet infrastructure

In-Memory Model ✅

  • Binary tree containment tests (BinTree model)
  • Company cross-reference tests
  • Shared reference tests
  • Multi-level containment hierarchy tests

JSON Serialisation ✅

  • JSON parser for model instances
  • JSON serialiser with sorted keys
  • Round-trip tests for all data types
  • Comprehensive error handling

XMI Serialisation ✅

  • SwiftXML dependency added
  • XMI parser foundation (Step 4.1)
  • XMI metamodel deserialisation (Step 4.2) - EPackage, EClass, EEnum, EDataType, EAttribute, EReference
  • XMI instance deserialisation (Step 4.3) - Dynamic object creation from instance files
  • Dynamic attribute parsing with type inference - Arbitrary XML attributes parsed without hardcoding
  • XPath reference resolution (Step 4.4) - Same-resource references with XPath-style navigation
  • XMI serialiser (Step 4.5) - Full serialisation with attributes, containment, and cross-references
  • Round-trip tests - XMI → memory → XMI with in-memory verification at each step
  • Cross-resource references (Step 4.6)

Generic JSON Serialisation ✅

  • JSON parser for model instances (Step 5.1)
  • JSON serialiser with sorted keys (Step 5.2)
  • Dynamic EClass creation from JSON - Type inference for attributes and references
  • Boolean type handling fix - Boolean detection from Foundation's JSONSerialisation
  • Multiple root objects support - Arrays of JSON root objects
  • Cross-format conversion - XMI ↔ JSON bidirectional conversion
  • Round-trip tests for all data types
  • PyEcore compatibility validation - minimal.json and intfloat.json patterns
  • Comprehensive error handling

Licence

See the details in the LICENCE file.

Compatibility

Swift Modelling aims for 100% round-trip compatibility with:

  • emf4cpp - C++ EMF implementation
  • pyecore - Python EMF implementation

References

This implementation is based on the following standards and technologies:

About

Swift implementation of the Eclipse Modeling Framework (EMF) Ecore

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages