Skip to content

Commit 366e7f7

Browse files
Merge pull request #67 from Strumenta/fix/lionweb-import
Import from Lionweb models not exported from Kolasu
2 parents 7ddf9ae + 5b24c8a commit 366e7f7

File tree

4 files changed

+84
-120
lines changed

4 files changed

+84
-120
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

+47-22
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
import {
66
Classifier,
77
Concept,
8-
Containment,
8+
Containment, deserializeChunk,
99
Feature as LWFeature,
1010
Id,
1111
InstantiationFacade,
1212
Interface,
1313
Language,
14-
Node as LWNodeInterface
14+
Node as LWNodeInterface,
15+
SerializationChunk
1516
} from "@lionweb/core";
16-
import {NodeAdapter, Issue, Node, NodeDefinition, Position, Feature, Point, pos} from "..";
17+
import {NodeAdapter, Issue, Node, NodeDefinition, Position, Feature, Point, pos, TraceNode} from "..";
1718
import {STARLASU_LANGUAGE} from "./lionweb-starlasu-language";
1819
export {STARLASU_LANGUAGE} from "./lionweb-starlasu-language";
1920

@@ -77,25 +78,37 @@ export class LanguageMapping {
7778
}
7879
}
7980

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

8585
function importFeature(feature: LWFeature): Feature | undefined {
8686
const def: Feature = { name: feature.name };
8787
if (feature instanceof Containment) {
88-
if (feature.type && isASTNode(feature.type)) {
88+
if (!isSpecialConcept(feature.type)) {
8989
def.child = true;
9090
def.multiple = feature.multiple;
9191
} 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
92+
// We don't import the containment because we handle it specially
9593
return undefined;
9694
}
9795
}
98-
return def
96+
return def;
97+
}
98+
99+
function importConcept(concept: NodeDefinition | undefined, classifier: Classifier) {
100+
concept = {
101+
name: classifier.name,
102+
features: {},
103+
resolved: true
104+
};
105+
allFeatures(classifier).forEach(f => {
106+
const feature = importFeature(f);
107+
if (feature) {
108+
concept!.features[f.name] = feature;
109+
}
110+
});
111+
return concept;
99112
}
100113

