Skip to content

Commit d7228e5

Browse files
updated to latest DSL and function name clean up
1 parent 66f52be commit d7228e5

File tree

5 files changed

+109
-109
lines changed

5 files changed

+109
-109
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@
156156
<repoServerHost>s01.oss.sonatype.org</repoServerHost>
157157
<stagingTimeoutInMinutes>10</stagingTimeoutInMinutes>
158158

159-
<rosetta.dsl.version>9.47.0</rosetta.dsl.version>
160-
<rosetta.bundle.version>11.57.1</rosetta.bundle.version>
159+
<rosetta.dsl.version>9.49.1</rosetta.dsl.version>
160+
<rosetta.bundle.version>11.59.1</rosetta.bundle.version>
161161

162162
<xtext.version>2.27.0</xtext.version>
163163

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

Lines changed: 101 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -64,43 +64,6 @@ class PythonExpressionGenerator {
6464
public var ifCondBlocks = new ArrayList<String>()
6565
public var isSwitchCond = false
6666

67-
def String generateConditions(Data cls) {
68-
var nConditions = 0;
69-
var result = '';
70-
for (Condition cond : cls.conditions) {
71-
result += generateConditionBoilerPlate(cond, nConditions)
72-
if (cond.isConstraintCondition)
73-
result += generateConstraintCondition(cls, cond)
74-
else
75-
result += generateIfThenElseOrSwitch(cond)
76-
nConditions++
77-
}
78-
return result
79-
}
80-
81-
def generateFunctionConditions(List<Condition> conditions, String condition_type) {
82-
var nConditions = 0;
83-
var result = '';
84-
for (Condition cond : conditions) {
85-
result += generateFunctionConditionBoilerPlate(cond, nConditions, condition_type)
86-
result += generateIfThenElseOrSwitch(cond)
87-
nConditions++
88-
}
89-
90-
return result
91-
}
92-
93-
def generateExpressionThenElse(RosettaExpression expr, List<Integer> ifLevel) {
94-
ifCondBlocks.clear()
95-
generateExpression(expr, ifLevel.get(0), false)
96-
var blocks = ""
97-
if (!ifCondBlocks.isEmpty()) {
98-
ifLevel.set(0, ifLevel.get(0) + 1)
99-
blocks = ''' «FOR arg : ifCondBlocks»«arg»«ENDFOR»'''
100-
}
101-
return '''«blocks»'''
102-
}
103-
10467
def String generateExpression(RosettaExpression expr, int ifLevel, boolean isLambda) {
10568
switch (expr) {
10669
// literals
@@ -144,70 +107,6 @@ class PythonExpressionGenerator {
144107
}
145108
}
146109

147-
private def boolean isConstraintCondition(Condition cond) {
148-
return isOneOf(cond) || isChoice(cond)
149-
}
150-
151-
private def boolean isOneOf(Condition cond) {
152-
return cond.expression instanceof OneOfOperation
153-
}
154-
155-
private def boolean isChoice(Condition cond) {
156-
return cond.expression instanceof ChoiceOperation
157-
}
158-
159-
private def generateConditionBoilerPlate(Condition cond, int nConditions) {
160-
'''
161-
162-
@rune_condition
163-
def condition_«nConditions»_«cond.name»(self):
164-
«IF cond.definition!==null»
165-
"""
166-
«cond.definition»
167-
"""
168-
«ENDIF»
169-
item = self
170-
'''
171-
}
172-
173-
private def generateFunctionConditionBoilerPlate(Condition cond, int nConditions, String condition_type) {
174-
'''
175-
176-
@rune_local_condition(«condition_type»)
177-
def condition_«nConditions»_«cond.name»(self):
178-
«IF cond.definition!==null»
179-
"""
180-
«cond.definition»
181-
"""
182-
«ENDIF»
183-
'''
184-
}
185-
186-
private def generateConstraintCondition(Data cls, Condition cond) {
187-
val expression = cond.expression
188-
var attributes = cls.attributes
189-
var necessity = "necessity=True"
190-
if (expression instanceof ChoiceOperation) {
191-
attributes = expression.attributes
192-
if (expression.necessity == Necessity.OPTIONAL) {
193-
necessity = "necessity=False"
194-
}
195-
}
196-
''' return rune_check_one_of(self, «FOR a : attributes SEPARATOR ", "»'«a.name»'«ENDFOR», «necessity»)
197-
'''
198-
}
199-
200-
private def generateIfThenElseOrSwitch(Condition c) {
201-
ifCondBlocks.clear()
202-
isSwitchCond=false
203-
204-
var expr = generateExpression(c.expression, 0, false)
205-
if (isSwitchCond) return expr
206-
var blocks = (ifCondBlocks.isEmpty()) ? "" : ''' «FOR arg : ifCondBlocks»«arg»«ENDFOR»'''
207-
return '''«blocks» return «expr»
208-
'''
209-
}
210-
211110
private def String generateConditionalExpression(RosettaConditionalExpression expr, int ifLevel, boolean isLambda) {
212111
val ifExpr = generateExpression(expr.getIf(), ifLevel + 1, isLambda)
213112
val ifThen = generateExpression(expr.ifthen, ifLevel + 1, isLambda)
@@ -427,6 +326,107 @@ class PythonExpressionGenerator {
427326
}
428327
}
429328

329+
def String generateTypeOrFunctionConditions(Data cls) {
330+
var nConditions = 0;
331+
var result = '';
332+
for (Condition cond : cls.conditions) {
333+
result += generateConditionBoilerPlate(cond, nConditions)
334+
if (cond.isConstraintCondition)
335+
result += generateConstraintCondition(cls, cond)
336+
else
337+
result += generateIfThenElseOrSwitch(cond)
338+
nConditions++
339+
}
340+
return result
341+
}
342+
343+
def generateFunctionConditions(List<Condition> conditions, String condition_type) {
344+
var nConditions = 0;
345+
var result = '';
346+
for (Condition cond : conditions) {
347+
result += generateFunctionConditionBoilerPlate(cond, nConditions, condition_type)
348+
result += generateIfThenElseOrSwitch(cond)
349+
nConditions++
350+
}
351+
352+
return result
353+
}
354+
355+
def generateThenElseForFunction(RosettaExpression expr, List<Integer> ifLevel) {
356+
ifCondBlocks.clear()
357+
generateExpression(expr, ifLevel.get(0), false)
358+
var blocks = ""
359+
if (!ifCondBlocks.isEmpty()) {
360+
ifLevel.set(0, ifLevel.get(0) + 1)
361+
blocks = ''' «FOR arg : ifCondBlocks»«arg»«ENDFOR»'''
362+
}
363+
return '''«blocks»'''
364+
}
365+
366+
private def boolean isConstraintCondition(Condition cond) {
367+
return isOneOf(cond) || isChoice(cond)
368+
}
369+
370+
private def boolean isOneOf(Condition cond) {
371+
return cond.expression instanceof OneOfOperation
372+
}
373+
374+
private def boolean isChoice(Condition cond) {
375+
return cond.expression instanceof ChoiceOperation
376+
}
377+
378+
private def generateConditionBoilerPlate(Condition cond, int nConditions) {
379+
'''
380+
381+
@rune_condition
382+
def condition_«nConditions»_«cond.name»(self):
383+
«IF cond.definition!==null»
384+
"""
385+
«cond.definition»
386+
"""
387+
«ENDIF»
388+
item = self
389+
'''
390+
}
391+
392+
private def generateFunctionConditionBoilerPlate(Condition cond, int nConditions, String condition_type) {
393+
'''
394+
395+
@rune_local_condition(«condition_type»)
396+
def condition_«nConditions»_«cond.name»(self):
397+
«IF cond.definition!==null»
398+
"""
399+
«cond.definition»
400+
"""
401+
«ENDIF»
402+
'''
403+
}
404+
405+
private def generateConstraintCondition(Data cls, Condition cond) {
406+
val expression = cond.expression
407+
var attributes = cls.attributes
408+
var necessity = "necessity=True"
409+
if (expression instanceof ChoiceOperation) {
410+
attributes = expression.attributes
411+
if (expression.necessity == Necessity.OPTIONAL) {
412+
necessity = "necessity=False"
413+
}
414+
}
415+
''' return rune_check_one_of(self, «FOR a : attributes SEPARATOR ", "»'«a.name»'«ENDFOR», «necessity»)
416+
'''
417+
}
418+
419+
private def generateIfThenElseOrSwitch(Condition c) {
420+
ifCondBlocks.clear()
421+
isSwitchCond=false
422+
423+
var expr = generateExpression(c.expression, 0, false)
424+
if (isSwitchCond) return expr
425+
var blocks = (ifCondBlocks.isEmpty()) ? "" : ''' «FOR arg : ifCondBlocks»«arg»«ENDFOR»'''
426+
return '''«blocks» return «expr»
427+
'''
428+
}
429+
430430
def addImportsFromConditions(String variable, String namespace) {
431431
val import = '''from «namespace».«variable» import «variable»'''
432432
if (importsFound !== null && !importsFound.contains(import)) {

src/main/java/com/regnosys/rosetta/generator/python/func/PythonFunctionGenerator.xtend

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class PythonFunctionGenerator {
7474
«ENDIF»
7575
self = inspect.currentframe()
7676
77-
«generateConditions(function)»
77+
«generateTypeOrFunctionConditions(function)»
7878
7979
«generateIfBlocks(function)»
8080
«generateAlias(function)»
@@ -211,15 +211,15 @@ class PythonFunctionGenerator {
211211

212212
'''
213213
«FOR shortcut : function.shortcuts»
214-
«expressionGenerator.generateExpressionThenElse(shortcut.expression, levelList)»
214+
«expressionGenerator.generateThenElseForFunction(shortcut.expression, levelList)»
215215
«ENDFOR»
216216
«FOR operation : function.operations»
217-
«expressionGenerator.generateExpressionThenElse(operation.expression, levelList)»
217+
«expressionGenerator.generateThenElseForFunction(operation.expression, levelList)»
218218
«ENDFOR»
219219
'''
220220
}
221221

222-
private def generateConditions(Function function) {
222+
private def generateTypeOrFunctionConditions(Function function) {
223223
'''
224224
«IF function.conditions.size>0»
225225
# conditions

src/main/java/com/regnosys/rosetta/generator/python/object/PythonAttributeProcessor.xtend

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class PythonAttributeProcessor {
219219
validators.add("@ref:scoped")
220220
}
221221
default: {
222-
println("---- unprocessed meta ... name: " + ma.name)
222+
throw new IllegalStateException("Unsupported metadata attribute: " + ma.name)
223223
}
224224
}
225225
]

src/main/java/com/regnosys/rosetta/generator/python/object/PythonModelObjectGenerator.xtend

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ class PythonModelObjectGenerator {
241241
«IF !keyRefConstraints.isEmpty()»
242242
«keyRefConstraintsToString(keyRefConstraints)»
243243
«ENDIF»
244-
«expressionGenerator.generateConditions(rosettaClass)»
244+
«expressionGenerator.generateTypeOrFunctionConditions(rosettaClass)»
245245
'''
246246
}
247247
}

0 commit comments

Comments
 (0)