Python: реализован инициализированный массив
Этот коммит содержится в:
родитель
c9d3b90caa
коммит
7414333f00
2 изменённых файлов: 32 добавлений и 3 удалений
|
@ -136,8 +136,19 @@ func handleBasicLit(bl *ast.BasicLit) string {
|
||||||
return bl.Value
|
return bl.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleCompositeLit(bl *ast.CompositeLit) string {
|
func handleCompositeLit(cl *ast.CompositeLit) string {
|
||||||
return "[]"
|
code := "["
|
||||||
|
switch cl.Type.(type) {
|
||||||
|
case *ast.ArrayType:
|
||||||
|
args := make([]string, 0)
|
||||||
|
for _, arg := range cl.Elts {
|
||||||
|
args = append(args, handleExpr(arg))
|
||||||
|
}
|
||||||
|
code += strings.Join(args, ",")
|
||||||
|
}
|
||||||
|
code += "]"
|
||||||
|
|
||||||
|
return code
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleUnaryExpr(expr *ast.UnaryExpr) string {
|
func handleUnaryExpr(expr *ast.UnaryExpr) string {
|
||||||
|
@ -210,6 +221,7 @@ func handleDeclStmt(stmt *ast.DeclStmt) string {
|
||||||
|
|
||||||
func handleExpr(expr ast.Expr) string {
|
func handleExpr(expr ast.Expr) string {
|
||||||
code := ""
|
code := ""
|
||||||
|
// spew.Dump(expr)
|
||||||
switch e := expr.(type) {
|
switch e := expr.(type) {
|
||||||
case *ast.BasicLit:
|
case *ast.BasicLit:
|
||||||
code += handleBasicLit(e)
|
code += handleBasicLit(e)
|
||||||
|
|
|
@ -98,7 +98,7 @@ main()
|
||||||
Compare(source, expected)
|
Compare(source, expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
It("Array assignment", func() {
|
It("Empty Array assignment", func() {
|
||||||
source := `package test
|
source := `package test
|
||||||
import "skidl"
|
import "skidl"
|
||||||
|
|
||||||
|
@ -117,6 +117,23 @@ main()
|
||||||
Compare(source, expected)
|
Compare(source, expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("Inited array assignment", func() {
|
||||||
|
source := `package test
|
||||||
|
import "skidl"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
a := []any{1, 2, x}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
expected := `from skidl import *
|
||||||
|
|
||||||
|
def main():
|
||||||
|
a = [1,2,x]
|
||||||
|
main()
|
||||||
|
`
|
||||||
|
Compare(source, expected)
|
||||||
|
})
|
||||||
|
|
||||||
It("Array append", func() {
|
It("Array append", func() {
|
||||||
source := `package test
|
source := `package test
|
||||||
import "skidl"
|
import "skidl"
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче