1- import base64
21import re
32from typing import Optional
43
54from lionwebpython .language import Language , Concept , Property , Containment
6- from lionwebpython .language .classifier import Classifier
75from lionwebpython .language .lioncore_builtins import LionCoreBuiltins
6+ from lionwebpython .lionweb_version import LionWebVersion
87from lionwebpython .model .classifier_instance_utils import ClassifierInstanceUtils
98from lionwebpython .model .impl .dynamic_node import DynamicNode
109from lionwebpython .model .node import Node
11- from lionwebpython .lionweb_version import LionWebVersion
1210from lionwebpython .serialization .json_serialization import JsonSerialization
1311
1412LW_REFERENCE_VERSION = LionWebVersion .V2023_1
1513
16- CODEBASE_LANGUAGE = Language (lion_web_version = LW_REFERENCE_VERSION , name = "Codebase" ,
17- id = "strumenta-codebase" , version = "1" , key = "strumenta-codebase" )
14+ CODEBASE_LANGUAGE = Language (
15+ lion_web_version = LW_REFERENCE_VERSION , name = "Codebase" ,
16+ id = "strumenta-codebase" , version = "1" , key = "strumenta-codebase" )
1817
19- CODEBASE_FILE = Concept (lion_web_version = LW_REFERENCE_VERSION , name = "CodebaseFile" ,
20- id = "strumenta-codebase-file" , key = "strumenta-codebase-file" )
18+ CODEBASE_FILE = Concept (
19+ lion_web_version = LW_REFERENCE_VERSION , name = "CodebaseFile" ,
20+ id = "strumenta-codebase-file" , key = "strumenta-codebase-file" )
2121CODEBASE_LANGUAGE .add_element (CODEBASE_FILE )
2222
23- CODEBASE_FILE_LANGUAGE_NAME = Property (lion_web_version = LW_REFERENCE_VERSION , name = "language_name" ,
24- id = "strumenta-codebase-file-language-name" )
23+ CODEBASE_FILE_LANGUAGE_NAME = Property (
24+ lion_web_version = LW_REFERENCE_VERSION , name = "language_name" ,
25+ id = "strumenta-codebase-file-language-name" )
2526CODEBASE_FILE .add_feature (CODEBASE_FILE_LANGUAGE_NAME )
2627CODEBASE_FILE_LANGUAGE_NAME .set_key ("strumenta-codebase-file-language-name" )
2728CODEBASE_FILE_LANGUAGE_NAME .set_optional (False )
2829CODEBASE_FILE_LANGUAGE_NAME .set_type (LionCoreBuiltins .get_string (LW_REFERENCE_VERSION ))
2930
30- CODEBASE_FILE_RELATIVE_PATH = Property (lion_web_version = LW_REFERENCE_VERSION , name = "relative_path" ,
31- id = "strumenta-codebase-file-relative-path" )
31+ CODEBASE_FILE_RELATIVE_PATH = Property (
32+ lion_web_version = LW_REFERENCE_VERSION , name = "relative_path" ,
33+ id = "strumenta-codebase-file-relative-path" )
3234CODEBASE_FILE .add_feature (CODEBASE_FILE_RELATIVE_PATH )
3335CODEBASE_FILE_RELATIVE_PATH .set_key ("strumenta-codebase-file-relative-path" )
3436CODEBASE_FILE_RELATIVE_PATH .set_optional (False )
3537CODEBASE_FILE_RELATIVE_PATH .set_type (LionCoreBuiltins .get_string (LW_REFERENCE_VERSION ))
3638
37- CODEBASE_FILE_CODE = Property (lion_web_version = LW_REFERENCE_VERSION , name = "code" ,
38- id = "strumenta-codebase-file-code" )
39+ CODEBASE_FILE_CODE = Property (
40+ lion_web_version = LW_REFERENCE_VERSION , name = "code" ,
41+ id = "strumenta-codebase-file-code" )
3942CODEBASE_FILE .add_feature (CODEBASE_FILE_CODE )
4043CODEBASE_FILE_CODE .set_key ("strumenta-codebase-file-code" )
4144CODEBASE_FILE_CODE .set_optional (False )
4245CODEBASE_FILE_CODE .set_type (LionCoreBuiltins .get_string (LW_REFERENCE_VERSION ))
4346
44- CODEBASE_FILE_AST = Containment (lion_web_version = LW_REFERENCE_VERSION , name = "ast" ,
45- id = "strumenta-codebase-file-ast" )
47+ CODEBASE_FILE_AST = Containment (
48+ lion_web_version = LW_REFERENCE_VERSION , name = "ast" ,
49+ id = "strumenta-codebase-file-ast" )
4650CODEBASE_FILE .add_feature (CODEBASE_FILE_AST )
4751CODEBASE_FILE_AST .set_key ("strumenta-codebase-file-ast" )
4852CODEBASE_FILE_AST .set_optional (True )
@@ -76,6 +80,7 @@ def to_lionweb_identifier(s: str) -> str:
7680 # Ensure the identifier is not empty
7781 return s if s else "_"
7882
83+
7984class CodebaseFile (DynamicNode ):
8085 language_name : str
8186 relative_path : str
@@ -127,21 +132,23 @@ def ast(self, value):
127132 self .remove_child (child = children [0 ])
128133 self .add_child (containment = containment , child = value )
129134
130- def __init__ (self , language_name : str , relative_path : str , code : str , ast : Optional [Node ] = None , id : Optional [str ] = None ):
135+ def __init__ (self , language_name : str , relative_path : str , code : str , ast : Optional [Node ] = None ,
136+ id : Optional [str ] = None ):
131137 super ().__init__ (id or f"codebase_file_{ to_lionweb_identifier (relative_path )} " , CODEBASE_FILE )
132138 self .language_name = language_name
133139 self .relative_path = relative_path
134140 self .code = code
135141 self .ast = ast
136142
137143
138- def codebase_deserializer (classifier , serialized_instance ,
139- deserialized_instances_by_id , properties_values ) -> CodebaseFile :
144+ def codebase_deserializer (
145+ classifier , serialized_instance ,
146+ deserialized_instances_by_id , properties_values ) -> CodebaseFile :
140147 language_name = properties_values [classifier .get_property_by_name ('language_name' )]
141148 relative_path = properties_values [classifier .get_property_by_name ('relative_path' )]
142149 code = properties_values [classifier .get_property_by_name ('code' )]
143150 return CodebaseFile (language_name = language_name , relative_path = relative_path , code = code , id = serialized_instance .id )
144151
145152
146153def register_codebase_deserializers (jsonser : JsonSerialization ):
147- jsonser .instantiator .register_custom_deserializer (CODEBASE_FILE .get_id (), codebase_deserializer )
154+ jsonser .instantiator .register_custom_deserializer (CODEBASE_FILE .get_id (), codebase_deserializer )
0 commit comments