Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import from Lionweb models not exported from Kolasu #67

Merged
merged 3 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
All notable changes to this project from version 1.2.0 upwards are documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [1.6.24] – Not yet released

### Fixed
- `assertASTsAreEqual` is now properly exported

## [1.6.23] – 2024-04-24

### Fixed
Expand Down
38 changes: 20 additions & 18 deletions src/interop/lionweb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,39 @@ export class LanguageMapping {
}
}

function isASTNode(classifier: Classifier) {
return (classifier instanceof Concept) &&
(classifier.key == ASTNode.key || (classifier.extends && isASTNode(classifier.extends)));
function isSpecialConcept(classifier: Classifier) {
return classifier.key == PositionClassifier.key;
}

function importFeature(feature: LWFeature): Feature | undefined {
const def: Feature = { name: feature.name };
if (feature instanceof Containment) {
if (feature.type && isASTNode(feature.type)) {
if (feature.type && feature.type instanceof Concept && !isSpecialConcept(feature.type)) {
def.child = true;
def.multiple = feature.multiple;
} else {
// TODO we assume that:
// 1) we're importing a StarLasu AST
// 2) containments in a StarLasu AST are either AST nodes or internal StarLasu objects like the position
// TODO is it possible in Lionweb to have a Containment that's not a concept?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes: it could be a ConceptInterface

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it makes sense to support that as well.

return undefined;
}
}
return def
}

function importConcept(concept: NodeDefinition | undefined, classifier: Classifier) {
concept = {
name: classifier.name,
features: {},
resolved: true
};
allFeatures(classifier).forEach(f => {
const feature = importFeature(f);
if (feature) {
concept!.features[f.name] = feature;
}
});
return concept;
}

export class TylasuInstantiationFacade implements InstantiationFacade<TylasuWrapper> {

protected readonly concepts = new Map<Classifier, NodeDefinition>();
Expand Down Expand Up @@ -128,17 +140,7 @@ export class TylasuInstantiationFacade implements InstantiationFacade<TylasuWrap
if (!node) {
let concept = this.concepts.get(classifier);
if (!concept) {
concept = {
name: classifier.name,
features: {},
resolved: true
};
allFeatures(classifier).forEach(f => {
const feature = importFeature(f);
if (feature) {
concept!.features[f.name] = feature;
}
});
concept = importConcept(concept, classifier);
this.concepts.set(classifier, concept);
}
node = new LionwebNode(concept, {
Expand Down
1 change: 1 addition & 0 deletions tests/interop/lionweb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,6 @@ describe('Lionweb integration', function() {
expect(dir.nodeDefinition.name).to.equal("EglCompilationUnit");
expect(dir.containment("position")).to.be.undefined;
expect(dir.position).not.to.be.undefined;
expect(dir.children.length).to.equal(0);
});
});