1
- import base64
2
1
import re
3
2
from typing import Optional
4
3
5
4
from lionwebpython .language import Language , Concept , Property , Containment
6
- from lionwebpython .language .classifier import Classifier
7
5
from lionwebpython .language .lioncore_builtins import LionCoreBuiltins
6
+ from lionwebpython .lionweb_version import LionWebVersion
8
7
from lionwebpython .model .classifier_instance_utils import ClassifierInstanceUtils
9
8
from lionwebpython .model .impl .dynamic_node import DynamicNode
10
9
from lionwebpython .model .node import Node
11
- from lionwebpython .lionweb_version import LionWebVersion
12
10
from lionwebpython .serialization .json_serialization import JsonSerialization
13
11
14
12
LW_REFERENCE_VERSION = LionWebVersion .V2023_1
15
13
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" )
18
17
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" )
21
21
CODEBASE_LANGUAGE .add_element (CODEBASE_FILE )
22
22
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" )
25
26
CODEBASE_FILE .add_feature (CODEBASE_FILE_LANGUAGE_NAME )
26
27
CODEBASE_FILE_LANGUAGE_NAME .set_key ("strumenta-codebase-file-language-name" )
27
28
CODEBASE_FILE_LANGUAGE_NAME .set_optional (False )
28
29
CODEBASE_FILE_LANGUAGE_NAME .set_type (LionCoreBuiltins .get_string (LW_REFERENCE_VERSION ))
29
30
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" )
32
34
CODEBASE_FILE .add_feature (CODEBASE_FILE_RELATIVE_PATH )
33
35
CODEBASE_FILE_RELATIVE_PATH .set_key ("strumenta-codebase-file-relative-path" )
34
36
CODEBASE_FILE_RELATIVE_PATH .set_optional (False )
35
37
CODEBASE_FILE_RELATIVE_PATH .set_type (LionCoreBuiltins .get_string (LW_REFERENCE_VERSION ))
36
38
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" )
39
42
CODEBASE_FILE .add_feature (CODEBASE_FILE_CODE )
40
43
CODEBASE_FILE_CODE .set_key ("strumenta-codebase-file-code" )
41
44
CODEBASE_FILE_CODE .set_optional (False )
42
45
CODEBASE_FILE_CODE .set_type (LionCoreBuiltins .get_string (LW_REFERENCE_VERSION ))
43
46
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" )
46
50
CODEBASE_FILE .add_feature (CODEBASE_FILE_AST )
47
51
CODEBASE_FILE_AST .set_key ("strumenta-codebase-file-ast" )
48
52
CODEBASE_FILE_AST .set_optional (True )
@@ -76,6 +80,7 @@ def to_lionweb_identifier(s: str) -> str:
76
80
# Ensure the identifier is not empty
77
81
return s if s else "_"
78
82
83
+
79
84
class CodebaseFile (DynamicNode ):
80
85
language_name : str
81
86
relative_path : str
@@ -127,21 +132,23 @@ def ast(self, value):
127
132
self .remove_child (child = children [0 ])
128
133
self .add_child (containment = containment , child = value )
129
134
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 ):
131
137
super ().__init__ (id or f"codebase_file_{ to_lionweb_identifier (relative_path )} " , CODEBASE_FILE )
132
138
self .language_name = language_name
133
139
self .relative_path = relative_path
134
140
self .code = code
135
141
self .ast = ast
136
142
137
143
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 :
140
147
language_name = properties_values [classifier .get_property_by_name ('language_name' )]
141
148
relative_path = properties_values [classifier .get_property_by_name ('relative_path' )]
142
149
code = properties_values [classifier .get_property_by_name ('code' )]
143
150
return CodebaseFile (language_name = language_name , relative_path = relative_path , code = code , id = serialized_instance .id )
144
151
145
152
146
153
def 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