diff --git a/transpile_python/service.go b/transpile_python/service.go index 51a59b2..49a2a92 100644 --- a/transpile_python/service.go +++ b/transpile_python/service.go @@ -497,6 +497,8 @@ func handleStmt(stmt ast.Stmt, standaloneAssignment bool) string { code += handleExprStmt(s) case *ast.ForStmt: code += handleForStmt(s) + case *ast.RangeStmt: + code += handleRangeStmt(s) case *ast.IfStmt: code += handleIfStmt(s) case *ast.SwitchStmt: @@ -535,6 +537,18 @@ func handleForStmt(stmt *ast.ForStmt) string { return code } +func handleRangeStmt(stmt *ast.RangeStmt) string { + code := "for " + code += handleIdent(stmt.Key) + code += " in " + code += handleExpr(stmt.X) + code += ":\n" + increaseInd() + code += handleBlockStmt(stmt.Body) + decreaseInd() + return code +} + func handleSwitchStmt(stmt *ast.SwitchStmt) string { code := "switch (" code += handleExpr(stmt.Tag) diff --git a/transpile_python/service_test.go b/transpile_python/service_test.go index ecc4c31..95214c0 100644 --- a/transpile_python/service_test.go +++ b/transpile_python/service_test.go @@ -52,7 +52,7 @@ main() Compare(source, expected) }) - FIt("Variables declaration", func() { + It("Variables declaration", func() { source := `package test import "skidl" @@ -403,6 +403,26 @@ main() Compare(source, expected) }) + It("For with range", func() { + source := `package test + import "skidl" + + func main() { + for v := range list { + call(v) + } + } + ` + expected := `from skidl import * + +def main(): + for v in list: + call(v) +main() +` + Compare(source, expected) + }) + It("Function decl/call", func() { source := `package test import "skidl"