Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/target
**/target
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"rust-lang.rust-analyzer",
"tamasfe.even-better-toml"
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.formatOnSave": true
}
22 changes: 22 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Documenting code

- Refer to [Concerto Specification documentation](https://concerto.accordproject.org/docs/category/specification) when figuring out anything related to `concerto-core`, especially anything related to instrospection.
- Add Rust-Docs using above documentation when possible.

# Adding and modifying code

- Always use the most idiomatic approach suitable for Rust language.
- If needed split the code into different crates. If a crate does not exist, ask the operator for help.
- Add a derive macro for repeated `impl`s of a trait, into `concerto-macros` crate.
- Types under `concerto-core` should only refer to the types from `concerto-metamodel` using new-type pattern.
- Prefer sum-type over complicated traits.
- Remove any code that is not being used (don't add extra code, just because, that might be useful in the future.)
- Add unit tests for new functions and methods.

# Testing

- Run `cargo build` and `cargo test` to verify any change.

# PR instructions

- Use [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) style for PR titles.
51 changes: 27 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 3 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
[package]
name = "concerto_core"
version = "0.1.0"
edition = "2021"
authors = ["Accord Project"]
description = "Rust implementation of Concerto Core for structural and semantic metamodel validation"

[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0"
regex = "1.10"
semver = "1.0"
log = "0.4"
lazy_static = "1.4"
chrono = "0.4"
[workspace]
resolver = "3"
members = ["concerto-metamodel", "concerto-core", "concerto-macros"]
81 changes: 6 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,91 +1,22 @@
# Concerto Rust

A prototype Rust implementation of the Concerto modeling language, focusing on structural and semantic metamodel validation.
Rust implementation of the Concerto modeling language, focusing on structural and semantic metamodel validation.

## Overview

This project is a partial Rust implementation of the [Concerto](https://github.com/accordproject/concerto) modeling language, which was originally developed in JavaScript. This Rust version focuses specifically on the structural and semantic validation aspects of the metamodel.

## Features

The implementation includes:

- Model file parsing and validation
- Declaration types (Asset, Concept, Enum, Scalar, Map)
- Property type validation
- Import and namespace validation
- Semantic validation based on the Concerto Conformance rules

## Project Structure

The project is organized as follows:

- `src/`
- `lib.rs`: Main entry point exporting public modules
- `declaration.rs`: Core declarations for data modeling
- `model_file.rs`: Represents model files with namespace and imports management
- `model_manager.rs`: Manages model collections and cross-model validations
- `error.rs`: Error types for the library
- `validation.rs`: Validation traits and implementations
- `introspect/mod.rs`: Introspection capabilities
- `util.rs`: Utility functions
The project is organized into different crates under one workspace:

## Testing

The test suite includes:

- `declaration_tests.rs`: Tests for declaration validation
- `conformance_tests.rs`: Tests for conformance with the specification
- `enum_tests.rs`: Tests for enum declarations and validation
- `scalar_tests.rs`: Tests for scalar declarations and validation
- `map_tests.rs`: Tests for map declarations and validation
- `namespace_tests.rs`: Tests for namespace validation
- [`concerto-core`](/concerto-core/) is the core implementation with introspection and validation.
- [`concerto-macros`](/concerto-macros/) has the derive macros used by the `cocnerto-core` crate.
- [`concerto-metamodel`](/concerto-metamodel/) crate exposes the generated Rust types from the main [`concerto-metamodel`](https://github.com/accordproject/concerto-metamodel) package.

## Usage

```rust
use concerto_core::{
ModelFile,
Declaration,
ModelManager,
validation::Validate,
};

// Create a model file
let model_file = ModelFile {
namespace: "org.example".to_string(),
imports: vec![],
declarations: vec![
// Add your declarations here
],
};

// Validate the model file
match model_file.validate() {
Ok(_) => println!("Model file is valid"),
Err(e) => println!("Validation error: {}", e),
};

// Create a model manager
let mut model_manager = ModelManager::new();
model_manager.add_model_file(model_file).unwrap();

// Validate the entire model
match model_manager.validate() {
Ok(_) => println!("Model is valid"),
Err(e) => println!("Validation error: {}", e),
};
```

## Status

This is a partial implementation focusing on the validation aspects of Concerto. It includes:

- Basic model file structure and validation
- Declaration validation
- Cross-model validation
- Import and namespace validation
- Support for Enums, Scalars, and Maps
TBD

## License

Expand Down
18 changes: 18 additions & 0 deletions concerto-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "concerto-core"
version = "0.1.0"
edition = "2024"
authors = ["Accord Project <accordproject.org>"]
description = "Core implementation of Concerto Modelling Language in Rust"
license = "Apache-2.0"
license-file = "../LICENSE"
homepage = "https://concerto.accordproject.org/"

[dependencies]
concerto-metamodel = { path = "../concerto-metamodel" }
concerto-macros = { path = "../concerto-macros" }
thiserror = "2"
regex = "1"
chrono = "0.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
23 changes: 23 additions & 0 deletions concerto-core/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use concerto_metamodel::concerto_metamodel_1_0_0::Range;

/// Errors produced by concerto-core.
#[derive(Debug, thiserror::Error)]
pub enum ConcertoError {
/// The model contains an illegal construct.
#[error("{message}")]
IllegalModel {
message: String,
file_name: Option<String>,
location: Option<Range>,
},

/// A referenced type could not be found.
#[error("Type not found: {type_name}")]
TypeNotFound { type_name: String },

/// A value failed validation against the model.
#[error("Validation error on {component}: {message}")]
Validation { message: String, component: String },
}

pub type Result<T> = std::result::Result<T, ConcertoError>;
Loading
Loading