1313from lionwebpython .lionweb_version import LionWebVersion
1414
1515from pylasu .lionweb .starlasu import StarLasuBaseLanguage
16- from pylasu .lionweb .utils import calculate_field_name
16+ from pylasu .lionweb .utils import calculate_field_name , to_snake_case
1717
1818
1919def _identify_topological_deps (classifiers : List [Classifier ], id_to_concept ) -> Dict [str , List [str ]]:
@@ -117,15 +117,14 @@ def _generate_from_feature(feature: Feature, classdef: ClassDef):
117117 raise ValueError ()
118118
119119
120- def _generate_constructor () -> ast .FunctionDef :
120+ def _generate_constructor (concept : Concept ) -> ast .FunctionDef :
121121 return ast .FunctionDef (
122122 name = "__init__" ,
123123 args = ast .arguments (
124124 posonlyargs = [],
125125 args = [
126126 ast .arg (arg = "self" , annotation = None ),
127127 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 ())),
129128 ast .arg (arg = "position" , annotation = ast .Subscript (
130129 value = ast .Name (id = "Optional" , ctx = ast .Load ()),
131130 slice = ast .Name (id = "Position" , ctx = ast .Load ()),
@@ -146,7 +145,7 @@ def _generate_constructor() -> ast.FunctionDef:
146145 keywords = [
147146 ast .keyword (arg = 'id' , value = ast .Name (id = 'id' , ctx = ast .Load ())),
148147 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 ())),
148+ ast .keyword (arg = 'concept' , value = ast .Name (id = ast . Name ( id = to_snake_case ( concept . get_name ()). upper () , ctx = ast .Load () ))),
150149 ]
151150 )),
152151 # self.set_id(id)
@@ -222,12 +221,12 @@ def _generate_from_concept(classifier: Concept) -> ClassDef:
222221 for feature in classifier .get_features ():
223222 _generate_from_feature (feature , classdef )
224223
225- classdef .body .append (_generate_constructor ())
224+ classdef .body .append (_generate_constructor (classifier ))
226225
227226 return classdef
228227
229228
230- def ast_generation (click , language : Language , output ):
229+ def ast_generation (click , language : Language , output , language_name = str ):
231230 import_abc = ast .ImportFrom (
232231 module = 'abc' ,
233232 names = [ast .alias (name = 'ABC' , asname = None )],
@@ -276,8 +275,14 @@ def ast_generation(click, language: Language, output):
276275 names = [ast .alias (name = 'Position' , asname = None )],
277276 level = 0
278277 )
278+ # from rpg.language import CONTROL_SPECIFICATION
279+ import_concepts = ast .ImportFrom (
280+ module = f"{ language_name .lower ()} .language" ,
281+ names = [ast .alias (name = to_snake_case (e .get_name ()).upper (), asname = None )for e in language .get_elements () if isinstance (e , Concept )],
282+ level = 0
283+ )
279284 module = ast .Module (body = [import_abc , import_dataclass , import_typing , import_enum , import_starlasu , import_node ,
280- import_language , import_model ],
285+ import_language , import_model , import_concepts ],
281286 type_ignores = [])
282287
283288 for element in language .get_elements ():
0 commit comments