Skip to content

Commit 447fb43

Browse files
align ExpressionGenerator to develop
1 parent 458aa4b commit 447fb43

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

src/main/java/com/regnosys/rosetta/generator/python/expressions/PythonExpressionGenerator.xtend

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class PythonExpressionGenerator {
7171
if (cond.isConstraintCondition)
7272
result += generateConstraintCondition(cls, cond)
7373
else
74-
result += generateExpressionCondition(cond)
74+
result += generateIfThenElseOrSwitch(cond)
7575
nConditions++
7676
}
7777
return result
@@ -82,7 +82,7 @@ class PythonExpressionGenerator {
8282
var result = '';
8383
for (Condition cond : conditions) {
8484
result += generateFunctionConditionBoilerPlate(cond, nConditions, condition_type)
85-
result += generateExpressionCondition(cond)
85+
result += generateIfThenElseOrSwitch(cond)
8686
nConditions++
8787
}
8888

@@ -196,23 +196,17 @@ class PythonExpressionGenerator {
196196
'''
197197
}
198198

199-
private def generateExpressionCondition(Condition c) {
199+
private def generateIfThenElseOrSwitch(Condition c) {
200200
ifCondBlocks.clear()
201-
switchCondBlocks = new ArrayList<String>()
201+
switchCondBlocks.clear()
202202
var expr = generateExpression(c.expression, 0, false)
203-
var blocks = ""
204-
var switch_blocks = ""
205-
if (!ifCondBlocks.isEmpty()) {
206-
blocks = ''' «FOR arg : ifCondBlocks»«arg»«ENDFOR»'''
207-
}
208203
if (!switchCondBlocks.isEmpty()) {
209-
switch_blocks = ''' «FOR arg : switchCondBlocks»«arg»«ENDFOR»'''
204+
var switchBlocks = ''' «FOR arg : switchCondBlocks»«arg»«ENDFOR»'''
205+
return '''«switchBlocks» «expr»'''
210206
}
211-
if (switch_blocks.equals(""))
212-
return '''«blocks» return «expr»
213-
'''
214-
else
215-
return '''«switch_blocks» «expr»'''
207+
var blocks = (ifCondBlocks.isEmpty()) ? "" : ''' «FOR arg : ifCondBlocks»«arg»«ENDFOR»'''
208+
return '''«blocks» return «expr»
209+
'''
216210
}
217211

218212
private def String generateConditionalExpression(RosettaConditionalExpression expr, int ifLevel, boolean isLambda) {
@@ -292,6 +286,7 @@ class PythonExpressionGenerator {
292286
}
293287

294288
private def String generateSwitchOperation(SwitchOperation expr, int ifLevel, boolean isLambda) {
289+
// translate switch into a series of if / elif statements
295290
val attr = generateExpression(expr.argument, 0, isLambda)
296291
val arg = expr.argument as RosettaSymbolReference
297292

0 commit comments

Comments
 (0)