vtlengine 1.4.0rc2__py3-none-any.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.
Files changed (66) hide show
  1. vtlengine/API/_InternalApi.py +791 -0
  2. vtlengine/API/__init__.py +612 -0
  3. vtlengine/API/data/schema/external_routines_schema.json +34 -0
  4. vtlengine/API/data/schema/json_schema_2.1.json +116 -0
  5. vtlengine/API/data/schema/value_domain_schema.json +97 -0
  6. vtlengine/AST/ASTComment.py +57 -0
  7. vtlengine/AST/ASTConstructor.py +598 -0
  8. vtlengine/AST/ASTConstructorModules/Expr.py +1928 -0
  9. vtlengine/AST/ASTConstructorModules/ExprComponents.py +995 -0
  10. vtlengine/AST/ASTConstructorModules/Terminals.py +790 -0
  11. vtlengine/AST/ASTConstructorModules/__init__.py +50 -0
  12. vtlengine/AST/ASTDataExchange.py +10 -0
  13. vtlengine/AST/ASTEncoders.py +32 -0
  14. vtlengine/AST/ASTString.py +675 -0
  15. vtlengine/AST/ASTTemplate.py +558 -0
  16. vtlengine/AST/ASTVisitor.py +25 -0
  17. vtlengine/AST/DAG/__init__.py +479 -0
  18. vtlengine/AST/DAG/_words.py +10 -0
  19. vtlengine/AST/Grammar/Vtl.g4 +705 -0
  20. vtlengine/AST/Grammar/VtlTokens.g4 +409 -0
  21. vtlengine/AST/Grammar/__init__.py +0 -0
  22. vtlengine/AST/Grammar/lexer.py +2139 -0
  23. vtlengine/AST/Grammar/parser.py +16597 -0
  24. vtlengine/AST/Grammar/tokens.py +169 -0
  25. vtlengine/AST/VtlVisitor.py +824 -0
  26. vtlengine/AST/__init__.py +674 -0
  27. vtlengine/DataTypes/TimeHandling.py +562 -0
  28. vtlengine/DataTypes/__init__.py +863 -0
  29. vtlengine/DataTypes/_time_checking.py +135 -0
  30. vtlengine/Exceptions/__exception_file_generator.py +96 -0
  31. vtlengine/Exceptions/__init__.py +159 -0
  32. vtlengine/Exceptions/messages.py +1004 -0
  33. vtlengine/Interpreter/__init__.py +2048 -0
  34. vtlengine/Model/__init__.py +501 -0
  35. vtlengine/Operators/Aggregation.py +357 -0
  36. vtlengine/Operators/Analytic.py +455 -0
  37. vtlengine/Operators/Assignment.py +23 -0
  38. vtlengine/Operators/Boolean.py +106 -0
  39. vtlengine/Operators/CastOperator.py +451 -0
  40. vtlengine/Operators/Clause.py +366 -0
  41. vtlengine/Operators/Comparison.py +488 -0
  42. vtlengine/Operators/Conditional.py +495 -0
  43. vtlengine/Operators/General.py +191 -0
  44. vtlengine/Operators/HROperators.py +254 -0
  45. vtlengine/Operators/Join.py +447 -0
  46. vtlengine/Operators/Numeric.py +422 -0
  47. vtlengine/Operators/RoleSetter.py +77 -0
  48. vtlengine/Operators/Set.py +176 -0
  49. vtlengine/Operators/String.py +578 -0
  50. vtlengine/Operators/Time.py +1144 -0
  51. vtlengine/Operators/Validation.py +275 -0
  52. vtlengine/Operators/__init__.py +900 -0
  53. vtlengine/Utils/__Virtual_Assets.py +34 -0
  54. vtlengine/Utils/__init__.py +479 -0
  55. vtlengine/__extras_check.py +17 -0
  56. vtlengine/__init__.py +27 -0
  57. vtlengine/files/__init__.py +0 -0
  58. vtlengine/files/output/__init__.py +35 -0
  59. vtlengine/files/output/_time_period_representation.py +55 -0
  60. vtlengine/files/parser/__init__.py +240 -0
  61. vtlengine/files/parser/_rfc_dialect.py +22 -0
  62. vtlengine/py.typed +0 -0
  63. vtlengine-1.4.0rc2.dist-info/METADATA +89 -0
  64. vtlengine-1.4.0rc2.dist-info/RECORD +66 -0
  65. vtlengine-1.4.0rc2.dist-info/WHEEL +4 -0
  66. vtlengine-1.4.0rc2.dist-info/licenses/LICENSE.md +661 -0
