@@ -117,11 +117,82 @@ def _generate_from_feature(feature: Feature, classdef: ClassDef):
117
117
raise ValueError ()
118
118
119
119
120
+ def _generate_constructor () -> ast .FunctionDef :
121
+ return ast .FunctionDef (
122
+ name = "__init__" ,
123
+ args = ast .arguments (
124
+ posonlyargs = [],
125
+ args = [
126
+ ast .arg (arg = "self" , annotation = None ),
127
+ ast .arg (arg = "id" , annotation = ast .Name (id = "str" , ctx = ast .Load ())),
128
+ ast .arg (arg = "concept" , annotation = ast .Name (id = "Concept" , ctx = ast .Load ())),
129
+ ast .arg (arg = "position" , annotation = ast .Subscript (
130
+ value = ast .Name (id = "Optional" , ctx = ast .Load ()),
131
+ slice = ast .Name (id = "Position" , ctx = ast .Load ()),
132
+ ctx = ast .Load ()
133
+ )),
134
+ ],
135
+ kwonlyargs = [], kw_defaults = [], defaults = []
136
+ ),
137
+ body = [
138
+ # super().__init__(id=id, position=position, concept=concept)
139
+ ast .Expr (value = ast .Call (
140
+ func = ast .Attribute (
141
+ value = ast .Call (func = ast .Name (id = 'super' , ctx = ast .Load ()), args = [], keywords = []),
142
+ attr = '__init__' ,
143
+ ctx = ast .Load ()
144
+ ),
145
+ args = [],
146
+ keywords = [
147
+ ast .keyword (arg = 'id' , value = ast .Name (id = 'id' , ctx = ast .Load ())),
148
+ ast .keyword (arg = 'position' , value = ast .Name (id = 'position' , ctx = ast .Load ())),
149
+ ast .keyword (arg = 'concept' , value = ast .Name (id = 'concept' , ctx = ast .Load ())),
150
+ ]
151
+ )),
152
+ # self.set_id(id)
153
+ ast .Expr (value = ast .Call (
154
+ func = ast .Attribute (value = ast .Name (id = 'self' , ctx = ast .Load ()), attr = 'set_id' , ctx = ast .Load ()),
155
+ args = [ast .Name (id = 'id' , ctx = ast .Load ())],
156
+ keywords = []
157
+ )),
158
+ # # self._set_containment_single_value(..., ...)
159
+ # ast.Expr(value=ast.Call(
160
+ # func=ast.Attribute(
161
+ # value=ast.Name(id='self', ctx=ast.Load()),
162
+ # attr='_set_containment_single_value',
163
+ # ctx=ast.Load()
164
+ # ),
165
+ # args=[],
166
+ # keywords=[
167
+ # ast.keyword(
168
+ # arg='containment',
169
+ # value=ast.Call(
170
+ # func=ast.Attribute(
171
+ # value=ast.Name(id='concept', ctx=ast.Load()),
172
+ # attr='get_containment_by_name',
173
+ # ctx=ast.Load()
174
+ # ),
175
+ # args=[ast.Constant(value='externalName')],
176
+ # keywords=[]
177
+ # )
178
+ # ),
179
+ # ast.keyword(
180
+ # arg='value',
181
+ # value=ast.Name(id='externalName', ctx=ast.Load())
182
+ # )
183
+ # ]
184
+ # ))
185
+ ],
186
+ decorator_list = [],
187
+ returns = None
188
+ )
189
+
190
+
120
191
def _generate_from_concept (classifier : Concept ) -> ClassDef :
121
192
bases = []
122
193
if classifier .get_extended_concept ().id == StarLasuBaseLanguage .get_astnode (LionWebVersion .V2023_1 ).id :
123
194
if len (classifier .get_implemented ()) == 0 :
124
- bases .append ('Node ' )
195
+ bases .append ('ASTNode ' )
125
196
else :
126
197
bases .append (classifier .get_extended_concept ().get_name ())
127
198
special_interfaces = {
@@ -132,6 +203,7 @@ def _generate_from_concept(classifier: Concept) -> ClassDef:
132
203
'com-strumenta-StarLasu-Documentation-id' : 'StarLasuDocumentation' ,
133
204
'com-strumenta-StarLasu-BehaviorDeclaration-id' : 'StarLasuBehaviorDeclaration' ,
134
205
'com-strumenta-StarLasu-EntityDeclaration-id' : 'StarLasuEntityDeclaration' ,
206
+ 'com-strumenta-StarLasu-TypeAnnotation-id' : 'StarLasuTypeAnnotation' ,
135
207
'LionCore-builtins-INamed' : 'StarLasuNamed'
136
208
}
137
209
for i in classifier .get_implemented ():
@@ -144,12 +216,14 @@ def _generate_from_concept(classifier: Concept) -> ClassDef:
144
216
dataclass_decorator = ast .Name (id = "dataclass" , ctx = ast .Load ())
145
217
classdef = ast .ClassDef (classifier .get_name (), bases = bases ,
146
218
keywords = [],
147
- body = [ast . Pass () ],
219
+ body = [],
148
220
decorator_list = [dataclass_decorator ])
149
221
150
222
for feature in classifier .get_features ():
151
223
_generate_from_feature (feature , classdef )
152
224
225
+ classdef .body .append (_generate_constructor ())
226
+
153
227
return classdef
154
228
155
229
@@ -188,11 +262,22 @@ def ast_generation(click, language: Language, output):
188
262
level = 0
189
263
)
190
264
import_node = ast .ImportFrom (
265
+ module = 'pylasu.lwmodel' ,
266
+ names = [ast .alias (name = 'ASTNode' , asname = None )],
267
+ level = 0
268
+ )
269
+ import_language = ast .ImportFrom (
270
+ module = 'lionwebpython.language' ,
271
+ names = [ast .alias (name = 'Concept' , asname = None )],
272
+ level = 0
273
+ )
274
+ import_model = ast .ImportFrom (
191
275
module = 'pylasu.model' ,
192
- names = [ast .alias (name = 'Node ' , asname = None )],
276
+ names = [ast .alias (name = 'Position ' , asname = None )],
193
277
level = 0
194
278
)
195
- module = ast .Module (body = [import_abc , import_dataclass , import_typing , import_enum , import_starlasu , import_node ],
279
+ module = ast .Module (body = [import_abc , import_dataclass , import_typing , import_enum , import_starlasu , import_node ,
280
+ import_language , import_model ],
196
281
type_ignores = [])
197
282
198
283
for element in language .get_elements ():
@@ -230,7 +315,7 @@ def ast_generation(click, language: Language, output):
230
315
elif isinstance (classifier , Interface ):
231
316
bases = []
232
317
if len (classifier .get_extended_interfaces ()) == 0 :
233
- bases .append ("Node " )
318
+ bases .append ("ASTNode " )
234
319
# bases.append("ABC")
235
320
236
321
classdef = ast .ClassDef (classifier .get_name (), bases = bases ,
0 commit comments