libqasm 0.6.6__cp311-cp311-macosx_11_0_universal2.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
cqasm/__init__.py ADDED
@@ -0,0 +1 @@
1
+ #
cqasm/v3x/__init__.py ADDED
@@ -0,0 +1,65 @@
1
+ import cqasm.v3x.ast as ast
2
+ import cqasm.v3x.semantic as semantic
3
+ import libqasm
4
+
5
+
6
+ class Analyzer(libqasm.V3xAnalyzer):
7
+ # parse_file and parse_string are static methods because they do not change the status of the analyzer
8
+ # Instead, they just invoke free functions that create a temporary instance of a parser
9
+ # analyze_file and analyze_string are not static methods because they change the status of the analyzer
10
+
11
+ # parse_file, parse_string, analyze_file, and analyze_string return a vector of strings
12
+ # If the length of the vector is 1, the string is a serialization of the AST
13
+ # Otherwise, it is a list of errors
14
+
15
+ @staticmethod
16
+ def parse_file(*args):
17
+ ret = libqasm.V3xAnalyzer.parse_file(*args)
18
+ if len(ret) == 1:
19
+ serialized_ast_str = str(ret[0])
20
+ serialized_ast_bytes = serialized_ast_str.encode(encoding='utf-8', errors="surrogateescape")
21
+ deserialized_ast = ast.Root.deserialize(serialized_ast_bytes)
22
+ return deserialized_ast
23
+ return [str(error) for error in ret[1:]]
24
+
25
+ @staticmethod
26
+ def parse_string(*args):
27
+ ret = libqasm.V3xAnalyzer.parse_string(*args)
28
+ if len(ret) == 1:
29
+ serialized_ast_str = str(ret[0])
30
+ serialized_ast_bytes = serialized_ast_str.encode(encoding='utf-8', errors="surrogateescape")
31
+ deserialized_ast = ast.Root.deserialize(serialized_ast_bytes)
32
+ return deserialized_ast
33
+ return [str(error) for error in ret[1:]]
34
+
35
+ def analyze_file(self, *args):
36
+ ret = super().analyze_file(*args)
37
+ if len(ret) == 1:
38
+ serialized_ast_str = str(ret[0])
39
+ serialized_ast_bytes = serialized_ast_str.encode(encoding='utf-8', errors="surrogateescape")
40
+ deserialized_ast = semantic.Program.deserialize(serialized_ast_bytes)
41
+ return deserialized_ast
42
+ return [str(error) for error in ret[1:]]
43
+
44
+ def analyze_string(self, *args):
45
+ ret = super().analyze_string(*args)
46
+ if len(ret) == 1:
47
+ serialized_ast_str = str(ret[0])
48
+ serialized_ast_bytes = serialized_ast_str.encode(encoding='utf-8', errors="surrogateescape")
49
+ deserialized_ast = semantic.Program.deserialize(serialized_ast_bytes)
50
+ return deserialized_ast
51
+ return [str(error) for error in ret[1:]]
52
+
53
+ @staticmethod
54
+ def parse_file_to_json(*args):
55
+ return libqasm.V3xAnalyzer.parse_file_to_json(*args)
56
+
57
+ @staticmethod
58
+ def parse_string_to_json(*args):
59
+ return libqasm.V3xAnalyzer.parse_string_to_json(*args)
60
+
61
+ def analyze_file_to_json(self, *args):
62
+ return super().analyze_file_to_json(*args)
63
+
64
+ def analyze_string_to_json(self, *args):
65
+ return super().analyze_string_to_json(*args)