@@ -117,11 +117,82 @@ def _generate_from_feature(feature: Feature, classdef: ClassDef):
117117 raise ValueError ()
118118
119119
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+
120191def _generate_from_concept (classifier : Concept ) -> ClassDef :
121192 bases = []
122193 if classifier .get_extended_concept ().id == StarLasuBaseLanguage .get_astnode (LionWebVersion .V2023_1 ).id :
123194 if len (classifier .get_implemented ()) == 0 :
124- bases .append ('Node ' )
195+ bases .append ('ASTNode ' )
125196 else :
126197 bases .append (classifier .get_extended_concept ().get_name ())
127198 special_interfaces = {
@@ -132,6 +203,7 @@ def _generate_from_concept(classifier: Concept) -> ClassDef:
132203 'com-strumenta-StarLasu-Documentation-id' : 'StarLasuDocumentation' ,
133204 'com-strumenta-StarLasu-BehaviorDeclaration-id' : 'StarLasuBehaviorDeclaration' ,
134205 'com-strumenta-StarLasu-EntityDeclaration-id' : 'StarLasuEntityDeclaration' ,
206+ 'com-strumenta-StarLasu-TypeAnnotation-id' : 'StarLasuTypeAnnotation' ,
135207 'LionCore-builtins-INamed' : 'StarLasuNamed'
136208 }
137209 for i in classifier .get_implemented ():
@@ -144,12 +216,14 @@ def _generate_from_concept(classifier: Concept) -> ClassDef:
144216 dataclass_decorator = ast .Name (id = "dataclass" , ctx = ast .Load ())
145217 classdef = ast .ClassDef (classifier .get_name (), bases = bases ,
146218 keywords = [],
147- body = [ast . Pass () ],
219+ body = [],
148220 decorator_list = [dataclass_decorator ])
149221
150222 for feature in classifier .get_features ():
151223 _generate_from_feature (feature , classdef )
152224
225+ classdef .body .append (_generate_constructor ())
226+
153227 return classdef
154228
155229
@@ -188,11 +262,22 @@ def ast_generation(click, language: Language, output):
188262 level = 0
189263 )
190264 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 (
191275 module = 'pylasu.model' ,
192- names = [ast .alias (name = 'Node ' , asname = None )],
276+ names = [ast .alias (name = 'Position ' , asname = None )],
193277 level = 0
194278 )
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 ],
196281 type_ignores = [])
197282
198283 for element in language .get_elements ():
@@ -230,7 +315,7 @@ def ast_generation(click, language: Language, output):
230315 elif isinstance (classifier , Interface ):
231316 bases = []
232317 if len (classifier .get_extended_interfaces ()) == 0 :
233- bases .append ("Node " )
318+ bases .append ("ASTNode " )
234319 # bases.append("ABC")
235320
236321 classdef = ast .ClassDef (classifier .get_name (), bases = bases ,
0 commit comments