pydpm_xl 0.1.10__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.
- py_dpm/AST/ASTConstructor.py +503 -0
- py_dpm/AST/ASTObjects.py +827 -0
- py_dpm/AST/ASTTemplate.py +101 -0
- py_dpm/AST/ASTVisitor.py +13 -0
- py_dpm/AST/MLGeneration.py +588 -0
- py_dpm/AST/ModuleAnalyzer.py +79 -0
- py_dpm/AST/ModuleDependencies.py +203 -0
- py_dpm/AST/WhereClauseChecker.py +12 -0
- py_dpm/AST/__init__.py +0 -0
- py_dpm/AST/check_operands.py +302 -0
- py_dpm/DataTypes/ScalarTypes.py +324 -0
- py_dpm/DataTypes/TimeClasses.py +370 -0
- py_dpm/DataTypes/TypePromotion.py +195 -0
- py_dpm/DataTypes/__init__.py +0 -0
- py_dpm/Exceptions/__init__.py +0 -0
- py_dpm/Exceptions/exceptions.py +84 -0
- py_dpm/Exceptions/messages.py +114 -0
- py_dpm/OperationScopes/OperationScopeService.py +247 -0
- py_dpm/OperationScopes/__init__.py +0 -0
- py_dpm/Operators/AggregateOperators.py +138 -0
- py_dpm/Operators/BooleanOperators.py +30 -0
- py_dpm/Operators/ClauseOperators.py +159 -0
- py_dpm/Operators/ComparisonOperators.py +69 -0
- py_dpm/Operators/ConditionalOperators.py +362 -0
- py_dpm/Operators/NumericOperators.py +101 -0
- py_dpm/Operators/Operator.py +388 -0
- py_dpm/Operators/StringOperators.py +27 -0
- py_dpm/Operators/TimeOperators.py +53 -0
- py_dpm/Operators/__init__.py +0 -0
- py_dpm/Utils/ValidationsGenerationUtils.py +429 -0
- py_dpm/Utils/__init__.py +0 -0
- py_dpm/Utils/operands_mapping.py +73 -0
- py_dpm/Utils/operator_mapping.py +89 -0
- py_dpm/Utils/tokens.py +172 -0
- py_dpm/Utils/utils.py +2 -0
- py_dpm/ValidationsGeneration/PropertiesConstraintsProcessor.py +190 -0
- py_dpm/ValidationsGeneration/Utils.py +364 -0
- py_dpm/ValidationsGeneration/VariantsProcessor.py +265 -0
- py_dpm/ValidationsGeneration/__init__.py +0 -0
- py_dpm/ValidationsGeneration/auxiliary_functions.py +98 -0
- py_dpm/__init__.py +61 -0
- py_dpm/api/__init__.py +140 -0
- py_dpm/api/ast_generator.py +438 -0
- py_dpm/api/complete_ast.py +241 -0
- py_dpm/api/data_dictionary_validation.py +577 -0
- py_dpm/api/migration.py +77 -0
- py_dpm/api/semantic.py +224 -0
- py_dpm/api/syntax.py +182 -0
- py_dpm/client.py +106 -0
- py_dpm/data_handlers.py +99 -0
- py_dpm/db_utils.py +117 -0
- py_dpm/grammar/__init__.py +0 -0
- py_dpm/grammar/dist/__init__.py +0 -0
- py_dpm/grammar/dist/dpm_xlLexer.interp +428 -0
- py_dpm/grammar/dist/dpm_xlLexer.py +804 -0
- py_dpm/grammar/dist/dpm_xlLexer.tokens +106 -0
- py_dpm/grammar/dist/dpm_xlParser.interp +249 -0
- py_dpm/grammar/dist/dpm_xlParser.py +5224 -0
- py_dpm/grammar/dist/dpm_xlParser.tokens +106 -0
- py_dpm/grammar/dist/dpm_xlParserListener.py +742 -0
- py_dpm/grammar/dist/dpm_xlParserVisitor.py +419 -0
- py_dpm/grammar/dist/listeners.py +10 -0
- py_dpm/grammar/dpm_xlLexer.g4 +435 -0
- py_dpm/grammar/dpm_xlParser.g4 +260 -0
- py_dpm/migration.py +282 -0
- py_dpm/models.py +2139 -0
- py_dpm/semantics/DAG/DAGAnalyzer.py +158 -0
- py_dpm/semantics/DAG/__init__.py +0 -0
- py_dpm/semantics/SemanticAnalyzer.py +320 -0
- py_dpm/semantics/Symbols.py +223 -0
- py_dpm/semantics/__init__.py +0 -0
- py_dpm/utils/__init__.py +0 -0
- py_dpm/utils/ast_serialization.py +481 -0
- py_dpm/views/data_types.sql +12 -0
- py_dpm/views/datapoints.sql +65 -0
- py_dpm/views/hierarchy_operand_reference.sql +11 -0
- py_dpm/views/hierarchy_preconditions.sql +13 -0
- py_dpm/views/hierarchy_variables.sql +26 -0
- py_dpm/views/hierarchy_variables_context.sql +14 -0
- py_dpm/views/key_components.sql +18 -0
- py_dpm/views/module_from_table.sql +11 -0
- py_dpm/views/open_keys.sql +13 -0
- py_dpm/views/operation_info.sql +27 -0
- py_dpm/views/operation_list.sql +18 -0
- py_dpm/views/operations_versions_from_module_version.sql +30 -0
- py_dpm/views/precondition_info.sql +17 -0
- py_dpm/views/report_type_operand_reference_info.sql +18 -0
- py_dpm/views/subcategory_info.sql +17 -0
- py_dpm/views/table_info.sql +19 -0
- pydpm_xl-0.1.10.dist-info/LICENSE +674 -0
- pydpm_xl-0.1.10.dist-info/METADATA +50 -0
- pydpm_xl-0.1.10.dist-info/RECORD +94 -0
- pydpm_xl-0.1.10.dist-info/WHEEL +4 -0
- pydpm_xl-0.1.10.dist-info/entry_points.txt +3 -0
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
"""
|
|
2
|
+
AST.ASTConstructor.py
|
|
3
|
+
=====================
|
|
4
|
+
|
|
5
|
+
Description
|
|
6
|
+
-----------
|
|
7
|
+
Generate an AST based on object of AST.ASTObjects.
|
|
8
|
+
"""
|
|
9
|
+
import re
|
|
10
|
+
|
|
11
|
+
from antlr4.tree.Tree import TerminalNodeImpl
|
|
12
|
+
|
|
13
|
+
from py_dpm.AST.ASTObjects import *
|
|
14
|
+
from py_dpm.Exceptions import exceptions
|
|
15
|
+
from py_dpm.Exceptions.exceptions import SemanticError
|
|
16
|
+
from py_dpm.Utils.tokens import TABLE_GROUP_PREFIX
|
|
17
|
+
from py_dpm.grammar.dist.dpm_xlParser import dpm_xlParser
|
|
18
|
+
from py_dpm.grammar.dist.dpm_xlParserVisitor import dpm_xlParserVisitor
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class ASTVisitor(dpm_xlParserVisitor):
|
|
22
|
+
"""
|
|
23
|
+
Class to walk to generate an AST which nodes are defined at AST.ASTObjects
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def visitStart(self, ctx: dpm_xlParser.StartContext):
|
|
27
|
+
ctx_list = list(ctx.getChildren())
|
|
28
|
+
|
|
29
|
+
expression_nodes = []
|
|
30
|
+
expressions = [expr for expr in ctx_list if isinstance(expr, dpm_xlParser.StatementContext)]
|
|
31
|
+
if len(ctx_list) > 3 and isinstance(ctx_list[2], dpm_xlParser.StatementsContext):
|
|
32
|
+
statements_list = list(ctx_list[2].getChildren())
|
|
33
|
+
expressions += [statement for statement in statements_list if
|
|
34
|
+
isinstance(statement, dpm_xlParser.StatementContext)]
|
|
35
|
+
|
|
36
|
+
if len(expressions) > 0:
|
|
37
|
+
for expression in expressions:
|
|
38
|
+
expression_nodes.append(self.visit(expression))
|
|
39
|
+
|
|
40
|
+
start = Start(children=expression_nodes)
|
|
41
|
+
return start
|
|
42
|
+
|
|
43
|
+
def visitExprWithSelection(self, ctx: dpm_xlParser.ExprWithSelectionContext):
|
|
44
|
+
ctx_list = list(ctx.getChildren())
|
|
45
|
+
partial_selection = self.visit(ctx_list[1])
|
|
46
|
+
expression = self.visit(ctx_list[3])
|
|
47
|
+
return WithExpression(partial_selection=partial_selection, expression=expression)
|
|
48
|
+
|
|
49
|
+
def visitPartialSelect(self, ctx: dpm_xlParser.PartialSelectContext):
|
|
50
|
+
return self.visit(ctx.getChild(1))
|
|
51
|
+
|
|
52
|
+
def visitPersistentAssignmentExpression(self, ctx: dpm_xlParser.PersistentAssignmentExpressionContext):
|
|
53
|
+
|
|
54
|
+
ctx_list = list(ctx.getChildren())
|
|
55
|
+
left = self.visit(ctx_list[0])
|
|
56
|
+
op = ctx_list[1].symbol.text
|
|
57
|
+
right = self.visit(ctx_list[2])
|
|
58
|
+
return PersistentAssignment(left=left, op=op, right=right)
|
|
59
|
+
|
|
60
|
+
def visitTemporaryAssignmentExpression(self, ctx: dpm_xlParser.TemporaryAssignmentExpressionContext):
|
|
61
|
+
ctx_list = list(ctx.getChildren())
|
|
62
|
+
left = self.visit(ctx_list[0])
|
|
63
|
+
op = ctx_list[1].symbol.text
|
|
64
|
+
right = self.visit(ctx_list[2])
|
|
65
|
+
return TemporaryAssignment(left=left, op=op, right=right)
|
|
66
|
+
|
|
67
|
+
def visitExpr(self, ctx: dpm_xlParser.ExpressionContext):
|
|
68
|
+
child = ctx.getChild(0)
|
|
69
|
+
if isinstance(child, dpm_xlParser.ParExprContext):
|
|
70
|
+
return self.visitParExpr(child)
|
|
71
|
+
elif isinstance(child, dpm_xlParser.FuncExprContext):
|
|
72
|
+
return self.visitFuncExpr(child)
|
|
73
|
+
elif isinstance(child, dpm_xlParser.ClauseExprContext):
|
|
74
|
+
return self.visitClauseExpr(child)
|
|
75
|
+
elif isinstance(child, dpm_xlParser.UnaryExprContext):
|
|
76
|
+
return self.visitUnaryExpr(child)
|
|
77
|
+
elif isinstance(child, dpm_xlParser.NotExprContext):
|
|
78
|
+
return self.visitNotExpr(child)
|
|
79
|
+
elif isinstance(child, dpm_xlParser.NumericExprContext):
|
|
80
|
+
return self.visitNumericExpr(child)
|
|
81
|
+
elif isinstance(child, dpm_xlParser.ConcatExprContext):
|
|
82
|
+
return self.visitConcatExpr(child)
|
|
83
|
+
elif isinstance(child, dpm_xlParser.CompExprContext):
|
|
84
|
+
return self.visitCompExpr(child)
|
|
85
|
+
elif isinstance(child, dpm_xlParser.InExprContext):
|
|
86
|
+
return self.visitInExpr(child)
|
|
87
|
+
elif isinstance(child, dpm_xlParser.PropertyReferenceExprContext):
|
|
88
|
+
return self.visitPropertyReferenceExpr(child)
|
|
89
|
+
elif isinstance(child, dpm_xlParser.ItemReferenceExprContext):
|
|
90
|
+
return self.visitItemReferenceExpr(child)
|
|
91
|
+
elif isinstance(child, dpm_xlParser.BoolExprContext):
|
|
92
|
+
return self.visitBoolExpr(child)
|
|
93
|
+
elif isinstance(child, dpm_xlParser.IfExprContext):
|
|
94
|
+
return self.visitIfExpr(child)
|
|
95
|
+
elif isinstance(child, dpm_xlParser.KeyNamesExprContext):
|
|
96
|
+
return self.visitKeyNamesExpr(child)
|
|
97
|
+
elif isinstance(child, dpm_xlParser.LiteralExprContext):
|
|
98
|
+
return self.visitLiteralExpr(child)
|
|
99
|
+
elif isinstance(child, dpm_xlParser.SelectExprContext):
|
|
100
|
+
return self.visitSelectExpr(child)
|
|
101
|
+
|
|
102
|
+
def visitParExpr(self, ctx: dpm_xlParser.ParExprContext):
|
|
103
|
+
expression = self.visit(ctx.getChild(1))
|
|
104
|
+
return ParExpr(expression=expression)
|
|
105
|
+
|
|
106
|
+
def visitUnaryExpr(self, ctx: dpm_xlParser.UnaryExprContext):
|
|
107
|
+
ctx_list = list(ctx.getChildren())
|
|
108
|
+
op = ctx_list[0].symbol.text
|
|
109
|
+
operand = self.visit(ctx_list[1])
|
|
110
|
+
return UnaryOp(op=op, operand=operand)
|
|
111
|
+
|
|
112
|
+
def visitNotExpr(self, ctx: dpm_xlParser.NotExprContext):
|
|
113
|
+
ctx_list = list(ctx.getChildren())
|
|
114
|
+
op = ctx_list[0].symbol.text
|
|
115
|
+
operand = self.visit(ctx_list[2])
|
|
116
|
+
return UnaryOp(op=op, operand=operand)
|
|
117
|
+
|
|
118
|
+
def visitCommonAggrOp(self, ctx: dpm_xlParser.CommonAggrOpContext):
|
|
119
|
+
ctx_list = list(ctx.getChildren())
|
|
120
|
+
op = ctx_list[0].symbol.text
|
|
121
|
+
operand = None
|
|
122
|
+
grouping_clause = None
|
|
123
|
+
for child in ctx_list:
|
|
124
|
+
if isinstance(child, dpm_xlParser.GroupingClauseContext):
|
|
125
|
+
grouping_clause = self.visitGroupingClause(child)
|
|
126
|
+
elif not isinstance(child, TerminalNodeImpl):
|
|
127
|
+
operand = self.visit(child)
|
|
128
|
+
|
|
129
|
+
return AggregationOp(op=op, operand=operand, grouping_clause=grouping_clause)
|
|
130
|
+
|
|
131
|
+
def visitGroupingClause(self, ctx: dpm_xlParser.GroupingClauseContext):
|
|
132
|
+
ctx_list = list(ctx.getChildren())
|
|
133
|
+
components = [self.visit(child) for child in ctx_list if isinstance(child, dpm_xlParser.KeyNamesContext)]
|
|
134
|
+
return GroupingClause(components=components)
|
|
135
|
+
|
|
136
|
+
def visitKeyNames(self, ctx: dpm_xlParser.KeyNamesContext):
|
|
137
|
+
return ctx.getChild(0).symbol.text
|
|
138
|
+
|
|
139
|
+
def visitPropertyCode(self, ctx: dpm_xlParser.PropertyCodeContext):
|
|
140
|
+
return ctx.getChild(0).symbol.text
|
|
141
|
+
|
|
142
|
+
def visitUnaryNumericFunctions(self, ctx: dpm_xlParser.UnaryNumericFunctionsContext):
|
|
143
|
+
ctx_list = list(ctx.getChildren())
|
|
144
|
+
op = ctx_list[0].symbol.text
|
|
145
|
+
operand = self.visit(ctx_list[2])
|
|
146
|
+
return UnaryOp(op=op, operand=operand)
|
|
147
|
+
|
|
148
|
+
def visitBinaryNumericFunctions(self, ctx: dpm_xlParser.BinaryNumericFunctionsContext):
|
|
149
|
+
ctx_list = list(ctx.getChildren())
|
|
150
|
+
op = ctx_list[0].symbol.text
|
|
151
|
+
left = self.visit(ctx_list[2])
|
|
152
|
+
right = self.visit(ctx_list[4])
|
|
153
|
+
return BinOp(op=op, left=left, right=right)
|
|
154
|
+
|
|
155
|
+
def visitComplexNumericFunctions(self, ctx: dpm_xlParser.ComplexNumericFunctionsContext):
|
|
156
|
+
ctx_list = list(ctx.getChildren())
|
|
157
|
+
op = ctx_list[0].symbol.text
|
|
158
|
+
operands = []
|
|
159
|
+
for child in ctx_list:
|
|
160
|
+
if not isinstance(child, TerminalNodeImpl):
|
|
161
|
+
operands.append(self.visit(child))
|
|
162
|
+
return ComplexNumericOp(op=op, operands=operands)
|
|
163
|
+
|
|
164
|
+
def visitMatchExpr(self, ctx: dpm_xlParser.MatchExprContext):
|
|
165
|
+
ctx_list = list(ctx.getChildren())
|
|
166
|
+
op = ctx_list[0].symbol.text
|
|
167
|
+
left = self.visit(ctx_list[2])
|
|
168
|
+
pattern = self.visitLiteral(ctx_list[4])
|
|
169
|
+
try:
|
|
170
|
+
re.compile(pattern.value)
|
|
171
|
+
except re.error as error:
|
|
172
|
+
raise exceptions.SyntaxError(code="0-1", message=error.msg)
|
|
173
|
+
return BinOp(left=left, op=op, right=pattern)
|
|
174
|
+
|
|
175
|
+
def visitIsnullExpr(self, ctx: dpm_xlParser.IsnullExprContext):
|
|
176
|
+
ctx_list = list(ctx.getChildren())
|
|
177
|
+
op = ctx_list[0].symbol.text
|
|
178
|
+
operand = self.visit(ctx_list[2])
|
|
179
|
+
return UnaryOp(op=op, operand=operand)
|
|
180
|
+
|
|
181
|
+
def visitFilterOperators(self, ctx: dpm_xlParser.FilterOperatorsContext):
|
|
182
|
+
ctx_list = list(ctx.getChildren())
|
|
183
|
+
selection = self.visit(ctx_list[2])
|
|
184
|
+
condition = self.visit(ctx_list[4])
|
|
185
|
+
return FilterOp(selection=selection, condition=condition)
|
|
186
|
+
|
|
187
|
+
def visitNvlFunction(self, ctx: dpm_xlParser.NvlFunctionContext):
|
|
188
|
+
ctx_list = list(ctx.getChildren())
|
|
189
|
+
op = ctx_list[0].symbol.text
|
|
190
|
+
left = self.visit(ctx_list[2])
|
|
191
|
+
right = self.visit(ctx_list[4])
|
|
192
|
+
return BinOp(op=op, left=left, right=right)
|
|
193
|
+
|
|
194
|
+
def visitTimeShiftFunction(self, ctx: dpm_xlParser.TimeShiftFunctionContext):
|
|
195
|
+
ctx_list = list(ctx.getChildren())
|
|
196
|
+
operand = self.visit(ctx_list[2])
|
|
197
|
+
component = None
|
|
198
|
+
period_indicator = ctx_list[4].symbol.text
|
|
199
|
+
shift_number = ctx_list[6].symbol.text
|
|
200
|
+
if len(ctx_list) > 8:
|
|
201
|
+
component = self.visit(ctx_list[8])
|
|
202
|
+
return TimeShiftOp(operand=operand, component=component, period_indicator=period_indicator,
|
|
203
|
+
shift_number=shift_number)
|
|
204
|
+
|
|
205
|
+
def visitUnaryStringFunction(self, ctx: dpm_xlParser.UnaryStringFunctionContext):
|
|
206
|
+
ctx_list = list(ctx.getChildren())
|
|
207
|
+
op = ctx_list[0].symbol.text
|
|
208
|
+
operand = self.visit(ctx_list[2])
|
|
209
|
+
return UnaryOp(op=op, operand=operand)
|
|
210
|
+
|
|
211
|
+
def visitClauseExpr(self, ctx: dpm_xlParser.ClauseExprContext):
|
|
212
|
+
ctx_list = list(ctx.getChildren())
|
|
213
|
+
operand = self.visit(ctx_list[0])
|
|
214
|
+
if isinstance(ctx_list[2], dpm_xlParser.WhereExprContext):
|
|
215
|
+
condition = self.visitWhereExpr(ctx_list[2])
|
|
216
|
+
return WhereClauseOp(operand=operand, condition=condition)
|
|
217
|
+
elif isinstance(ctx_list[2], dpm_xlParser.GetExprContext):
|
|
218
|
+
component = self.visitGetExpr(ctx_list[2])
|
|
219
|
+
return GetOp(operand=operand, component=component)
|
|
220
|
+
elif isinstance(ctx_list[2], dpm_xlParser.RenameExprContext):
|
|
221
|
+
rename_nodes = self.visitRenameExpr(ctx_list[2])
|
|
222
|
+
return RenameOp(operand=operand, rename_nodes=rename_nodes)
|
|
223
|
+
|
|
224
|
+
def visitWhereExpr(self, ctx: dpm_xlParser.WhereExprContext):
|
|
225
|
+
return self.visit(ctx.getChild(1))
|
|
226
|
+
|
|
227
|
+
def visitGetExpr(self, ctx: dpm_xlParser.GetExprContext):
|
|
228
|
+
return self.visit(ctx.getChild(1))
|
|
229
|
+
|
|
230
|
+
def visitRenameExpr(self, ctx: dpm_xlParser.RenameExprContext):
|
|
231
|
+
ctx_list = list(ctx.getChildren())
|
|
232
|
+
rename_nodes = []
|
|
233
|
+
for child in ctx_list:
|
|
234
|
+
if isinstance(child, dpm_xlParser.RenameClauseContext):
|
|
235
|
+
rename_nodes.append(self.visit(child))
|
|
236
|
+
return rename_nodes
|
|
237
|
+
|
|
238
|
+
def visitRenameClause(self, ctx: dpm_xlParser.RenameClauseContext):
|
|
239
|
+
ctx_list = list(ctx.getChildren())
|
|
240
|
+
old_name = self.visit(ctx_list[0])
|
|
241
|
+
new_name = self.visit(ctx_list[2])
|
|
242
|
+
return RenameNode(old_name=old_name, new_name=new_name)
|
|
243
|
+
|
|
244
|
+
def create_bin_op(self, ctx: dpm_xlParser.ExpressionContext):
|
|
245
|
+
ctx_list = list(ctx.getChildren())
|
|
246
|
+
|
|
247
|
+
left = self.visit(ctx_list[0])
|
|
248
|
+
if isinstance(ctx_list[1], dpm_xlParser.ComparisonOperatorsContext):
|
|
249
|
+
op = self.visitComparisonOperators(ctx_list[1])
|
|
250
|
+
else:
|
|
251
|
+
op = ctx_list[1].symbol.text
|
|
252
|
+
right = self.visit(ctx_list[2])
|
|
253
|
+
|
|
254
|
+
return BinOp(left=left, op=op, right=right)
|
|
255
|
+
|
|
256
|
+
def visitSelect(self, ctx: dpm_xlParser.SelectContext):
|
|
257
|
+
return self.visit(ctx.getChild(1))
|
|
258
|
+
|
|
259
|
+
def visitComparisonOperators(self, ctx: dpm_xlParser.ComparisonOperatorsContext):
|
|
260
|
+
return ctx.getChild(0).symbol.text
|
|
261
|
+
|
|
262
|
+
def visitNumericExpr(self, ctx: dpm_xlParser.NumericExprContext):
|
|
263
|
+
return self.create_bin_op(ctx)
|
|
264
|
+
|
|
265
|
+
def visitConcatExpr(self, ctx: dpm_xlParser.ConcatExprContext):
|
|
266
|
+
return self.create_bin_op(ctx)
|
|
267
|
+
|
|
268
|
+
def visitCompExpr(self, ctx: dpm_xlParser.CompExprContext):
|
|
269
|
+
return self.create_bin_op(ctx)
|
|
270
|
+
|
|
271
|
+
def visitIfExpr(self, ctx: dpm_xlParser.IfExprContext):
|
|
272
|
+
ctx_list = list(ctx.getChildren())
|
|
273
|
+
condition = self.visit(ctx_list[1])
|
|
274
|
+
then_expr = self.visit(ctx_list[3])
|
|
275
|
+
else_expr = self.visit(ctx_list[5]) if len(ctx_list) > 5 else None
|
|
276
|
+
return CondExpr(condition=condition, then_expr=then_expr, else_expr=else_expr)
|
|
277
|
+
|
|
278
|
+
def visitInExpr(self, ctx: dpm_xlParser.InExprContext):
|
|
279
|
+
ctx_list = list(ctx.getChildren())
|
|
280
|
+
left = self.visit(ctx_list[0])
|
|
281
|
+
op = ctx_list[1].symbol.text
|
|
282
|
+
right = self.visit(ctx_list[2])
|
|
283
|
+
return BinOp(left=left, op=op, right=right)
|
|
284
|
+
|
|
285
|
+
def visitSetOperand(self, ctx: dpm_xlParser.SetOperandContext):
|
|
286
|
+
return self.visit(ctx.getChild(1))
|
|
287
|
+
|
|
288
|
+
def visitSetElements(self, ctx: dpm_xlParser.SetElementsContext):
|
|
289
|
+
ctx_list = list(ctx.getChildren())
|
|
290
|
+
set_elements = []
|
|
291
|
+
for child in ctx_list:
|
|
292
|
+
if not isinstance(child, TerminalNodeImpl):
|
|
293
|
+
set_elements.append(self.visit(child))
|
|
294
|
+
return Set(children=set_elements)
|
|
295
|
+
|
|
296
|
+
def visitItemReference(self, ctx: dpm_xlParser.ItemReferenceContext):
|
|
297
|
+
item = self.visit(ctx.getChild(1))
|
|
298
|
+
return Scalar(item=item, scalar_type='Item')
|
|
299
|
+
|
|
300
|
+
def visitItemSignature(self, ctx: dpm_xlParser.ItemSignatureContext):
|
|
301
|
+
ctx_list = list(ctx.getChildren())
|
|
302
|
+
return ''.join([child.symbol.text for child in ctx_list])
|
|
303
|
+
|
|
304
|
+
def visitBoolExpr(self, ctx: dpm_xlParser.BoolExprContext):
|
|
305
|
+
return self.create_bin_op(ctx)
|
|
306
|
+
|
|
307
|
+
def visitPropertyReferenceExpr(self, ctx: dpm_xlParser.PropertyReferenceExprContext):
|
|
308
|
+
return self.visit(ctx.getChild(0))
|
|
309
|
+
|
|
310
|
+
def visitPropertyReference(self, ctx: dpm_xlParser.PropertyReferenceContext):
|
|
311
|
+
code = self.visit(ctx.getChild(1))
|
|
312
|
+
return PropertyReference(code=code)
|
|
313
|
+
|
|
314
|
+
def visitItemReferenceExpr(self, ctx: dpm_xlParser.ItemReferenceExprContext):
|
|
315
|
+
return self.visitChildren(ctx)
|
|
316
|
+
|
|
317
|
+
def visitLiteral(self, ctx: dpm_xlParser.LiteralContext):
|
|
318
|
+
|
|
319
|
+
if not hasattr(ctx, 'children') and ctx.symbol.text == 'null':
|
|
320
|
+
return Constant(type_='Null', value=None)
|
|
321
|
+
|
|
322
|
+
token = ctx.getChild(0).symbol
|
|
323
|
+
value = token.text
|
|
324
|
+
type_ = token.type
|
|
325
|
+
|
|
326
|
+
if type_ == dpm_xlParser.INTEGER_LITERAL:
|
|
327
|
+
return Constant(type_='Integer', value=int(value))
|
|
328
|
+
elif type_ == dpm_xlParser.DECIMAL_LITERAL:
|
|
329
|
+
return Constant(type_='Number', value=float(value))
|
|
330
|
+
elif type_ == dpm_xlParser.PERCENT_LITERAL:
|
|
331
|
+
return Constant(type_='Number', value=float(value.replace('%', '')) / 100)
|
|
332
|
+
elif type_ == dpm_xlParser.STRING_LITERAL:
|
|
333
|
+
value = value[1:-1]
|
|
334
|
+
if value == 'null':
|
|
335
|
+
raise SemanticError("0-3")
|
|
336
|
+
return Constant(type_='String', value=value)
|
|
337
|
+
elif type_ == dpm_xlParser.BOOLEAN_LITERAL:
|
|
338
|
+
if value == 'true':
|
|
339
|
+
constant_value = True
|
|
340
|
+
elif value == 'false':
|
|
341
|
+
constant_value = False
|
|
342
|
+
else:
|
|
343
|
+
raise NotImplementedError
|
|
344
|
+
return Constant(type_='Boolean', value=constant_value)
|
|
345
|
+
elif type_ == dpm_xlParser.DATE_LITERAL:
|
|
346
|
+
return Constant(type_='Date', value=value.replace('#', ''))
|
|
347
|
+
elif type_ == dpm_xlParser.TIME_PERIOD_LITERAL:
|
|
348
|
+
return Constant(type_='TimePeriod', value=value.replace('#', ''))
|
|
349
|
+
elif type_ == dpm_xlParser.TIME_INTERVAL_LITERAL:
|
|
350
|
+
return Constant(type_='TimeInterval', value=value.replace('#', ''))
|
|
351
|
+
elif type_ == dpm_xlParser.EMPTY_LITERAL:
|
|
352
|
+
value = value[1:-1]
|
|
353
|
+
return Constant(type_='String', value=value)
|
|
354
|
+
elif type_ == dpm_xlParser.NULL_LITERAL:
|
|
355
|
+
return Constant(type_='Null', value=None)
|
|
356
|
+
else:
|
|
357
|
+
raise NotImplementedError
|
|
358
|
+
|
|
359
|
+
def visitVarRef(self, ctx: dpm_xlParser.VarRefContext):
|
|
360
|
+
child = ctx.getChild(0)
|
|
361
|
+
variable = child.symbol.text[1:]
|
|
362
|
+
return VarRef(variable=variable)
|
|
363
|
+
|
|
364
|
+
def visitCellRef(self, ctx: dpm_xlParser.CellRefContext):
|
|
365
|
+
ctx_list = list(ctx.getChildren())
|
|
366
|
+
|
|
367
|
+
child = ctx_list[0]
|
|
368
|
+
if isinstance(child, dpm_xlParser.TableRefContext):
|
|
369
|
+
return self.visitTableRef(child)
|
|
370
|
+
elif isinstance(child, dpm_xlParser.CompRefContext):
|
|
371
|
+
return self.visitCompRef(child)
|
|
372
|
+
|
|
373
|
+
def visitPreconditionElem(self, ctx: dpm_xlParser.PreconditionElemContext):
|
|
374
|
+
child = ctx.getChild(0)
|
|
375
|
+
precondition = child.symbol.text[2:]
|
|
376
|
+
return PreconditionItem(variable_id=precondition, variable_code=precondition) # This is not the variable_id but we keep the name for later
|
|
377
|
+
|
|
378
|
+
def visitOperationRef(self, ctx: dpm_xlParser.OperationRefContext):
|
|
379
|
+
child = ctx.getChild(0)
|
|
380
|
+
operation_code = child.symbol.text[1:]
|
|
381
|
+
return OperationRef(operation_code=operation_code)
|
|
382
|
+
|
|
383
|
+
def create_var_id(self, ctx_list: list, table=None, is_table_group=False):
|
|
384
|
+
rows = None
|
|
385
|
+
cols = None
|
|
386
|
+
sheets = None
|
|
387
|
+
interval = None
|
|
388
|
+
default = None
|
|
389
|
+
for child in ctx_list:
|
|
390
|
+
if isinstance(child, dpm_xlParser.RowArgContext):
|
|
391
|
+
if rows is not None:
|
|
392
|
+
raise exceptions.SemanticError("0-2", argument='rows')
|
|
393
|
+
rows = self.visitRowArg(child)
|
|
394
|
+
elif isinstance(child, dpm_xlParser.ColArgContext):
|
|
395
|
+
if cols is not None:
|
|
396
|
+
raise exceptions.SemanticError("0-2", argument='columns')
|
|
397
|
+
cols = self.visitColArg(child)
|
|
398
|
+
elif isinstance(child, dpm_xlParser.SheetArgContext):
|
|
399
|
+
if sheets is not None:
|
|
400
|
+
raise exceptions.SemanticError("0-2", argument='sheets')
|
|
401
|
+
sheets = self.visitSheetArg(child)
|
|
402
|
+
elif isinstance(child, dpm_xlParser.IntervalArgContext):
|
|
403
|
+
if interval is not None:
|
|
404
|
+
raise exceptions.SemanticError("0-2", argument='interval')
|
|
405
|
+
interval = self.visitIntervalArg(child)
|
|
406
|
+
elif isinstance(child, dpm_xlParser.DefaultArgContext):
|
|
407
|
+
if default is not None:
|
|
408
|
+
raise exceptions.SemanticError("0-2", argument='default')
|
|
409
|
+
default = self.visitDefaultArg(child)
|
|
410
|
+
|
|
411
|
+
return VarID(table=table, rows=rows, cols=cols, sheets=sheets, interval=interval, default=default,
|
|
412
|
+
is_table_group=is_table_group)
|
|
413
|
+
|
|
414
|
+
def visitTableRef(self, ctx: dpm_xlParser.TableRefContext):
|
|
415
|
+
ctx_list = list(ctx.getChildren())
|
|
416
|
+
table_reference = self.visit(ctx_list[0])
|
|
417
|
+
is_group = False
|
|
418
|
+
if table_reference[0] == TABLE_GROUP_PREFIX:
|
|
419
|
+
is_group = True
|
|
420
|
+
return self.create_var_id(ctx_list=ctx_list, table=table_reference[1:], is_table_group=is_group)
|
|
421
|
+
|
|
422
|
+
def visitTableReference(self, ctx:dpm_xlParser.TableReferenceContext):
|
|
423
|
+
return ctx.getChild(0).symbol.text
|
|
424
|
+
|
|
425
|
+
def visitCompRef(self, ctx: dpm_xlParser.CompRefContext):
|
|
426
|
+
ctx_list = list(ctx.getChildren())
|
|
427
|
+
return self.create_var_id(ctx_list=ctx_list)
|
|
428
|
+
|
|
429
|
+
def visitRowHandler(self, ctx: dpm_xlParser.RowHandlerContext):
|
|
430
|
+
ctx_list = list(ctx.getChildren())
|
|
431
|
+
|
|
432
|
+
rows = []
|
|
433
|
+
for child in ctx_list:
|
|
434
|
+
if isinstance(child, dpm_xlParser.RowElemContext):
|
|
435
|
+
rows.append(self.visitRowElem(child))
|
|
436
|
+
elif isinstance(child, TerminalNodeImpl) and child.symbol.text not in (',', '(', ')'):
|
|
437
|
+
rows.append(child.symbol.text[1:])
|
|
438
|
+
return rows
|
|
439
|
+
|
|
440
|
+
def visitColHandler(self, ctx: dpm_xlParser.ColHandlerContext):
|
|
441
|
+
ctx_list = list(ctx.getChildren())
|
|
442
|
+
|
|
443
|
+
cols = []
|
|
444
|
+
for child in ctx_list:
|
|
445
|
+
if isinstance(child, dpm_xlParser.ColElemContext):
|
|
446
|
+
cols.append(self.visitColElem(child))
|
|
447
|
+
elif isinstance(child, TerminalNodeImpl) and child.symbol.text not in (',', '(', ')'):
|
|
448
|
+
cols.append(child.symbol.text[1:])
|
|
449
|
+
return cols
|
|
450
|
+
|
|
451
|
+
def visitSheetHandler(self, ctx: dpm_xlParser.SheetHandlerContext):
|
|
452
|
+
ctx_list = list(ctx.getChildren())
|
|
453
|
+
|
|
454
|
+
sheets = []
|
|
455
|
+
for child in ctx_list:
|
|
456
|
+
if isinstance(child, dpm_xlParser.SheetElemContext):
|
|
457
|
+
sheets.append(self.visitSheetElem(child))
|
|
458
|
+
elif isinstance(child, TerminalNodeImpl) and child.symbol.text not in (',', '(', ')'):
|
|
459
|
+
sheets.append(child.symbol.text[1:])
|
|
460
|
+
return sheets
|
|
461
|
+
|
|
462
|
+
def visitInterval(self, ctx: dpm_xlParser.IntervalContext):
|
|
463
|
+
interval = None
|
|
464
|
+
ctx_list = list(ctx.getChildren())
|
|
465
|
+
if ctx_list[2].symbol.text and ctx_list[2].symbol.text.lower() == 'true':
|
|
466
|
+
interval = True
|
|
467
|
+
if ctx_list[2].symbol.text and ctx_list[2].symbol.text.lower() == 'false':
|
|
468
|
+
interval = False
|
|
469
|
+
return interval
|
|
470
|
+
|
|
471
|
+
def visitDefault(self, ctx: dpm_xlParser.DefaultContext):
|
|
472
|
+
if isinstance(ctx.getChild(2), TerminalNodeImpl) and ctx.getChild(2).symbol.text == 'null':
|
|
473
|
+
return None
|
|
474
|
+
default_value = self.visitLiteral(ctx.getChild(2))
|
|
475
|
+
return default_value
|
|
476
|
+
|
|
477
|
+
def visitRowElem(self, ctx: dpm_xlParser.RowElemContext):
|
|
478
|
+
return self.process_cell_element(ctx)
|
|
479
|
+
|
|
480
|
+
def visitColElem(self, ctx: dpm_xlParser.ColElemContext):
|
|
481
|
+
return self.process_cell_element(ctx)
|
|
482
|
+
|
|
483
|
+
def visitSheetElem(self, ctx: dpm_xlParser.SheetElemContext):
|
|
484
|
+
return self.process_cell_element(ctx)
|
|
485
|
+
|
|
486
|
+
def visitKeyNamesExpr(self, ctx: dpm_xlParser.KeyNamesExprContext):
|
|
487
|
+
child = ctx.getChild(0)
|
|
488
|
+
code = self.visit(child)
|
|
489
|
+
return Dimension(dimension_code=code)
|
|
490
|
+
|
|
491
|
+
def visitVarID(self, ctx: dpm_xlParser.VarIDContext):
|
|
492
|
+
return self.visit(ctx.getChild(1))
|
|
493
|
+
|
|
494
|
+
def visitTemporaryIdentifier(self, ctx: dpm_xlParser.TemporaryIdentifierContext):
|
|
495
|
+
value = ctx.getChild(0).symbol.text
|
|
496
|
+
return TemporaryIdentifier(value=value)
|
|
497
|
+
|
|
498
|
+
@staticmethod
|
|
499
|
+
def process_cell_element(ctx):
|
|
500
|
+
|
|
501
|
+
child = ctx.getChild(0)
|
|
502
|
+
value = child.symbol.text
|
|
503
|
+
return value[1:]
|