From 25a5993b52b8af7a91f24165329781b1733eaf40 Mon Sep 17 00:00:00 2001 From: Softonik Date: Thu, 8 Dec 2022 03:51:01 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D1=86=D0=B8=D0=BA=D0=BB=20=D1=81=20range?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- transpile_python/service.go | 14 ++++++++++++++ transpile_python/service_test.go | 22 +++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) 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"