@@ -180,16 +180,26 @@ class PythonExpressionGenerator {
180
180
}
181
181
182
182
private def getGuardExpression (SwitchCaseGuard caseGuard , boolean isLambda ){
183
- val enumGuard= caseGuard. getEnumGuard
184
- if (enumGuard!== null ){
185
- return ' ' ' switchAttribute == rune_resolve_attr(«generateEnumString(enumGuard)»,"«caseGuard.getEnumGuard.getName()»")' ' '
183
+ if (caseGuard == = null ) {
184
+ throw new UnsupportedOperationException (" Null SwitchCaseGuard" )
186
185
}
187
- if (caseGuard. getChoiceOptionGuard!== null ){
188
- return ' ' ' rune_resolve_attr(switchAttribute,"«caseGuard.getChoiceOptionGuard.getName()»")' ' '
186
+ val literalGuard = caseGuard. getLiteralGuard();
187
+ if (literalGuard !== null ) {
188
+ return ' ' ' switchAttribute == «generateExpression(literalGuard, 0, isLambda)»' ' '
189
189
}
190
- if (caseGuard. getSymbolGuard!== null ){
191
- return ' ' ' rune_resolve_attr(switchAttribute,"«caseGuard.getSymbolGuard.getName()»")' ' '
190
+ val enumGuard = caseGuard. getEnumGuard
191
+ if (enumGuard !== null ){
192
+ return ' ' ' switchAttribute == rune_resolve_attr(«generateEnumString(enumGuard)»,"«enumGuard.getName()»")' ' '
192
193
}
194
+ val optionGuard = caseGuard. getChoiceOptionGuard
195
+ if (optionGuard !== null ){
196
+ return ' ' ' rune_resolve_attr(switchAttribute,"«optionGuard.getName()»")' ' '
197
+ }
198
+ val dataGuard = caseGuard. getDataGuard
199
+ if (dataGuard !== null ){
200
+ return ' ' ' rune_resolve_attr(switchAttribute,"«dataGuard.getName()»")' ' '
201
+ }
202
+ throw new UnsupportedOperationException (" Unsupported SwitchCaseGuard type" )
193
203
}
194
204
195
205
private def String generateSwitchOperation (SwitchOperation expr , int ifLevel , boolean isLambda ) {
@@ -204,8 +214,8 @@ class PythonExpressionGenerator {
204
214
205
215
for (pair : expr. cases. indexed) {
206
216
val currentCase = pair. value
207
- val funcName= (currentCase. isDefault()) ? " _then_default" : " _then_" + (pair. key+ 1 )
208
- val thenExprDef= (currentCase. isDefault()) ? generateExpression(expr. getDefault(), 0 , isLambda) : generateExpression(currentCase. getExpression(), ifLevel + 1 , isLambda)
217
+ val funcName = (currentCase. isDefault()) ? " _then_default" : " _then_" + (pair. key+ 1 )
218
+ val thenExprDef = (currentCase. isDefault()) ? generateExpression(expr. getDefault(), 0 , isLambda) : generateExpression(currentCase. getExpression(), ifLevel + 1 , isLambda)
209
219
210
220
_thenFuncsBuilder. append(indent)
211
221
_thenFuncsBuilder. append(" def " + funcName + " ():" )
@@ -214,7 +224,7 @@ class PythonExpressionGenerator {
214
224
_thenFuncsBuilder. append(" return " + thenExprDef)
215
225
_thenFuncsBuilder. newLine
216
226
217
- if (currentCase. isDefault()){
227
+ if (currentCase. isDefault()) {
218
228
// Default else
219
229
_switchLogicBuilder. append(indent)
220
230
_switchLogicBuilder. append(" else:" )
@@ -223,21 +233,12 @@ class PythonExpressionGenerator {
223
233
_switchLogicBuilder. append(" return " )
224
234
_switchLogicBuilder. append(funcName)
225
235
_switchLogicBuilder. append(" ()" )
226
- }
227
- else {
228
- val guard = currentCase. getGuard()
229
-
236
+ } else {
237
+ val guard = currentCase. getGuard()
230
238
val prefix = (pair. key == 0 ) ? " if " : " elif "
231
239
_switchLogicBuilder. append(indent)
232
240
_switchLogicBuilder. append(prefix)
233
- if (guard. getLiteralGuard() !== null ) {
234
- val guardExpr = generateExpression(guard. getLiteralGuard(), 0 , isLambda)
235
- _switchLogicBuilder. append(" switchAttribute == " )
236
- _switchLogicBuilder. append(guardExpr)
237
- } else {
238
- val guardExpr = getGuardExpression(guard, isLambda)
239
- _switchLogicBuilder. append(guardExpr)
240
- }
241
+ _switchLogicBuilder. append(getGuardExpression(guard, isLambda))
241
242
_switchLogicBuilder. append(" :" )
242
243
_switchLogicBuilder. newLine()
243
244
_switchLogicBuilder. append(indent)
0 commit comments