Python: добавлено объявление переменных

Этот коммит содержится в:
Softonik 2022-12-08 03:28:58 +03:00 коммит произвёл Nikolay Kopitonenko
родитель 83b314b387
коммит 153c00d0c5
2 изменённых файлов: 27 добавлений и 3 удалений

Просмотреть файл

@ -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:

Просмотреть файл

@ -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)