vtlengine 1.0__py3-none-any.whl → 1.0.1__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.
Potentially problematic release.
This version of vtlengine might be problematic. Click here for more details.
- vtlengine/API/_InternalApi.py +153 -100
- vtlengine/API/__init__.py +109 -67
- vtlengine/AST/ASTConstructor.py +188 -98
- vtlengine/AST/ASTConstructorModules/Expr.py +306 -200
- vtlengine/AST/ASTConstructorModules/ExprComponents.py +172 -102
- vtlengine/AST/ASTConstructorModules/Terminals.py +158 -95
- vtlengine/AST/ASTEncoders.py +1 -1
- vtlengine/AST/ASTTemplate.py +8 -9
- vtlengine/AST/ASTVisitor.py +8 -12
- vtlengine/AST/DAG/__init__.py +43 -35
- vtlengine/AST/DAG/_words.py +4 -4
- vtlengine/AST/Grammar/lexer.py +732 -142
- vtlengine/AST/Grammar/parser.py +2188 -826
- vtlengine/AST/Grammar/tokens.py +128 -128
- vtlengine/AST/VtlVisitor.py +7 -4
- vtlengine/AST/__init__.py +22 -11
- vtlengine/DataTypes/NumericTypesHandling.py +5 -4
- vtlengine/DataTypes/TimeHandling.py +194 -301
- vtlengine/DataTypes/__init__.py +304 -218
- vtlengine/Exceptions/__init__.py +52 -27
- vtlengine/Exceptions/messages.py +134 -62
- vtlengine/Interpreter/__init__.py +781 -487
- vtlengine/Model/__init__.py +165 -121
- vtlengine/Operators/Aggregation.py +156 -95
- vtlengine/Operators/Analytic.py +115 -59
- vtlengine/Operators/Assignment.py +7 -4
- vtlengine/Operators/Boolean.py +27 -32
- vtlengine/Operators/CastOperator.py +177 -131
- vtlengine/Operators/Clause.py +137 -99
- vtlengine/Operators/Comparison.py +148 -117
- vtlengine/Operators/Conditional.py +149 -98
- vtlengine/Operators/General.py +68 -47
- vtlengine/Operators/HROperators.py +91 -72
- vtlengine/Operators/Join.py +217 -118
- vtlengine/Operators/Numeric.py +89 -44
- vtlengine/Operators/RoleSetter.py +16 -15
- vtlengine/Operators/Set.py +61 -36
- vtlengine/Operators/String.py +213 -139
- vtlengine/Operators/Time.py +334 -216
- vtlengine/Operators/Validation.py +117 -76
- vtlengine/Operators/__init__.py +340 -213
- vtlengine/Utils/__init__.py +195 -40
- vtlengine/__init__.py +1 -1
- vtlengine/files/output/__init__.py +15 -6
- vtlengine/files/output/_time_period_representation.py +10 -9
- vtlengine/files/parser/__init__.py +77 -52
- vtlengine/files/parser/_rfc_dialect.py +6 -5
- vtlengine/files/parser/_time_checking.py +46 -37
- vtlengine-1.0.1.dist-info/METADATA +236 -0
- vtlengine-1.0.1.dist-info/RECORD +58 -0
- {vtlengine-1.0.dist-info → vtlengine-1.0.1.dist-info}/WHEEL +1 -1
- vtlengine-1.0.dist-info/METADATA +0 -104
- vtlengine-1.0.dist-info/RECORD +0 -58
- {vtlengine-1.0.dist-info → vtlengine-1.0.1.dist-info}/LICENSE.md +0 -0
vtlengine/AST/ASTConstructor.py
CHANGED
|
@@ -14,7 +14,14 @@ from vtlengine.AST import (
|
|
|
14
14
|
Assignment,
|
|
15
15
|
PersistentAssignment,
|
|
16
16
|
Operator,
|
|
17
|
-
Argument,
|
|
17
|
+
Argument,
|
|
18
|
+
DPRuleset,
|
|
19
|
+
HRBinOp,
|
|
20
|
+
DPRule,
|
|
21
|
+
HRuleset,
|
|
22
|
+
DefIdentifier,
|
|
23
|
+
HRule,
|
|
24
|
+
HRUnOp,
|
|
18
25
|
)
|
|
19
26
|
from vtlengine.AST.ASTConstructorModules.Expr import Expr
|
|
20
27
|
from vtlengine.AST.ASTConstructorModules.ExprComponents import ExprComp
|
|
@@ -51,8 +58,9 @@ class ASTVisitor(VtlVisitor):
|
|
|
51
58
|
ctx_list = list(ctx.getChildren())
|
|
52
59
|
|
|
53
60
|
statements_nodes = []
|
|
54
|
-
statements = [
|
|
55
|
-
|
|
61
|
+
statements = [
|
|
62
|
+
statement for statement in ctx_list if isinstance(statement, Parser.StatementContext)
|
|
63
|
+
]
|
|
56
64
|
if len(statements) != 0:
|
|
57
65
|
for statement in statements:
|
|
58
66
|
statements_nodes.append(self.visitStatement(statement))
|
|
@@ -119,10 +127,10 @@ class ASTVisitor(VtlVisitor):
|
|
|
119
127
|
|
|
120
128
|
def visitDefineExpression(self, ctx: Parser.DefineExpressionContext):
|
|
121
129
|
"""
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
130
|
+
defExpr: defOperator
|
|
131
|
+
| defDatapoint
|
|
132
|
+
| defHierarchical
|
|
133
|
+
;
|
|
126
134
|
"""
|
|
127
135
|
if isinstance(ctx, Parser.DefOperatorContext):
|
|
128
136
|
return self.visitDefOperator(ctx)
|
|
@@ -135,40 +143,45 @@ class ASTVisitor(VtlVisitor):
|
|
|
135
143
|
|
|
136
144
|
def visitDefOperator(self, ctx: Parser.DefOperatorContext):
|
|
137
145
|
"""
|
|
138
|
-
|
|
139
|
-
|
|
146
|
+
DEFINE OPERATOR operatorID LPAREN (parameterItem (COMMA parameterItem)*)? RPAREN
|
|
147
|
+
(RETURNS outputParameterType)? IS (expr) END OPERATOR # defOperator"""
|
|
140
148
|
ctx_list = list(ctx.getChildren())
|
|
141
149
|
|
|
142
150
|
operator = Terminals().visitOperatorID(ctx_list[2])
|
|
143
|
-
parameters = [
|
|
144
|
-
|
|
151
|
+
parameters = [
|
|
152
|
+
self.visitParameterItem(parameter)
|
|
153
|
+
for parameter in ctx_list
|
|
154
|
+
if isinstance(parameter, Parser.ParameterItemContext)
|
|
155
|
+
]
|
|
145
156
|
return_ = [
|
|
146
157
|
Terminals().visitOutputParameterType(datatype)
|
|
147
158
|
for datatype in ctx_list
|
|
148
159
|
if isinstance(datatype, Parser.OutputParameterTypeContext)
|
|
149
160
|
]
|
|
150
161
|
# Here should be modified if we want to include more than one expr per function.
|
|
151
|
-
expr =
|
|
152
|
-
|
|
162
|
+
expr = [
|
|
163
|
+
Expr().visitExpr(expr) for expr in ctx_list if isinstance(expr, Parser.ExprContext)
|
|
164
|
+
][0]
|
|
153
165
|
|
|
154
166
|
if len(return_) == 0:
|
|
155
167
|
raise SemanticError("1-4-2-5", op=operator)
|
|
156
168
|
else:
|
|
157
169
|
return_node = return_[0]
|
|
158
170
|
|
|
159
|
-
return Operator(
|
|
160
|
-
|
|
171
|
+
return Operator(
|
|
172
|
+
op=operator, parameters=parameters, output_type=return_node, expression=expr
|
|
173
|
+
)
|
|
161
174
|
|
|
162
175
|
"""
|
|
163
176
|
-----------------------------------
|
|
164
|
-
Define Datapoint
|
|
177
|
+
Define Datapoint
|
|
165
178
|
-----------------------------------
|
|
166
179
|
"""
|
|
167
180
|
|
|
168
181
|
def visitDefDatapointRuleset(self, ctx: Parser.DefDatapointRulesetContext):
|
|
169
182
|
"""
|
|
170
|
-
|
|
171
|
-
|
|
183
|
+
DEFINE DATAPOINT RULESET rulesetID LPAREN rulesetSignature RPAREN IS ruleClauseDatapoint
|
|
184
|
+
END DATAPOINT RULESET # defDatapointRuleset
|
|
172
185
|
"""
|
|
173
186
|
|
|
174
187
|
ctx_list = list(ctx.getChildren())
|
|
@@ -177,8 +190,12 @@ class ASTVisitor(VtlVisitor):
|
|
|
177
190
|
signature_type, ruleset_elements = self.visitRulesetSignature(ctx_list[5])
|
|
178
191
|
ruleset_rules = self.visitRuleClauseDatapoint(ctx_list[8])
|
|
179
192
|
|
|
180
|
-
return DPRuleset(
|
|
181
|
-
|
|
193
|
+
return DPRuleset(
|
|
194
|
+
name=ruleset_name,
|
|
195
|
+
params=ruleset_elements,
|
|
196
|
+
rules=ruleset_rules,
|
|
197
|
+
signature_type=signature_type,
|
|
198
|
+
)
|
|
182
199
|
|
|
183
200
|
def visitRulesetSignature(self, ctx: Parser.RulesetSignatureContext):
|
|
184
201
|
"""
|
|
@@ -187,19 +204,29 @@ class ASTVisitor(VtlVisitor):
|
|
|
187
204
|
ctx_list = list(ctx.getChildren())
|
|
188
205
|
signature_type = ctx_list[0].getSymbol().text
|
|
189
206
|
|
|
190
|
-
value_domains = [
|
|
191
|
-
|
|
192
|
-
|
|
207
|
+
value_domains = [
|
|
208
|
+
value_domain
|
|
209
|
+
for value_domain in ctx_list
|
|
210
|
+
if isinstance(value_domain, TerminalNodeImpl)
|
|
211
|
+
and value_domain.getSymbol().type == Parser.VALUE_DOMAIN
|
|
212
|
+
]
|
|
193
213
|
if len(value_domains) != 0:
|
|
194
|
-
kind =
|
|
214
|
+
kind = "ValuedomainID"
|
|
195
215
|
|
|
196
|
-
variables = [
|
|
197
|
-
|
|
216
|
+
variables = [
|
|
217
|
+
variable
|
|
218
|
+
for variable in ctx_list
|
|
219
|
+
if isinstance(variable, TerminalNodeImpl)
|
|
220
|
+
and variable.getSymbol().type == Parser.VARIABLE
|
|
221
|
+
]
|
|
198
222
|
if len(variables) != 0:
|
|
199
|
-
kind =
|
|
223
|
+
kind = "ComponentID"
|
|
200
224
|
|
|
201
|
-
component_nodes = [
|
|
202
|
-
|
|
225
|
+
component_nodes = [
|
|
226
|
+
Terminals().visitSignature(component, kind)
|
|
227
|
+
for component in ctx_list
|
|
228
|
+
if isinstance(component, Parser.SignatureContext)
|
|
229
|
+
]
|
|
203
230
|
|
|
204
231
|
return signature_type, component_nodes
|
|
205
232
|
|
|
@@ -209,8 +236,11 @@ class ASTVisitor(VtlVisitor):
|
|
|
209
236
|
"""
|
|
210
237
|
ctx_list = list(ctx.getChildren())
|
|
211
238
|
|
|
212
|
-
ruleset_rules = [
|
|
213
|
-
|
|
239
|
+
ruleset_rules = [
|
|
240
|
+
self.visitRuleItemDatapoint(ruleId)
|
|
241
|
+
for ruleId in ctx_list
|
|
242
|
+
if isinstance(ruleId, Parser.RuleItemDatapointContext)
|
|
243
|
+
]
|
|
214
244
|
return ruleset_rules
|
|
215
245
|
|
|
216
246
|
def visitRuleItemDatapoint(self, ctx: Parser.RuleItemDatapointContext):
|
|
@@ -219,15 +249,25 @@ class ASTVisitor(VtlVisitor):
|
|
|
219
249
|
"""
|
|
220
250
|
ctx_list = list(ctx.getChildren())
|
|
221
251
|
|
|
222
|
-
when = [
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
252
|
+
when = [
|
|
253
|
+
whens
|
|
254
|
+
for whens in ctx_list
|
|
255
|
+
if isinstance(whens, TerminalNodeImpl) and whens.getSymbol().type == Parser.WHEN
|
|
256
|
+
]
|
|
257
|
+
rule_name = [
|
|
258
|
+
(
|
|
259
|
+
rule_name.getSymbol().text
|
|
260
|
+
if isinstance(rule_name, TerminalNodeImpl)
|
|
261
|
+
and rule_name.getSymbol().type == Parser.IDENTIFIER
|
|
262
|
+
else None
|
|
263
|
+
)
|
|
264
|
+
for rule_name in ctx_list
|
|
265
|
+
][0]
|
|
266
|
+
expr_node = [
|
|
267
|
+
ExprComp().visitExprComponent(rule_node)
|
|
268
|
+
for rule_node in ctx_list
|
|
269
|
+
if isinstance(rule_node, Parser.ExprComponentContext)
|
|
270
|
+
]
|
|
231
271
|
|
|
232
272
|
if len(when) != 0:
|
|
233
273
|
rule_node = HRBinOp(left=expr_node[0], op=when[0].getSymbol().text, right=expr_node[1])
|
|
@@ -235,14 +275,20 @@ class ASTVisitor(VtlVisitor):
|
|
|
235
275
|
else:
|
|
236
276
|
rule_node = expr_node[0]
|
|
237
277
|
|
|
238
|
-
er_code = [
|
|
239
|
-
|
|
278
|
+
er_code = [
|
|
279
|
+
Terminals().visitErCode(erCode_name)
|
|
280
|
+
for erCode_name in ctx_list
|
|
281
|
+
if isinstance(erCode_name, Parser.ErCodeContext)
|
|
282
|
+
]
|
|
240
283
|
if len(er_code) == 0:
|
|
241
284
|
er_code = None
|
|
242
285
|
else:
|
|
243
286
|
er_code = er_code[0]
|
|
244
|
-
er_level = [
|
|
245
|
-
|
|
287
|
+
er_level = [
|
|
288
|
+
Terminals().visitErLevel(erLevel_name)
|
|
289
|
+
for erLevel_name in ctx_list
|
|
290
|
+
if isinstance(erLevel_name, Parser.ErLevelContext)
|
|
291
|
+
]
|
|
246
292
|
if len(er_level) == 0:
|
|
247
293
|
er_level = None
|
|
248
294
|
else:
|
|
@@ -256,12 +302,21 @@ class ASTVisitor(VtlVisitor):
|
|
|
256
302
|
"""
|
|
257
303
|
ctx_list = list(ctx.getChildren())
|
|
258
304
|
|
|
259
|
-
argument_name = [
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
305
|
+
argument_name = [
|
|
306
|
+
Terminals().visitVarID(element)
|
|
307
|
+
for element in ctx_list
|
|
308
|
+
if isinstance(element, Parser.VarIDContext)
|
|
309
|
+
][0]
|
|
310
|
+
argument_type = [
|
|
311
|
+
Terminals().visitInputParameterType(element)
|
|
312
|
+
for element in ctx_list
|
|
313
|
+
if isinstance(element, Parser.InputParameterTypeContext)
|
|
314
|
+
][0]
|
|
315
|
+
argument_default = [
|
|
316
|
+
Terminals().visitScalarItem(element)
|
|
317
|
+
for element in ctx_list
|
|
318
|
+
if isinstance(element, Parser.ScalarItemContext)
|
|
319
|
+
]
|
|
265
320
|
|
|
266
321
|
if len(argument_default) == 0:
|
|
267
322
|
argument_default = None
|
|
@@ -274,14 +329,14 @@ class ASTVisitor(VtlVisitor):
|
|
|
274
329
|
|
|
275
330
|
"""
|
|
276
331
|
-----------------------------------
|
|
277
|
-
Define Hierarchical
|
|
332
|
+
Define Hierarchical
|
|
278
333
|
-----------------------------------
|
|
279
334
|
"""
|
|
280
335
|
|
|
281
336
|
def visitDefHierarchical(self, ctx: Parser.DefHierarchicalContext):
|
|
282
337
|
"""
|
|
283
|
-
|
|
284
|
-
|
|
338
|
+
DEFINE DATAPOINT RULESET rulesetID LPAREN rulesetSignature RPAREN IS ruleClauseDatapoint
|
|
339
|
+
END DATAPOINT RULESET # defDatapointRuleset
|
|
285
340
|
"""
|
|
286
341
|
|
|
287
342
|
ctx_list = list(ctx.getChildren())
|
|
@@ -298,8 +353,12 @@ class ASTVisitor(VtlVisitor):
|
|
|
298
353
|
if len(ruleset_rules) == 0:
|
|
299
354
|
raise Exception(f"No rules found for the ruleset {ruleset_name}")
|
|
300
355
|
|
|
301
|
-
return HRuleset(
|
|
302
|
-
|
|
356
|
+
return HRuleset(
|
|
357
|
+
signature_type=signature_type,
|
|
358
|
+
name=ruleset_name,
|
|
359
|
+
element=ruleset_elements,
|
|
360
|
+
rules=ruleset_rules,
|
|
361
|
+
)
|
|
303
362
|
|
|
304
363
|
# TODO Add support for value Domains.
|
|
305
364
|
def visitHierRuleSignature(self, ctx: Parser.HierRuleSignatureContext):
|
|
@@ -310,27 +369,37 @@ class ASTVisitor(VtlVisitor):
|
|
|
310
369
|
|
|
311
370
|
signature_type = ctx_list[0].getSymbol().text
|
|
312
371
|
|
|
313
|
-
value_domain = [
|
|
314
|
-
|
|
315
|
-
|
|
372
|
+
value_domain = [
|
|
373
|
+
valueDomain
|
|
374
|
+
for valueDomain in ctx_list
|
|
375
|
+
if isinstance(valueDomain, TerminalNodeImpl)
|
|
376
|
+
and valueDomain.getSymbol().type == Parser.VALUE_DOMAIN
|
|
377
|
+
]
|
|
316
378
|
if len(value_domain) != 0:
|
|
317
|
-
kind =
|
|
379
|
+
kind = "ValuedomainID"
|
|
318
380
|
else:
|
|
319
|
-
kind =
|
|
381
|
+
kind = "DatasetID"
|
|
320
382
|
|
|
321
383
|
conditions = [
|
|
322
|
-
self.visitValueDomainSignature(vtlsig)
|
|
323
|
-
|
|
384
|
+
self.visitValueDomainSignature(vtlsig)
|
|
385
|
+
for vtlsig in ctx_list
|
|
386
|
+
if isinstance(vtlsig, Parser.ValueDomainSignatureContext)
|
|
387
|
+
]
|
|
324
388
|
|
|
325
|
-
dataset = [
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
389
|
+
dataset = [
|
|
390
|
+
identifier
|
|
391
|
+
for identifier in ctx_list
|
|
392
|
+
if isinstance(identifier, TerminalNodeImpl)
|
|
393
|
+
and identifier.getSymbol().type == Parser.IDENTIFIER
|
|
394
|
+
][0]
|
|
329
395
|
|
|
330
396
|
if conditions:
|
|
331
397
|
identifiers_list = [
|
|
332
|
-
DefIdentifier(
|
|
333
|
-
|
|
398
|
+
DefIdentifier(
|
|
399
|
+
value=elto.alias if getattr(elto, "alias", None) else elto.value, kind=kind
|
|
400
|
+
)
|
|
401
|
+
for elto in conditions[0]
|
|
402
|
+
]
|
|
334
403
|
identifiers_list.append(DefIdentifier(value=dataset.getSymbol().text, kind=kind))
|
|
335
404
|
return signature_type, identifiers_list
|
|
336
405
|
else:
|
|
@@ -339,12 +408,15 @@ class ASTVisitor(VtlVisitor):
|
|
|
339
408
|
# TODO Support for valueDomainSignature.
|
|
340
409
|
def visitValueDomainSignature(self, ctx: Parser.ValueDomainSignatureContext):
|
|
341
410
|
"""
|
|
342
|
-
valueDomainSignature: CONDITION IDENTIFIER (AS IDENTIFIER)? (',' IDENTIFIER (AS IDENTIFIER)?)* ;
|
|
411
|
+
valueDomainSignature: CONDITION IDENTIFIER (AS IDENTIFIER)? (',' IDENTIFIER (AS IDENTIFIER)?)* ; # noqa E501
|
|
343
412
|
"""
|
|
344
413
|
# AST_ASTCONSTRUCTOR.7
|
|
345
414
|
ctx_list = list(ctx.getChildren())
|
|
346
|
-
component_nodes = [
|
|
347
|
-
|
|
415
|
+
component_nodes = [
|
|
416
|
+
Terminals().visitSignature(component)
|
|
417
|
+
for component in ctx_list
|
|
418
|
+
if isinstance(component, Parser.SignatureContext)
|
|
419
|
+
]
|
|
348
420
|
return component_nodes
|
|
349
421
|
|
|
350
422
|
def visitRuleClauseHierarchical(self, ctx: Parser.RuleClauseHierarchicalContext):
|
|
@@ -353,8 +425,11 @@ class ASTVisitor(VtlVisitor):
|
|
|
353
425
|
"""
|
|
354
426
|
ctx_list = list(ctx.getChildren())
|
|
355
427
|
|
|
356
|
-
rules_nodes = [
|
|
357
|
-
|
|
428
|
+
rules_nodes = [
|
|
429
|
+
self.visitRuleItemHierarchical(rule)
|
|
430
|
+
for rule in ctx_list
|
|
431
|
+
if isinstance(rule, Parser.RuleItemHierarchicalContext)
|
|
432
|
+
]
|
|
358
433
|
return rules_nodes
|
|
359
434
|
|
|
360
435
|
def visitRuleItemHierarchical(self, ctx: Parser.RuleItemHierarchicalContext):
|
|
@@ -363,22 +438,35 @@ class ASTVisitor(VtlVisitor):
|
|
|
363
438
|
"""
|
|
364
439
|
ctx_list = list(ctx.getChildren())
|
|
365
440
|
|
|
366
|
-
rule_name = [
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
441
|
+
rule_name = [
|
|
442
|
+
(
|
|
443
|
+
rule_name.getSymbol().text
|
|
444
|
+
if isinstance(rule_name, TerminalNodeImpl)
|
|
445
|
+
and rule_name.getSymbol().type == Parser.IDENTIFIER
|
|
446
|
+
else None
|
|
447
|
+
)
|
|
448
|
+
for rule_name in ctx_list
|
|
449
|
+
][0]
|
|
450
|
+
rule_node = [
|
|
451
|
+
self.visitCodeItemRelation(rule_node)
|
|
452
|
+
for rule_node in ctx_list
|
|
453
|
+
if isinstance(rule_node, Parser.CodeItemRelationContext)
|
|
454
|
+
][0]
|
|
455
|
+
|
|
456
|
+
er_code = [
|
|
457
|
+
Terminals().visitErCode(erCode_name)
|
|
458
|
+
for erCode_name in ctx_list
|
|
459
|
+
if isinstance(erCode_name, Parser.ErCodeContext)
|
|
460
|
+
]
|
|
376
461
|
if len(er_code) == 0:
|
|
377
462
|
er_code = None
|
|
378
463
|
else:
|
|
379
464
|
er_code = er_code[0]
|
|
380
|
-
er_level = [
|
|
381
|
-
|
|
465
|
+
er_level = [
|
|
466
|
+
Terminals().visitErLevel(erLevel_name)
|
|
467
|
+
for erLevel_name in ctx_list
|
|
468
|
+
if isinstance(erLevel_name, Parser.ErLevelContext)
|
|
469
|
+
]
|
|
382
470
|
if len(er_level) == 0:
|
|
383
471
|
er_level = None
|
|
384
472
|
else:
|
|
@@ -388,8 +476,8 @@ class ASTVisitor(VtlVisitor):
|
|
|
388
476
|
|
|
389
477
|
def visitCodeItemRelation(self, ctx: Parser.CodeItemRelationContext):
|
|
390
478
|
"""
|
|
391
|
-
codeItemRelation: ( WHEN expr THEN )? codeItemRef codeItemRelationClause (codeItemRelationClause)* ;
|
|
392
|
-
( WHEN exprComponent THEN )? codetemRef=valueDomainValue comparisonOperand? codeItemRelationClause (codeItemRelationClause)*
|
|
479
|
+
codeItemRelation: ( WHEN expr THEN )? codeItemRef codeItemRelationClause (codeItemRelationClause)* ; # noqa E501
|
|
480
|
+
( WHEN exprComponent THEN )? codetemRef=valueDomainValue comparisonOperand? codeItemRelationClause (codeItemRelationClause)* # noqa E501
|
|
393
481
|
|
|
394
482
|
"""
|
|
395
483
|
|
|
@@ -405,10 +493,12 @@ class ASTVisitor(VtlVisitor):
|
|
|
405
493
|
vd_value = Terminals().visitValueDomainValue(ctx_list[0])
|
|
406
494
|
op = Terminals().visitComparisonOperand(ctx_list[1])
|
|
407
495
|
|
|
408
|
-
rule_node = HRBinOp(
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
496
|
+
rule_node = HRBinOp(
|
|
497
|
+
left=DefIdentifier(value=vd_value, kind="CodeItemID"), op=op, right=None
|
|
498
|
+
)
|
|
499
|
+
items = [
|
|
500
|
+
item for item in ctx_list if isinstance(item, Parser.CodeItemRelationClauseContext)
|
|
501
|
+
]
|
|
412
502
|
|
|
413
503
|
# Means that no concatenations of operations is needed for that rule.
|
|
414
504
|
if len(items) == 1:
|
|
@@ -441,7 +531,7 @@ class ASTVisitor(VtlVisitor):
|
|
|
441
531
|
|
|
442
532
|
def visitCodeItemRelationClause(self, ctx: Parser.CodeItemRelationClauseContext):
|
|
443
533
|
"""
|
|
444
|
-
(opAdd=( PLUS | MINUS ))? rightCodeItem=valueDomainValue ( QLPAREN rightCondition=exprComponent QRPAREN )?
|
|
534
|
+
(opAdd=( PLUS | MINUS ))? rightCodeItem=valueDomainValue ( QLPAREN rightCondition=exprComponent QRPAREN )? # noqa E501
|
|
445
535
|
"""
|
|
446
536
|
ctx_list = list(ctx.getChildren())
|
|
447
537
|
|
|
@@ -451,23 +541,23 @@ class ASTVisitor(VtlVisitor):
|
|
|
451
541
|
raise NotImplementedError
|
|
452
542
|
|
|
453
543
|
right_condition = [
|
|
454
|
-
ExprComp().visitExprComponent(right_condition)
|
|
455
|
-
|
|
544
|
+
ExprComp().visitExprComponent(right_condition)
|
|
545
|
+
for right_condition in ctx_list
|
|
546
|
+
if isinstance(right_condition, Parser.ComparisonExprCompContext)
|
|
456
547
|
]
|
|
457
548
|
|
|
458
549
|
if isinstance(ctx_list[0], TerminalNodeImpl):
|
|
459
550
|
op = ctx_list[0].getSymbol().text
|
|
460
551
|
value = Terminals().visitValueDomainValue(ctx_list[1])
|
|
461
552
|
|
|
462
|
-
code_item = DefIdentifier(value=value, kind=
|
|
553
|
+
code_item = DefIdentifier(value=value, kind="CodeItemID")
|
|
463
554
|
if right_condition:
|
|
464
555
|
setattr(code_item, "_right_condition", right_condition[0])
|
|
465
556
|
|
|
466
|
-
return HRBinOp(left=None, op=op,
|
|
467
|
-
right=code_item)
|
|
557
|
+
return HRBinOp(left=None, op=op, right=code_item)
|
|
468
558
|
else:
|
|
469
559
|
value = Terminals().visitValueDomainValue(ctx_list[0])
|
|
470
|
-
code_item = DefIdentifier(value=value, kind=
|
|
560
|
+
code_item = DefIdentifier(value=value, kind="CodeItemID")
|
|
471
561
|
if right_condition:
|
|
472
562
|
setattr(code_item, "_right_condition", right_condition[0])
|
|
473
563
|
|