@@ -0,0 +1,116 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "description": "VTL Metadata JSON serialization",
4
+ "$defs": {
5
+ "vtl-id": {
6
+ "type": "string",
7
+ "pattern": "^[a-zA-Z][a-zA-Z0-9_]*$|^'.*'$"
8
+ },
9
+ "set-type": {
10
+ "type": "array",
11
+ "uniqueItems": true,
12
+ "oneOf": [
13
+ { "items": { "oneOf": [ { "type": "string" }, { "type": "null" } ] } },
14
+ { "items": { "oneOf": [ { "type": "number" }, { "type": "null" } ] } }
15
+ ]
16
+ },
17
+ "identifiable": {
18
+ "type": "object",
19
+ "properties": {
20
+ "name": { "$ref": "#/$defs/vtl-id" },
21
+ "description": { "type": "string" }
22
+ },
23
+ "required": [ "name" ]
24
+ }
25
+ },
26
+ "type": "object",
27
+ "properties": {
28
+ "datasets": {
29
+ "type": "array",
30
+ "items": {
31
+ "allOf": [ { "$ref": "#/$defs/identifiable" } ],
32
+ "properties": {
33
+ "source": { "type": "string" },
34
+ "structure": { "$ref": "#/$defs/vtl-id" }
35
+ },
36
+ "required": [ "structure" ]
37
+ }
38
+ },
39
+ "structures": {
40
+ "type": "array",
41
+ "items": {
42
+ "allOf": [ { "$ref": "#/$defs/identifiable" } ],
43
+ "properties": {
44
+ "components": {
45
+ "type": "array",
46
+ "items": {
47
+ "allOf": [ { "$ref": "#/$defs/identifiable" } ],
48
+ "properties": {
49
+ "role": {
50
+ "type": "string",
51
+ "enum": [ "Identifier", "Measure", "Attribute", "Viral Attribute" ]
52
+ },
53
+ "subset": { "$ref": "#/$defs/vtl-id" },
54
+ "nullable": { "type": "boolean" },
55
+ "data_type": {
56
+ "type": "string",
57
+ "enum": [ "String", "Number", "Integer", "Boolean", "Time", "TimePeriod", "Date", "Duration" ]
58
+ }
59
+ },
60
+ "required": [ "role" ]
61
+ }
62
+ }
63
+ },
64
+ "required": [ "components" ]
65
+ }
66
+ },
67
+ "variables": {
68
+ "type": "array",
69
+ "items": {
70
+ "allOf": [ { "$ref": "#/$defs/identifiable" } ],
71
+ "properties": {
72
+ "domain": { "$ref": "#/$defs/vtl-id" }
73
+ },
74
+ "required": [ "domain" ]
75
+ }
76
+ },
77
+ "domains": {
78
+ "type": "array",
79
+ "items": {
80
+ "allOf": [ { "$ref": "#/$defs/identifiable" } ],
81
+ "unevaluatedProperties": false,
82
+ "oneOf": [
83
+ {
84
+ "properties": {
85
+ "externalRef": { "type": "string" }
86
+ },
87
+ "required": [ "externalRef" ]
88
+ }, {
89
+ "properties": {
90
+ "parent": { "$ref": "#/$defs/vtl-id" }
91
+ },
92
+ "required": [ "parent" ],
93
+ "oneOf": [{
94
+ "properties": {
95
+ "restriction": { "$ref": "#/$defs/set-type" }
96
+ },
97
+ "required": [ "restriction" ]
98
+ }, {
99
+ "properties": {
100
+ "enumerated": { "$ref": "#/$defs/set-type" }
101
+ },
102
+ "required": [ "enumerated" ]
103
+ }, {
104
+ "properties": {
105
+ "described": { "type": "string" }
106
+ },
107
+ "required": [ "described" ]
108
+ }
109
+ ]
110
+ }
111
+ ]
112
+ }
113
+ }
114
+ }
115
+ }
116
+
@@ -0,0 +1,97 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "definitions": {
4
+ "ValueDomain": {
5
+ "type": "object",
6
+ "properties": {
7
+ "name": {
8
+ "type": "string",
9
+ "description": "Name identifier for the Value Domain"
10
+ },
11
+ "setlist": {
12
+ "type": "array",
13
+ "minItems": 1,
14
+ "uniqueItems": true,
15
+ "description": "List of unique values of the Value Domain"
16
+ },
17
+ "type": {
18
+ "type": "string",
19
+ "enum": ["Integer", "Number", "String", "Boolean", "Date", "Time_Period", "Time", "Duration"],
20
+ "description": "Data type of the Value Domain"
21
+ }
22
+ },
23
+ "required": ["name", "setlist", "type"],
24
+ "additionalProperties": false,
25
+ "allOf": [
26
+ {
27
+ "if": {
28
+ "properties": {
29
+ "type": {"const": "Integer"}
30
+ }
31
+ },
32
+ "then": {
33
+ "properties": {
34
+ "setlist": {
35
+ "items": {"type": "integer"}
36
+ }
37
+ }
38
+ }
39
+ },
40
+ {
41
+ "if": {
42
+ "properties": {
43
+ "type": {"const": "Number"}
44
+ }
45
+ },
46
+ "then": {
47
+ "properties": {
48
+ "setlist": {
49
+ "items": {"type": "number"}
50
+ }
51
+ }
52
+ }
53
+ },
54
+ {
55
+ "if": {
56
+ "properties": {
57
+ "type": {"const": "Boolean"}
58
+ }
59
+ },
60
+ "then": {
61
+ "properties": {
62
+ "setlist": {
63
+ "items": {"type": "boolean"}
64
+ }
65
+ }
66
+ }
67
+ },
68
+ {
69
+ "if": {
70
+ "properties": {
71
+ "type": {"enum": ["String", "Date", "Time_Period", "Time", "Duration"]}
72
+ }
73
+ },
74
+ "then": {
75
+ "properties": {
76
+ "setlist": {
77
+ "items": {"type": "string"}
78
+ }
79
+ }
80
+ }
81
+ }
82
+ ]
83
+ }
84
+ },
85
+ "oneOf": [
86
+ {
87
+ "$ref": "#/definitions/ValueDomain"
88
+ },
89
+ {
90
+ "type": "array",
91
+ "items": {
92
+ "$ref": "#/definitions/ValueDomain"
93
+ },
94
+ "minItems": 1
95
+ }
96
+ ]
97
+ }
@@ -0,0 +1,57 @@
1
+ from antlr4 import CommonTokenStream, InputStream
2
+ from antlr4.Token import CommonToken
3
+
4
+ from vtlengine.API import create_ast
5
+ from vtlengine.AST import Comment, Start
6
+ from vtlengine.AST.ASTConstructorModules import extract_token_info
7
+ from vtlengine.AST.Grammar.lexer import Lexer
8
+
9
+
10
+ def generate_ast_comment(token: CommonToken) -> Comment:
11
+ """
12
+ Parses a token belonging to a comment and returns a Comment AST object.
13
+
14
+ Args:
15
+ token (str): The comment string to parse.
16
+
17
+ Returns:
18
+ Comment: A Comment AST object.
19
+ """
20
+ token_info = extract_token_info(token)
21
+ text = token.text
22
+ if token.type == Lexer.SL_COMMENT:
23
+ text = token.text[:-1] # Remove the trailing newline character
24
+ return Comment(value=text, **token_info)
25
+
26
+
27
+ def create_ast_with_comments(text: str) -> Start:
28
+ """
29
+ Parses a VTL script and returns an AST with comments.
30
+
31
+ Args:
32
+ text (str): The VTL script to parse.
33
+
34
+ Returns:
35
+ AST: The generated AST with comments.
36
+ """
37
+ # Call the create_ast function to generate the AST from channel 0
38
+ ast = create_ast(text)
39
+
40
+ text = text if text.endswith("\n") else text + "\n"
41
+ # Reading the script on channel 2 to get the comments
42
+ lexer_ = Lexer(InputStream(text))
43
+ stream = CommonTokenStream(lexer_, channel=2)
44
+
45
+ # Fill the stream with tokens on the buffer
46
+ stream.fill()
47
+
48
+ # Extract comments from the stream
49
+ comments = [generate_ast_comment(token) for token in stream.tokens if token.channel == 2]
50
+
51
+ # Add comments to the AST
52
+ ast.children.extend(comments)
53
+
54
+ # Sort the ast children based on their start line and column
55
+ ast.children.sort(key=lambda x: (x.line_start, x.column_start))
56
+
57
+ return ast