@@ -6,22 +6,24 @@ import {
6
6
Classifier ,
7
7
Concept ,
8
8
Containment ,
9
- Feature ,
9
+ Feature as LWFeature ,
10
10
Id ,
11
11
InstantiationFacade ,
12
12
Interface ,
13
13
Language ,
14
- Node as LionwebNodeInterface
14
+ Node as LWNodeInterface
15
15
} from "@lionweb/core" ;
16
- import { NodeAdapter , Issue , Node , NodeDefinition , Position , PropertyDefinition } from ".." ;
16
+ import { NodeAdapter , Issue , Node , NodeDefinition , Position , Feature } from ".." ;
17
17
import { STARLASU_LANGUAGE } from "./lionweb-starlasu-language" ;
18
18
export { STARLASU_LANGUAGE } from "./lionweb-starlasu-language" ;
19
19
20
- export class TylasuNodeWrapper implements LionwebNodeInterface {
20
+ export const ASTNode = STARLASU_LANGUAGE . entities . find ( e => e . name == "ASTNode" ) ! ;
21
+
22
+ export class TylasuNodeWrapper implements LWNodeInterface {
21
23
id : Id ;
22
24
node : Node ;
23
- parent ?: LionwebNodeInterface ;
24
- annotations : LionwebNodeInterface [ ] ;
25
+ parent ?: LWNodeInterface ;
26
+ annotations : LWNodeInterface [ ] ;
25
27
}
26
28
27
29
export class LanguageMapping {
@@ -43,11 +45,23 @@ export class LanguageMapping {
43
45
}
44
46
}
45
47
46
- function featureToProperty ( feature : Feature ) : PropertyDefinition {
47
- const def : PropertyDefinition = { name : feature . name } ;
48
+ function isASTNode ( classifier : Classifier ) {
49
+ return ( classifier instanceof Concept ) &&
50
+ ( classifier . key == ASTNode . key || ( classifier . extends && isASTNode ( classifier . extends ) ) ) ;
51
+ }
52
+
53
+ function importFeature ( feature : LWFeature ) : Feature | undefined {
54
+ const def : Feature = { name : feature . name } ;
48
55
if ( feature instanceof Containment ) {
49
- def . child = true ;
50
- def . multiple = feature . multiple ;
56
+ if ( isASTNode ( feature . classifier ) ) {
57
+ def . child = true ;
58
+ def . multiple = feature . multiple ;
59
+ } else {
60
+ // TODO we assume that:
61
+ // 1) we're importing a StarLasu AST
62
+ // 2) containments in a StarLasu AST are either AST nodes or internal StarLasu objects like the position
63
+ return undefined ;
64
+ }
51
65
}
52
66
return def
53
67
}
@@ -81,7 +95,7 @@ export class TylasuInstantiationFacade implements InstantiationFacade<TylasuNode
81
95
annotations : [ ]
82
96
} ;
83
97
}
84
- setFeatureValue ( node : TylasuNodeWrapper , feature : Feature , value : unknown ) : void {
98
+ setFeatureValue ( node : TylasuNodeWrapper , feature : LWFeature , value : unknown ) : void {
85
99
if ( feature instanceof Containment ) {
86
100
if ( feature . multiple ) {
87
101
node . node . addChild ( feature . name , ( value as TylasuNodeWrapper ) ?. node ) ;
@@ -132,16 +146,19 @@ export class LionwebNode extends NodeAdapter {
132
146
133
147
constructor (
134
148
public readonly classifier : Classifier ,
135
- protected lwnode : LionwebNodeInterface
149
+ protected lwnode : LWNodeInterface
136
150
) {
137
151
super ( ) ;
138
- const properties = { } ;
152
+ const features = { } ;
139
153
allFeatures ( classifier ) . forEach ( f => {
140
- properties [ f . name ] = featureToProperty ( f ) ;
154
+ const feature = importFeature ( f ) ;
155
+ if ( feature ) {
156
+ features [ f . name ] = feature ;
157
+ }
141
158
} ) ;
142
159
this . _nodeDefinition = {
143
160
name : classifier . name ,
144
- features : properties ,
161
+ features,
145
162
resolved : true
146
163
} ;
147
164
}
0 commit comments