Skip to content

Commit 3720f41

Browse files
committed
Lionweb: test with more current language and model
1 parent e20e7d4 commit 3720f41

File tree

5 files changed

+19603
-874
lines changed

5 files changed

+19603
-874
lines changed

src/interop/lionweb.ts

+17-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,18 @@ import {
1414
Node as LWNodeInterface,
1515
SerializationChunk
1616
} from "@lionweb/core";
17-
import {NodeAdapter, Issue, Node, NodeDefinition, Position, Feature, Point, pos, TraceNode} from "..";
17+
import {
18+
NodeAdapter,
19+
Issue,
20+
Node,
21+
NodeDefinition,
22+
Position,
23+
Feature,
24+
Point,
25+
pos,
26+
TraceNode,
27+
getNodeDefinition
28+
} from "..";
1829
import {STARLASU_LANGUAGE} from "./lionweb-starlasu-language";
1930
export {STARLASU_LANGUAGE} from "./lionweb-starlasu-language";
2031

@@ -64,6 +75,9 @@ export class LanguageMapping {
6475
readonly classifiers = new Map<Classifier, any>();
6576

6677
register(nodeType: any, classifier: Classifier) {
78+
if (!classifier) {
79+
throw new Error(`Can't register ${getNodeDefinition(nodeType)?.name}: not a classifier: ${classifier}`);
80+
}
6781
this.nodeTypes.set(nodeType, classifier);
6882
this.classifiers.set(classifier, nodeType);
6983
}
@@ -190,8 +204,8 @@ export function findClassifier(language: Language, id: string) {
190204
return language.entities.find(e => e.id == id) as Classifier;
191205
}
192206

193-
export const AST_NODE_CLASSIFIER = findClassifier(STARLASU_LANGUAGE, "com_strumenta_starlasu_ASTNode");
194-
STARLASU_LANGUAGE_MAPPING.register(Node, AST_NODE_CLASSIFIER)
207+
export const AST_NODE_CLASSIFIER = findClassifier(STARLASU_LANGUAGE, "com-strumenta-StarLasu-ASTNode-id");
208+
STARLASU_LANGUAGE_MAPPING.register(Node, AST_NODE_CLASSIFIER);
195209

196210
function allFeatures(classifier: Classifier) {
197211
const features = [...classifier.features];

src/model/model.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,12 @@ export abstract class Node extends Origin implements Destination {
184184
return props[name]?.child ? props[name] : undefined;
185185
}
186186

187-
setChild(name: string, child: Node): void {
187+
setChild(name: string | symbol, child: Node): void {
188188
const containment = this.containment(name);
189189
if(!containment) {
190-
throw new Error("Not a containment: " + name);
190+
throw this.notAContainment(name);
191191
} else if (containment.multiple) {
192-
throw new Error(name + " is a collection, use addChild");
192+
throw new Error(name.toString() + " is a collection, use addChild");
193193
}
194194
if(child.parent && child.parent != this) {
195195
throw new Error("Child already has a different parent");
@@ -200,12 +200,12 @@ export abstract class Node extends Origin implements Destination {
200200
this[name] = child.withParent(this);
201201
}
202202

203-
addChild(name: string, child: Node): void {
203+
addChild(name: string | symbol, child: Node): void {
204204
const containment = this.containment(name);
205205
if(!containment) {
206-
throw new Error("Not a containment: " + name);
206+
throw this.notAContainment(name);
207207
} else if (!containment.multiple) {
208-
throw new Error(name + " is not a collection, use setChild");
208+
throw new Error(name.toString() + " is not a collection, use setChild");
209209
}
210210
if(child.parent && child.parent != this) {
211211
throw new Error("Child already has a different parent");
@@ -216,10 +216,14 @@ export abstract class Node extends Origin implements Destination {
216216
this[name].push(child.withParent(this));
217217
}
218218

219+
private notAContainment(name: string | symbol) {
220+
return new Error(`Not a containment: ${name.toString()} of ${this.nodeDefinition?.name || "<unknown>"}`);
221+
}
222+
219223
getChild(name: string | symbol, index?: number): Node | undefined {
220224
const containment = this.containment(name);
221225
if(!containment) {
222-
throw new Error("Not a containment: " + name.toString());
226+
throw this.notAContainment(name);
223227
}
224228
const raw = this.doGetChildOrChildren(name);
225229
if (containment.multiple) {
@@ -271,7 +275,7 @@ export abstract class Node extends Origin implements Destination {
271275
getChildrenWithRole(name: string | symbol) {
272276
const containment = this.containment(name);
273277
if (!containment) {
274-
throw new Error("Not a containment: " + name.toString());
278+
throw this.notAContainment(name);
275279
}
276280
const raw = this.doGetChildOrChildren(name);
277281
if (containment.multiple) {

0 commit comments

Comments
 (0)