Python: добавлено объявление переменных
Этот коммит содержится в:
родитель
83b314b387
коммит
153c00d0c5
2 изменённых файлов: 27 добавлений и 3 удалений
|
@ -472,7 +472,7 @@ func handleSpecs(specs []ast.Spec) string {
|
||||||
case *ast.ImportSpec:
|
case *ast.ImportSpec:
|
||||||
code += handleImportSpec(spec)
|
code += handleImportSpec(spec)
|
||||||
case *ast.ValueSpec:
|
case *ast.ValueSpec:
|
||||||
code += handleValueSpec(spec) + ";"
|
code += handleValueSpec(spec)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
code += "\n"
|
code += "\n"
|
||||||
|
@ -556,13 +556,12 @@ func handleReturnStmt(stmt *ast.ReturnStmt) string {
|
||||||
func handleValueSpec(spec ast.Spec) string {
|
func handleValueSpec(spec ast.Spec) string {
|
||||||
s := spec.(*ast.ValueSpec)
|
s := spec.(*ast.ValueSpec)
|
||||||
code := ""
|
code := ""
|
||||||
code += handleValueSpecType(s.Type)
|
|
||||||
code += " "
|
|
||||||
code += handleValueSpecNames(s.Names)
|
code += handleValueSpecNames(s.Names)
|
||||||
if s.Values != nil {
|
if s.Values != nil {
|
||||||
code += " = "
|
code += " = "
|
||||||
code += handleValueSpecValues(s.Values)
|
code += handleValueSpecValues(s.Values)
|
||||||
}
|
}
|
||||||
|
code += "\n"
|
||||||
return code
|
return code
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -591,6 +590,8 @@ func handleValueSpecValues(values []ast.Expr) string {
|
||||||
switch v := value.(type) {
|
switch v := value.(type) {
|
||||||
case *ast.BasicLit:
|
case *ast.BasicLit:
|
||||||
code += handleBasicLit(v)
|
code += handleBasicLit(v)
|
||||||
|
case *ast.BinaryExpr:
|
||||||
|
code += handleBinaryExpr(v)
|
||||||
case *ast.SelectorExpr:
|
case *ast.SelectorExpr:
|
||||||
code += handleSelectorExpr(value)
|
code += handleSelectorExpr(value)
|
||||||
case *ast.CallExpr:
|
case *ast.CallExpr:
|
||||||
|
|
|
@ -47,6 +47,29 @@ main()
|
||||||
expected := `from skidl import *
|
expected := `from skidl import *
|
||||||
from FreeCAD 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()
|
main()
|
||||||
`
|
`
|
||||||
Compare(source, expected)
|
Compare(source, expected)
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче