Skip to content

Commit 414eb9f

Browse files
committed
#66 import from Lionweb models not exported from Kolasu
1 parent 7ddf9ae commit 414eb9f

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
All notable changes to this project from version 1.2.0 upwards are documented in this file.
33
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
44

5+
## [1.6.24] – Not yet released
6+
7+
### Fixed
8+
- `assertASTsAreEqual` is now properly exported
9+
510
## [1.6.23] – 2024-04-24
611

712
### Fixed

src/interop/lionweb.ts

+20-18
Original file line numberDiff line numberDiff line change
@@ -77,27 +77,39 @@ export class LanguageMapping {
7777
}
7878
}
7979

80-
function isASTNode(classifier: Classifier) {
81-
return (classifier instanceof Concept) &&
82-
(classifier.key == ASTNode.key || (classifier.extends && isASTNode(classifier.extends)));
80+
function isSpecialConcept(classifier: Classifier) {
81+
return classifier.key == PositionClassifier.key;
8382
}
8483

8584
function importFeature(feature: LWFeature): Feature | undefined {
8685
const def: Feature = { name: feature.name };
8786
if (feature instanceof Containment) {
88-
if (feature.type && isASTNode(feature.type)) {
87+
if (feature.type && feature.type instanceof Concept && !isSpecialConcept(feature.type)) {
8988
def.child = true;
9089
def.multiple = feature.multiple;
9190
} else {
92-
// TODO we assume that:
93-
// 1) we're importing a StarLasu AST
94-
// 2) containments in a StarLasu AST are either AST nodes or internal StarLasu objects like the position
91+
// TODO is it possible in Lionweb to have a Containment that's not a concept?
9592
return undefined;
9693
}
9794
}
9895
return def
9996
}
10097

98+
function importConcept(concept: NodeDefinition | undefined, classifier: Classifier) {
99+
concept = {
100+
name: classifier.name,
101+
features: {},
102+
resolved: true
103+
};
104+
allFeatures(classifier).forEach(f => {
105+
const feature = importFeature(f);
106+
if (feature) {
107+
concept!.features[f.name] = feature;
108+
}
109+
});
110+
return concept;
111+
}
112+
101113
export class TylasuInstantiationFacade implements InstantiationFacade<TylasuWrapper> {
102114

103115
protected readonly concepts = new Map<Classifier, NodeDefinition>();
@@ -128,17 +140,7 @@ export class TylasuInstantiationFacade implements InstantiationFacade<TylasuWrap
128140
if (!node) {
129141
let concept = this.concepts.get(classifier);
130142
if (!concept) {
131-
concept = {
132-
name: classifier.name,
133-
features: {},
134-
resolved: true
135-
};
136-
allFeatures(classifier).forEach(f => {
137-
const feature = importFeature(f);
138-
if (feature) {
139-
concept!.features[f.name] = feature;
140-
}
141-
});
143+
concept = importConcept(concept, classifier);
142144
this.concepts.set(classifier, concept);
143145
}
144146
node = new LionwebNode(concept, {

tests/interop/lionweb.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,6 @@ describe('Lionweb integration', function() {
144144
expect(dir.nodeDefinition.name).to.equal("EglCompilationUnit");
145145
expect(dir.containment("position")).to.be.undefined;
146146
expect(dir.position).not.to.be.undefined;
147+
expect(dir.children.length).to.equal(0);
147148
});
148149
});

0 commit comments

Comments
 (0)