Skip to content

Commit 4e29e15

Browse files
committed
ParserNode instances usable without ECore
1 parent e733053 commit 4e29e15

File tree

4 files changed

+42
-14
lines changed

4 files changed

+42
-14
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
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.12] – 2024-03-07
6+
7+
### Added
8+
- LionwebNode get method
9+
10+
### Fixed
11+
- ECoreNode definition
12+
513
## [1.6.11] – 2024-03-07
614

715
### Changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "AST building blocks for TypeScript/JavaScript, part of the *lasu family, with optional integrations with ANTLR4 and Ecore.",
44
"author": "Strumenta s.r.l.",
55
"publisher": "strumenta",
6-
"version": "1.6.11",
6+
"version": "1.6.12",
77
"license": "Apache-2.0",
88
"keywords": [
99
"antlr",

src/interop/ecore.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -838,17 +838,17 @@ export class ECoreNode extends NodeAdapter {
838838
}
839839
}
840840

841-
private __nodeDefinition?: NodeDefinition;
841+
private _nodeDefinition?: NodeDefinition;
842842

843843
get nodeDefinition() {
844-
if (!this.__nodeDefinition) {
845-
this.__nodeDefinition = {
844+
if (!this._nodeDefinition) {
845+
this._nodeDefinition = {
846846
package: this.eo.eClass.eContainer.get("name") as string,
847847
name: this.eo.eClass.get("name") as string,
848848
properties: this.getProperties()
849849
};
850850
}
851-
return this.__nodeDefinition;
851+
return this._nodeDefinition;
852852
}
853853

854854
get(...path: string[]): NodeAdapter | undefined {
@@ -876,13 +876,13 @@ export class ECoreNode extends NodeAdapter {
876876
return result;
877877
}
878878

879-
private __children?: ECoreNode[] = undefined;
879+
private _children?: ECoreNode[] = undefined;
880880

881881
getChildren(role?: string): ECoreNode[] {
882-
if (this.__children === undefined) {
883-
this.__children = this.getChildrenEObjects().map(c => new ECoreNode(c, this));
882+
if (this._children === undefined) {
883+
this._children = this.getChildrenEObjects().map(c => new ECoreNode(c, this));
884884
}
885-
return this.__children!.filter(c => !role || c.getRole() == role);
885+
return this._children!.filter(c => !role || c.getRole() == role);
886886
}
887887

888888
getId(): string {

src/interop/lionweb.ts

+25-5
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ function allFeatures(classifier: Classifier) {
125125
export class LionwebNode extends NodeAdapter {
126126

127127
parent: LionwebNode;
128-
public readonly nodeDefinition: NodeDefinition;
128+
private _nodeDefinition?: NodeDefinition;
129+
public get nodeDefinition(): NodeDefinition {
130+
return this._nodeDefinition!;
131+
}
129132

130133
constructor(
131134
public readonly classifier: Classifier,
@@ -136,20 +139,37 @@ export class LionwebNode extends NodeAdapter {
136139
allFeatures(classifier).forEach(f => {
137140
properties[f.name] = featureToProperty(f);
138141
});
139-
this.nodeDefinition = {
142+
this._nodeDefinition = {
140143
name: classifier.name,
141144
properties: properties,
142145
resolved: true
143146
};
144147
}
145148

146149
// eslint-disable-next-line @typescript-eslint/no-unused-vars
147-
get(...path: string[]): NodeAdapter | undefined {
148-
return undefined; // TODO
150+
get(...path: string[]): LionwebNode | undefined {
151+
let result: LionwebNode | undefined = undefined;
152+
// eslint-disable-next-line @typescript-eslint/no-this-alias
153+
let parent: LionwebNode = this;
154+
for (const element of path) {
155+
result = parent.getChild(element) as LionwebNode;
156+
if (result) {
157+
parent = result;
158+
} else {
159+
return undefined;
160+
}
161+
}
162+
return result;
149163
}
150164

151165
getAttributes(): { [p: string]: any } {
152-
return {}; // TODO
166+
const attributes = {};
167+
for (const p in this.nodeDefinition.properties) {
168+
if (!this.nodeDefinition.properties[p].child) {
169+
attributes[p] = this.getAttribute(p);
170+
}
171+
}
172+
return attributes;
153173
}
154174

155175
getId(): string {

0 commit comments

Comments
 (0)