From 153c00d0c59990859ab9badcb364a84f84ec1550 Mon Sep 17 00:00:00 2001 From: Softonik Date: Thu, 8 Dec 2022 03:28:58 +0300 Subject: [PATCH] =?UTF-8?q?Python:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=BE=D0=B1=D1=8A=D1=8F=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- transpile_python/service.go | 7 ++++--- transpile_python/service_test.go | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/transpile_python/service.go b/transpile_python/service.go index 491b585..51a59b2 100644 --- a/transpile_python/service.go +++ b/transpile_python/service.go @@ -472,7 +472,7 @@ func handleSpecs(specs []ast.Spec) string { case *ast.ImportSpec: code += handleImportSpec(spec) case *ast.ValueSpec: - code += handleValueSpec(spec) + ";" + code += handleValueSpec(spec) } } code += "\n" @@ -556,13 +556,12 @@ func handleReturnStmt(stmt *ast.ReturnStmt) string { func handleValueSpec(spec ast.Spec) string { s := spec.(*ast.ValueSpec) code := "" - code += handleValueSpecType(s.Type) - code += " " code += handleValueSpecNames(s.Names) if s.Values != nil { code += " = " code += handleValueSpecValues(s.Values) } + code += "\n" return code } @@ -591,6 +590,8 @@ func handleValueSpecValues(values []ast.Expr) string { switch v := value.(type) { case *ast.BasicLit: code += handleBasicLit(v) + case *ast.BinaryExpr: + code += handleBinaryExpr(v) case *ast.SelectorExpr: code += handleSelectorExpr(value) case *ast.CallExpr: diff --git a/transpile_python/service_test.go b/transpile_python/service_test.go index cb92b48..ecc4c31 100644 --- a/transpile_python/service_test.go +++ b/transpile_python/service_test.go @@ -47,6 +47,29 @@ main() expected := `from skidl import * from FreeCAD import * +main() +` + Compare(source, expected) + }) + + FIt("Variables declaration", func() { + source := `package test + import "skidl" + + var ( + a = 1 + b = 2 + c = 3 + d = a + b + c / 2 + ) + ` + expected := `from skidl import * + +a = 1 +b = 2 +c = 3 +d = a + b + c / 2 + main() ` Compare(source, expected)