Command-line tools for the Swift Modelling Framework.
These tools aim to provide comprehensive support for the Eclipse Modelling Framework (EMF), Atlas Transformation Language (ATL), and the OMG MOFM2T (MOF Model-to-Text Transformation) standard.
- Pure Swift: No Java/EMF dependencies, Swift 6.0+ with strict concurrency
- Cross-Platform: Full support for macOS, Linux, and Windows
- 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
- Eclipse ATL Compatibility: Full syntax compatibility with Eclipse ATL transformations
- Complete Parser: Full ATL/OCL syntax support (96/96 tests passing)
- XMI Serialisation: Eclipse ATL XMI format support (134/134 round-trip tests passing)
- Execution Engine: Complete ATL virtual machine with expression evaluation
- Advanced OCL: Let expressions, tuple expressions, iterate operations, lambda expressions
- Helper Functions: Context and standalone helper functions
- MTL Parser: Parse MTL templates from text files following the OMG MOFM2T v1.0 specification
- MTL Runtime: Execute templates with high performance using Swift's concurrent execution model
- Model Loading: Load models from XMI and JSON formats for transformation
- Expression Language: Full AQL (Acceleo Query Language) integration for expressions
- Advanced Features: File blocks, protected areas, queries, macros, control flow
- CLI Tool: Generate, parse, and validate MTL templates from the command line
- Standard Compliance: Implements OMG MOFM2T v1.0 with compatibility for Acceleo-specific extensions
- Swift 6.0 or later
- macOS 15.0+, Linux, or Windows
You can install the suite of modelling tools using Homebrew on macOS or Linux:
brew tap mipalgu/tap
brew install swift-modellingThis will install swift-ecore, swift-atl, and swift-mtl to your system.
Pre-built Windows binaries are available from the
GitHub Releases page.
Download swift-modelling-vX.Y.Z-windows-x86_64.zip, extract it, and add
the executables to your PATH.
# Build all CLI tools
swift build
# Run the ECore CLI
swift run swift-ecore --help
# Run the ATL CLI
swift run swift-atl --help
# Run the MTL CLI
swift run swift-mtl --helpThe swift-ecore command-line tool provides comprehensive Eclipse Modelling Framework functionality for Swift. All commands support the --verbose flag for detailed output and --help for usage information.
# Show version and available commands
swift run swift-ecore info
# Get help for any command
swift run swift-ecore <command> --helpValidate models and metamodels for structural correctness and compliance.
# Validate an XMI model file
swift run swift-ecore validate model.xmi
# Validate with verbose output
swift run swift-ecore validate model.xmi --verbose
# Validate a JSON model
swift run swift-ecore validate data.json --verbose
# Validate an Ecore metamodel
swift run swift-ecore validate metamodel.ecore
# Validate with optional metamodel reference
swift run swift-ecore validate instance.xmi --metamodel schema.ecoreSupported formats: XMI (.xmi), JSON (.json), Ecore (.ecore)
Convert between XMI and JSON formats while preserving model structure and data integrity.
# Convert XMI to JSON
swift run swift-ecore convert model.xmi output.json
# Convert JSON to XMI
swift run swift-ecore convert data.json output.xmi
# Convert with verbose progress information
swift run swift-ecore convert input.xmi output.json --verbose
# Force overwrite existing output file
swift run swift-ecore convert input.json output.xmi --force
# Example: Convert team model from XMI to JSON
swift run swift-ecore convert Tests/ECoreTests/Resources/xmi/team.xmi team.json --verboseRound-trip compatibility: XMI β JSON conversions maintain full fidelity with cross-references, containment relationships, and all data types.
Generate source code in multiple programming languages from Ecore metamodels or model instances.
# Generate Swift code (default language)
swift run swift-ecore generate metamodel.ecore --output generated/
# Generate C++ code
swift run swift-ecore generate model.xmi --language cpp --output cpp-code/
# Generate C code
swift run swift-ecore generate schema.ecore --language c --output c-src/ --verbose
# Generate LLVM IR
swift run swift-ecore generate model.json --language llvm --output ir/
# Example: Generate Swift classes from organisation metamodel
swift run swift-ecore generate Tests/ECoreTests/Resources/xmi/organisation.ecore \
--output generated/ --language swift --verboseSupported languages (planned):
- π§
swift- Swift structs with properties and types - π§
cpp- C++ classes with getters/setters and headers - π§
c- C structs and function declarations - π§
llvm- LLVM IR templates
Input formats: Ecore metamodels (.ecore), XMI models (.xmi), JSON models (.json)
Inspect and analyse models with powerful query operations.
# Show general model information (default query)
swift run swift-ecore query model.xmi
# Count total objects in model
swift run swift-ecore query model.xmi --query "count"
# List all available classes
swift run swift-ecore query model.xmi --query "list-classes"
# Find objects of specific class
swift run swift-ecore query model.xmi --query "find Person"
# Show object tree structure
swift run swift-ecore query model.xmi --query "tree"
# Query with verbose output
swift run swift-ecore query team.xmi --query "find Team" --verboseAvailable query types:
info- Model statistics and class distributioncount- Total object countlist-classes- Available classes in the modelfind <ClassName>- Objects matching class name with detailed propertiestree- Hierarchical view of model structure
Generate text from models using MTL templates following the OMG MOFM2T (MOF Model-to-Text Transformation) standard.
# Basic generation from template
swift run swift-mtl generate template.mtl --output generated/
# Generate with input models
swift run swift-mtl generate template.mtl \
--model input.xmi \
--output generated/
# Generate with multiple models
swift run swift-mtl generate template.mtl \
--model families.xmi \
--model departments.xmi \
--output generated/
# Specify main template explicitly
swift run swift-mtl generate template.mtl \
--model input.xmi \
--template generateAll \
--output generated/
# Verbose generation with statistics
swift run swift-mtl generate template.mtl \
--model input.xmi \
--output generated/ \
--verboseInput formats: MTL templates (.mtl), XMI models (.xmi), JSON models (.json)
Display MTL template structure for inspection and debugging.
# Parse and show template structure
swift run swift-mtl parse template.mtl
# Parse multiple templates
swift run swift-mtl parse template1.mtl template2.mtl
# Detailed template information
swift run swift-mtl parse template.mtl --detailed
# JSON output for programmatic use
swift run swift-mtl parse template.mtl --jsonValidate MTL template syntax and structure.
# Validate single template
swift run swift-mtl validate template.mtl
# Validate multiple templates
swift run swift-mtl validate *.mtl
# Verbose validation with module details
swift run swift-mtl validate template.mtl --verboseCreate a file hello.mtl:
[module HelloWorld('http://example.com')]
[template main()]
Hello, World!
This is a simple MTL template.
[/template]Then generate:
swift run swift-mtl generate hello.mtl --output /tmp/output/
cat /tmp/output/stdout[module ClassGenerator('http://www.eclipse.org/emf/2002/Ecore')]
[template generateClass(c : EClass)]
[file (c.name + '.swift', 'overwrite', 'UTF-8')]
// Generated from [c.name/]
class [c.name/] {
[for (attr in c.eAttributes) separator('\n')]
var [attr.name/]: [attr.eType.name/]
[/for]
}
[/file]
[/template]Generate Swift code from an Ecore model:
swift run swift-mtl generate ClassGenerator.mtl \
--model mymodel.ecore \
--output generated-swift/Complete workflow example:
# 1. Validate a metamodel
swift run swift-ecore validate organisation.ecore --verbose
# 2. Validate an instance against metamodel
swift run swift-ecore validate company.xmi --metamodel organisation.ecore
# 3. Convert to JSON for web APIs
swift run swift-ecore convert company.xmi company.json --verbose
# 4. Query the model for analysis
swift run swift-ecore query company.xmi --query "find Employee" --verbose
# 5. Generate Swift code from metamodel
swift run swift-ecore generate organisation.ecore --output swift-gen/ --verbose
# 6. Convert back to XMI from JSON
swift run swift-ecore convert company.json company-copy.xmi --forceBatch processing example:
# Validate all XMI files in a directory
for file in models/*.xmi; do
echo "Validating $file..."
swift run swift-ecore validate "$file" --verbose
done
# Convert all XMI files to JSON
for file in models/*.xmi; do
json_file="${file%.xmi}.json"
swift run swift-ecore convert "$file" "$json_file" --force
doneScripting: All commands return appropriate exit codes (0 for success, non-zero for errors) for use in scripts and CI/CD pipelines.
Large files: Use --verbose to monitor progress on large models.
Cross-platform: All functionality works identically on macOS, Linux, and Windows.
PyEcore compatibility: JSON output is compatible with PyEcore for cross-language workflows.
- Validate command - Validate models and metamodels for correctness
- Convert command - Convert between XMI and JSON formats
- Query command - Query models with info, count, find, list-classes, and tree operations
- Generate command - Generate code in Swift, C++, C, and LLVM IR
Swift Modelling consists of:
- ECore module: Core library implementing the Ecore metamodel
- ATL module: Complete ATL parser and execution engine
- MTL module: MTL parser, runtime, and generation engine
- swift-ecore executable: Command-line tool for validation, conversion, and code generation
- swift-atl executable: Command-line tool for ATL transformation
- swift-mtl executable: Command-line tool for MTL text generation
All types are value types (structs) for thread safety, with ID-based reference resolution for bidirectional relationships. Resources provide EMF-compliant object ownership and cross-reference resolution using actor-based concurrency.
See the details in the LICENCE file.
Swift Modelling aims for 100% round-trip compatibility with:
This implementation is based on the following standards and technologies:
- Eclipse Modeling Framework (EMF) - The reference EMF implementation
- Eclipse ATL (Atlas Transformation Language) - The reference ATL implementation
- Eclipse Acceleo - The reference MTL implementation
- OMG MOF (Meta Object Facility) - The metamodelling standard
- OMG XMI (XML Metadata Interchange) - The XML serialisation format
- OMG QVT (Query/View/Transformation) - The model transformation standard
- OMG MOFM2T (MOF Model-to-Text Transformation) - The model-to-text standard
- OMG OCL (Object Constraint Language) - The constraint and query language