13
13
from lionwebpython .lionweb_version import LionWebVersion
14
14
15
15
from 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
17
17
18
18
19
19
def _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):
117
117
raise ValueError ()
118
118
119
119
120
- def _generate_constructor () -> ast .FunctionDef :
120
+ def _generate_constructor (concept : Concept ) -> ast .FunctionDef :
121
121
return ast .FunctionDef (
122
122
name = "__init__" ,
123
123
args = ast .arguments (
124
124
posonlyargs = [],
125
125
args = [
126
126
ast .arg (arg = "self" , annotation = None ),
127
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
128
ast .arg (arg = "position" , annotation = ast .Subscript (
130
129
value = ast .Name (id = "Optional" , ctx = ast .Load ()),
131
130
slice = ast .Name (id = "Position" , ctx = ast .Load ()),
@@ -146,7 +145,7 @@ def _generate_constructor() -> ast.FunctionDef:
146
145
keywords = [
147
146
ast .keyword (arg = 'id' , value = ast .Name (id = 'id' , ctx = ast .Load ())),
148
147
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 () ))),
150
149
]
151
150
)),
152
151
# self.set_id(id)
@@ -222,12 +221,12 @@ def _generate_from_concept(classifier: Concept) -> ClassDef:
222
221
for feature in classifier .get_features ():
223
222
_generate_from_feature (feature , classdef )
224
223
225
- classdef .body .append (_generate_constructor ())
224
+ classdef .body .append (_generate_constructor (classifier ))
226
225
227
226
return classdef
228
227
229
228
230
- def ast_generation (click , language : Language , output ):
229
+ def ast_generation (click , language : Language , output , language_name = str ):
231
230
import_abc = ast .ImportFrom (
232
231
module = 'abc' ,
233
232
names = [ast .alias (name = 'ABC' , asname = None )],
@@ -276,8 +275,14 @@ def ast_generation(click, language: Language, output):
276
275
names = [ast .alias (name = 'Position' , asname = None )],
277
276
level = 0
278
277
)
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
+ )
279
284
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 ],
281
286
type_ignores = [])
282
287
283
288
for element in language .get_elements ():
0 commit comments