101114
export class TylasuInstantiationFacade implements InstantiationFacade<TylasuWrapper> {
@@ -128,17 +141,7 @@ export class TylasuInstantiationFacade implements InstantiationFacade<TylasuWrap
128141
if (!node) {
129142
let concept = this.concepts.get(classifier);
130143
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-
});
144+
concept = importConcept(concept, classifier);
142145
this.concepts.set(classifier, concept);
143146
}
144147
node = new LionwebNode(concept, {
@@ -281,3 +284,25 @@ export class LionwebNode extends NodeAdapter {
281284
return other instanceof LionwebNode && other.lwnode == this.lwnode;
282285
}
283286
}
287+
288+
export function deserializeToTylasuNodes(
289+
chunk: SerializationChunk,
290+
languages: Language[],
291+
languageMappings: LanguageMapping[] = [STARLASU_LANGUAGE_MAPPING],
292+
dependentNodes: LWNodeInterface[] = []
293+
): Node[] {
294+
return deserializeChunk(
295+
chunk, new TylasuInstantiationFacade(languageMappings), [STARLASU_LANGUAGE, ...languages], dependentNodes
296+
)
297+
.filter(n => n instanceof TylasuNodeWrapper)
298+
.map(n => (n as TylasuNodeWrapper).node);
299+
}
300+
301+
export function deserializeToTraceNodes(
302+
chunk: SerializationChunk,
303+
languages: Language[],
304+
dependentNodes: LWNodeInterface[] = []
305+
): TraceNode[] {
306+
return deserializeToTylasuNodes(chunk, languages, [], dependentNodes).map(
307+
n => new TraceNode(n as LionwebNode));
308+
}

tests/interop/fs-language.json

+13-78
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,7 @@
147147
"version": "2023.1",
148148
"key": "Concept-extends"
149149
},
150-
"targets": [
151-
{
152-
"resolveInfo": "ASTNode",
153-
"reference": "com-strumenta-StarLasu-ASTNode-id"
154-
}
155-
]
150+
"targets": []
156151
},
157152
{
158153
"reference": {
@@ -287,12 +282,7 @@
287282
"version": "2023.1",
288283
"key": "Concept-extends"
289284
},
290-
"targets": [
291-
{
292-
"resolveInfo": "ASTNode",
293-
"reference": "com-strumenta-StarLasu-ASTNode-id"
294-
}
295-
]
285+
"targets": []
296286
},
297287
{
298288
"reference": {
@@ -630,12 +620,7 @@
630620
"version": "2023.1",
631621
"key": "Concept-extends"
632622
},
633-
"targets": [
634-
{
635-
"resolveInfo": "ASTNode",
636-
"reference": "com-strumenta-StarLasu-ASTNode-id"
637-
}
638-
]
623+
"targets": []
639624
},
640625
{
641626
"reference": {
@@ -766,12 +751,7 @@
766751
"version": "2023.1",
767752
"key": "Concept-extends"
768753
},
769-
"targets": [
770-
{
771-
"resolveInfo": "ASTNode",
772-
"reference": "com-strumenta-StarLasu-ASTNode-id"
773-
}
774-
]
754+
"targets": []
775755
},
776756
{
777757
"reference": {
@@ -1096,12 +1076,7 @@
10961076
"version": "2023.1",
10971077
"key": "Concept-extends"
10981078
},
1099-
"targets": [
1100-
{
1101-
"resolveInfo": "ASTNode",
1102-
"reference": "com-strumenta-StarLasu-ASTNode-id"
1103-
}
1104-
]
1079+
"targets": []
11051080
},
11061081
{
11071082
"reference": {
@@ -1224,12 +1199,7 @@
12241199
"version": "2023.1",
12251200
"key": "Link-type"
12261201
},
1227-
"targets": [
1228-
{
1229-
"resolveInfo": "ASTNode",
1230-
"reference": "com-strumenta-StarLasu-ASTNode-id"
1231-
}
1232-
]
1202+
"targets": []
12331203
}
12341204
],
12351205
"annotations": [],
@@ -1357,12 +1327,7 @@
13571327
"version": "2023.1",
13581328
"key": "Concept-extends"
13591329
},
1360-
"targets": [
1361-
{
1362-
"resolveInfo": "ASTNode",
1363-
"reference": "com-strumenta-StarLasu-ASTNode-id"
1364-
}
1365-
]
1330+
"targets": []
13661331
},
13671332
{
13681333
"reference": {
@@ -1604,12 +1569,7 @@
16041569
"version": "2023.1",
16051570
"key": "Concept-extends"
16061571
},
1607-
"targets": [
1608-
{
1609-
"resolveInfo": "ASTNode",
1610-
"reference": "com-strumenta-StarLasu-ASTNode-id"
1611-
}
1612-
]
1572+
"targets": []
16131573
},
16141574
{
16151575
"reference": {
@@ -1943,12 +1903,7 @@
19431903
"version": "2023.1",
19441904
"key": "Concept-extends"
19451905
},
1946-
"targets": [
1947-
{
1948-
"resolveInfo": "ASTNode",
1949-
"reference": "com-strumenta-StarLasu-ASTNode-id"
1950-
}
1951-
]
1906+
"targets": []
19521907
},
19531908
{
19541909
"reference": {
@@ -2083,12 +2038,7 @@
20832038
"version": "2023.1",
20842039
"key": "Concept-extends"
20852040
},
2086-
"targets": [
2087-
{
2088-
"resolveInfo": "ASTNode",
2089-
"reference": "com-strumenta-StarLasu-ASTNode-id"
2090-
}
2091-
]
2041+
"targets": []
20922042
},
20932043
{
20942044
"reference": {
@@ -2275,12 +2225,7 @@
22752225
"version": "2023.1",
22762226
"key": "Concept-extends"
22772227
},
2278-
"targets": [
2279-
{
2280-
"resolveInfo": "ASTNode",
2281-
"reference": "com-strumenta-StarLasu-ASTNode-id"
2282-
}
2283-
]
2228+
"targets": []
22842229
},
22852230
{
22862231
"reference": {
@@ -2467,12 +2412,7 @@
24672412
"version": "2023.1",
24682413
"key": "Concept-extends"
24692414
},
2470-
"targets": [
2471-
{
2472-
"resolveInfo": "ASTNode",
2473-
"reference": "com-strumenta-StarLasu-ASTNode-id"
2474-
}
2475-
]
2415+
"targets": []
24762416
},
24772417
{
24782418
"reference": {
@@ -2667,12 +2607,7 @@
26672607
"version": "2023.1",
26682608
"key": "Concept-extends"
26692609
},
2670-
"targets": [
2671-
{
2672-
"resolveInfo": "ASTNode",
2673-
"reference": "com-strumenta-StarLasu-ASTNode-id"
2674-
}
2675-
]
2610+
"targets": []
26762611
},
26772612
{
26782613
"reference": {

0 commit comments

Comments
 (0)